Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Glutamat42 committed Jan 17, 2024
1 parent c4cfff9 commit 252bfa3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion classes/condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

class condition extends availability_condition {
use static_call_trait;
private logger $logger;
protected logger $logger;

protected string $condition;
protected $core_plugin_manager_instance;
Expand Down
11 changes: 11 additions & 0 deletions tests/condition_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use core_availability\info;
use core_plugin_manager;
use local_adler\plugin_interface;
use local_logging\logger;
use Mockery;
use moodle_exception;
use ReflectionClass;
Expand Down Expand Up @@ -424,6 +425,16 @@ public function test_is_available(array $installed_plugins, bool $evaluate_secti
$property->setValue($condition_mock, '1');


// mock logger as it does not exist because constructor is not executed
$logger_mock = Mockery::mock(Logger::class);
// ignore all method calls on mock
$logger_mock->shouldIgnoreMissing();
// set logger mock to $logger variable in class under test
$property = $reflection->getProperty('logger');
$property->setAccessible(true);
$property->setValue($condition_mock, $logger_mock);


// invoke method is_available on $reflection
$result = $condition_mock->is_available($not, $info_mock, true, 0);
// alternative approach
Expand Down

0 comments on commit 252bfa3

Please sign in to comment.