diff --git a/components/ILIAS/LegalDocuments/tests/AdministrationEditLinksTest.php b/components/ILIAS/LegalDocuments/tests/AdministrationEditLinksTest.php index 4b4a37b3bbac..08eddde97bde 100755 --- a/components/ILIAS/LegalDocuments/tests/AdministrationEditLinksTest.php +++ b/components/ILIAS/LegalDocuments/tests/AdministrationEditLinksTest.php @@ -27,13 +27,16 @@ use ILIAS\LegalDocuments\Value\Document; use ILIAS\LegalDocuments\Value\Criterion; use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\MockObject\Stub; class AdministrationEditLinksTest extends TestCase { public function testConstruct(): void { - $admin = $this->getMockBuilder(Administration::class)->disableOriginalConstructor()->getMock(); - $gui = $this->getMockBuilder(ilLegalDocumentsAdministrationGUI::class)->disableOriginalConstructor()->getMock(); + /** @var Administration&Stub $admin */ + $admin = $this->createStub(Administration::class); + /** @var ilLegalDocumentsAdministrationGUI&Stub $gui */ + $gui = $this->createStub(ilLegalDocumentsAdministrationGUI::class); $this->assertInstanceOf(AdministrationEditLinks::class, new AdministrationEditLinks($gui, $admin)); } @@ -41,11 +44,12 @@ public function testConstruct(): void public function testMethods(string $method, string $target, int $argc): void { $admin = $this->getMockBuilder(Administration::class)->disableOriginalConstructor()->getMock(); - $gui = $this->getMockBuilder(ilLegalDocumentsAdministrationGUI::class)->disableOriginalConstructor()->getMock(); + /** @var ilLegalDocumentsAdministrationGUI&Stub $gui */ + $gui = $this->createStub(ilLegalDocumentsAdministrationGUI::class); $args = [ - $this->getMockBuilder(Document::class)->disableOriginalConstructor()->getMock(), - $this->getMockBuilder(Criterion::class)->disableOriginalConstructor()->getMock(), + $this->createStub(Document::class), + $this->createStub(Criterion::class), ]; $args = array_slice($args, 0, $argc); diff --git a/components/ILIAS/LegalDocuments/tests/AdministrationTest.php b/components/ILIAS/LegalDocuments/tests/AdministrationTest.php index de645c3cce20..0b0374de8071 100755 --- a/components/ILIAS/LegalDocuments/tests/AdministrationTest.php +++ b/components/ILIAS/LegalDocuments/tests/AdministrationTest.php @@ -40,6 +40,7 @@ use ILIAS\Refinery\Factory as Refinery; use ILIAS\Refinery\KindlyTo\Group as KindlyToGroup; use ILIAS\Refinery\Transformation; +use PHPUnit\Framework\MockObject\Stub; require_once __DIR__ . '/ContainerMock.php'; @@ -49,17 +50,22 @@ class AdministrationTest extends TestCase public function testConstruct(): void { - $config = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock(); - $container = $this->getMockBuilder(Container::class)->disableOriginalConstructor()->getMock(); - $ui = $this->getMockBuilder(UI::class)->disableOriginalConstructor()->getMock(); + /** @var Config&Stub $config */ + $config = $this->createStub(Config::class); + /** @var Container&Stub $container */ + $container = $this->createStub(Container::class); + /** @var UI&Stub $ui */ + $ui = $this->createStub(UI::class); $this->assertInstanceOf(Administration::class, new Administration($config, $container, $ui)); } public function testDeleteDocumentsConfirmation(): void { - $config = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock(); - $container = $this->getMockBuilder(Container::class)->disableOriginalConstructor()->getMock(); + /** @var Config&Stub $config */ + $config = $this->createStub(Config::class); + /** @var Container&Stub $container */ + $container = $this->createStub(Container::class); $ui = $this->mockMethod(UI::class, 'txt', ['sure_delete_documents_p'], 'translated'); $documents = [$this->doc(9, 'First title'), $this->doc(49, 'Second title')]; @@ -83,13 +89,15 @@ public function testDeleteDocumentsConfirmation(): void public function testDeleteDocuments(): void { - $container = $this->getMockBuilder(Container::class)->disableOriginalConstructor()->getMock(); - $ui = $this->getMockBuilder(UI::class)->disableOriginalConstructor()->getMock(); + /** @var Container&Stub $container */ + $container = $this->createStub(Container::class); + /** @var UI&Stub $ui */ + $ui = $this->createStub(UI::class); $documents = [ - $this->getMockBuilder(Document::class)->disableOriginalConstructor()->getMock(), - $this->getMockBuilder(Document::class)->disableOriginalConstructor()->getMock(), - $this->getMockBuilder(Document::class)->disableOriginalConstructor()->getMock(), + $this->createStub(Document::class), + $this->createStub(Document::class), + $this->createStub(Document::class), ]; $repository = $this->getMockBuilder(DocumentRepository::class)->getMock(); @@ -115,8 +123,10 @@ public function testDeleteDocuments(): void public function testWithDocumentAndCriterion(): void { - $container = $this->getMockBuilder(Container::class)->disableOriginalConstructor()->getMock(); - $ui = $this->getMockBuilder(UI::class)->disableOriginalConstructor()->getMock(); + /** @var Container&Stub $container */ + $container = $this->createStub(Container::class); + /** @var UI&Stub $ui */ + $ui = $this->createStub(UI::class); $criterion = $this->mockMethod(Criterion::class, 'id', [], 98); $document = $this->mockMethod(Document::class, 'criteria', [], [ diff --git a/components/ILIAS/LegalDocuments/tests/Condition/Definitions/RoleDefinitionTest.php b/components/ILIAS/LegalDocuments/tests/Condition/Definitions/RoleDefinitionTest.php index 65c3372f1a32..c62cc54dc815 100755 --- a/components/ILIAS/LegalDocuments/tests/Condition/Definitions/RoleDefinitionTest.php +++ b/components/ILIAS/LegalDocuments/tests/Condition/Definitions/RoleDefinitionTest.php @@ -40,9 +40,9 @@ class RoleDefinitionTest extends TestCase public function testConstruct(): void { $this->assertInstanceOf(RoleDefinition::class, new RoleDefinition( - $this->mock(UI::class), - $this->mock(ilObjectDataCache::class), - $this->mock(ilRbacReview::class), + $this->stub(UI::class), + $this->stub(ilObjectDataCache::class), + $this->stub(ilRbacReview::class), $this->fail(...) )); } @@ -54,10 +54,10 @@ public function testFormGroup(): void } $instance = new RoleDefinition( - $this->mock(UI::class), - $this->mock(ilObjectDataCache::class), - $this->mock(ilRbacReview::class), - fn() => $this->mock(Constraint::class) + $this->stub(UI::class), + $this->stub(ilObjectDataCache::class), + $this->stub(ilRbacReview::class), + fn() => $this->stub(Constraint::class) ); $this->assertInstanceOf(Group::class, $instance->formGroup()); @@ -66,9 +66,9 @@ public function testFormGroup(): void public function testTranslatedRole(): void { $instance = new RoleDefinition( - $this->mock(UI::class), + $this->stub(UI::class), $this->mockMethod(ilObjectDataCache::class, 'lookupTitle', [87], 'foo'), - $this->mock(ilRbacReview::class), + $this->stub(ilRbacReview::class), $this->fail(...) ); @@ -79,8 +79,8 @@ public function testTranslatedType(): void { $instance = new RoleDefinition( $this->mockMethod(UI::class, 'txt', ['crit_type_usr_global_role'], 'foo'), - $this->mock(ilObjectDataCache::class), - $this->mock(ilRbacReview::class), + $this->stub(ilObjectDataCache::class), + $this->stub(ilRbacReview::class), $this->fail(...) ); @@ -90,12 +90,12 @@ public function testTranslatedType(): void public function testWithCriterion(): void { $instance = new RoleDefinition( - $this->mock(UI::class), - $this->mock(ilObjectDataCache::class), - $this->mock(ilRbacReview::class), + $this->stub(UI::class), + $this->stub(ilObjectDataCache::class), + $this->stub(ilRbacReview::class), $this->fail(...) ); - $this->assertInstanceOf(Role::class, $instance->withCriterion($this->mock(CriterionContent::class))); + $this->assertInstanceOf(Role::class, $instance->withCriterion($this->stub(CriterionContent::class))); } } diff --git a/components/ILIAS/LegalDocuments/tests/Condition/Definitions/UserCountryDefinitionTest.php b/components/ILIAS/LegalDocuments/tests/Condition/Definitions/UserCountryDefinitionTest.php index 1db61175cf9d..d7dd508820be 100755 --- a/components/ILIAS/LegalDocuments/tests/Condition/Definitions/UserCountryDefinitionTest.php +++ b/components/ILIAS/LegalDocuments/tests/Condition/Definitions/UserCountryDefinitionTest.php @@ -38,7 +38,7 @@ class UserCountryDefinitionTest extends TestCase public function testConstruct(): void { $this->assertInstanceOf(UserCountryDefinition::class, new UserCountryDefinition( - $this->mock(UI::class), + $this->stub(UI::class), $this->fail(...) )); } @@ -46,8 +46,8 @@ public function testConstruct(): void public function testFormGroup(): void { $instance = new UserCountryDefinition( - $this->mock(UI::class), - fn() => $this->mock(Constraint::class) + $this->stub(UI::class), + fn() => $this->stub(Constraint::class) ); $this->assertInstanceOf(Group::class, $instance->formGroup()); @@ -55,8 +55,8 @@ public function testFormGroup(): void public function testWithCriterion(): void { - $instance = new UserCountryDefinition($this->mock(UI::class), $this->fail(...)); - $this->assertInstanceOf(UserCountry::class, $instance->withCriterion($this->mock(CriterionContent::class))); + $instance = new UserCountryDefinition($this->stub(UI::class), $this->fail(...)); + $this->assertInstanceOf(UserCountry::class, $instance->withCriterion($this->stub(CriterionContent::class))); } public function testTranslatedType(): void diff --git a/components/ILIAS/LegalDocuments/tests/Condition/Definitions/UserLanguageDefinitionTest.php b/components/ILIAS/LegalDocuments/tests/Condition/Definitions/UserLanguageDefinitionTest.php index 14eb062d0cf7..28c586dafb77 100755 --- a/components/ILIAS/LegalDocuments/tests/Condition/Definitions/UserLanguageDefinitionTest.php +++ b/components/ILIAS/LegalDocuments/tests/Condition/Definitions/UserLanguageDefinitionTest.php @@ -37,20 +37,20 @@ class UserLanguageDefinitionTest extends TestCase public function testConstruct(): void { - $this->assertInstanceOf(UserLanguageDefinition::class, new UserLanguageDefinition($this->mock(UI::class), [], $this->fail(...))); + $this->assertInstanceOf(UserLanguageDefinition::class, new UserLanguageDefinition($this->stub(UI::class), [], $this->fail(...))); } public function testFormGroup(): void { - $instance = new UserLanguageDefinition($this->mock(UI::class), [], fn() => $this->mock(Constraint::class)); + $instance = new UserLanguageDefinition($this->stub(UI::class), [], fn() => $this->stub(Constraint::class)); $this->assertInstanceOf(Group::class, $instance->formGroup()); } public function testWithCriterion(): void { - $instance = new UserLanguageDefinition($this->mock(UI::class), [], $this->fail(...)); - $this->assertInstanceOf(UserLanguage::class, $instance->withCriterion($this->mock(CriterionContent::class))); + $instance = new UserLanguageDefinition($this->stub(UI::class), [], $this->fail(...)); + $this->assertInstanceOf(UserLanguage::class, $instance->withCriterion($this->stub(CriterionContent::class))); } public function testTranslatedType(): void diff --git a/components/ILIAS/LegalDocuments/tests/Condition/RoleTest.php b/components/ILIAS/LegalDocuments/tests/Condition/RoleTest.php index 4a4fd0ed5364..42cc71bb296b 100755 --- a/components/ILIAS/LegalDocuments/tests/Condition/RoleTest.php +++ b/components/ILIAS/LegalDocuments/tests/Condition/RoleTest.php @@ -40,16 +40,16 @@ class RoleTest extends TestCase public function testConstruct(): void { $this->assertInstanceOf(Role::class, new Role( - $this->mock(CriterionContent::class), - $this->mock(RoleDefinition::class), - $this->mock(UIFactory::class), - $this->mock(ilRbacReview::class) + $this->stub(CriterionContent::class), + $this->stub(RoleDefinition::class), + $this->stub(UIFactory::class), + $this->stub(ilRbacReview::class) )); } public function testAsComponent(): void { - $legacy = $this->mock(Legacy\Content::class); + $legacy = $this->stub(Legacy\Content::class); $legacy_factory = $this->mock(Legacy\Factory::class); $legacy_factory ->expects($this->once()) @@ -57,10 +57,10 @@ public function testAsComponent(): void ->willReturn($legacy); $this->assertSame($legacy, (new Role( - $this->mockTree(CriterionContent::class, ['arguments' => ['role_id' => 78]]), - $this->mock(RoleDefinition::class), - $this->mockTree(UIFactory::class, ['legacy' => $legacy_factory]), - $this->mock(ilRbacReview::class) + $this->stubTree(CriterionContent::class, ['arguments' => ['role_id' => 78]]), + $this->stub(RoleDefinition::class), + $this->stubTree(UIFactory::class, ['legacy' => $legacy_factory]), + $this->stub(ilRbacReview::class) ))->asComponent()); } @@ -69,24 +69,24 @@ public function testEval(): void $rbac = $this->mockMethod(ilRbacReview::class, 'isAssigned', [45, 78], true); $instance = new Role( - $this->mockTree(CriterionContent::class, ['arguments' => ['role_id' => 78]]), - $this->mock(RoleDefinition::class), - $this->mock(UIFactory::class), + $this->stubTree(CriterionContent::class, ['arguments' => ['role_id' => 78]]), + $this->stub(RoleDefinition::class), + $this->stub(UIFactory::class), $rbac ); - $this->assertTrue($instance->eval($this->mockTree(ilObjUser::class, ['getId' => 45]))); + $this->assertTrue($instance->eval($this->stubTree(ilObjUser::class, ['getId' => 45]))); } public function testDefinition(): void { - $definition = $this->mock(RoleDefinition::class); + $definition = $this->stub(RoleDefinition::class); $instance = new Role( - $this->mock(CriterionContent::class), + $this->stub(CriterionContent::class), $definition, - $this->mock(UIFactory::class), - $this->mock(ilRbacReview::class) + $this->stub(UIFactory::class), + $this->stub(ilRbacReview::class) ); $this->assertSame($definition, $instance->definition()); @@ -95,12 +95,12 @@ public function testDefinition(): void public function testKnownToNeverMatchWith(): void { $instance = new Role( - $this->mock(CriterionContent::class), - $this->mock(RoleDefinition::class), - $this->mock(UIFactory::class), - $this->mock(ilRbacReview::class) + $this->stub(CriterionContent::class), + $this->stub(RoleDefinition::class), + $this->stub(UIFactory::class), + $this->stub(ilRbacReview::class) ); - $this->assertFalse($instance->knownToNeverMatchWith($this->mock(Condition::class))); + $this->assertFalse($instance->knownToNeverMatchWith($this->stub(Condition::class))); } } diff --git a/components/ILIAS/LegalDocuments/tests/Condition/UserCountryTest.php b/components/ILIAS/LegalDocuments/tests/Condition/UserCountryTest.php index 0b6b40b6b3a0..89efc3ba45bc 100755 --- a/components/ILIAS/LegalDocuments/tests/Condition/UserCountryTest.php +++ b/components/ILIAS/LegalDocuments/tests/Condition/UserCountryTest.php @@ -39,15 +39,15 @@ class UserCountryTest extends TestCase public function testConstruct(): void { $this->assertInstanceOf(UserCountry::class, new UserCountry( - $this->mock(CriterionContent::class), - $this->mock(UserCountryDefinition::class), - $this->mock(UIFactory::class) + $this->stub(CriterionContent::class), + $this->stub(UserCountryDefinition::class), + $this->stub(UIFactory::class) )); } public function testAsComponent(): void { - $legacy = $this->mock(Legacy\Content::class); + $legacy = $this->stub(Legacy\Content::class); $legacy_factory = $this->mock(Legacy\Factory::class); $legacy_factory ->expects($this->once()) @@ -55,9 +55,9 @@ public function testAsComponent(): void ->willReturn($legacy); $instance = new UserCountry( - $this->mockTree(CriterionContent::class, ['arguments' => ['country' => 'foo']]), - $this->mock(UserCountryDefinition::class), - $this->mockTree(UIFactory::class, ['legacy' => $legacy_factory]) + $this->stubTree(CriterionContent::class, ['arguments' => ['country' => 'foo']]), + $this->stub(UserCountryDefinition::class), + $this->stubTree(UIFactory::class, ['legacy' => $legacy_factory]) ); $this->assertSame($legacy, $instance->asComponent()); @@ -66,21 +66,21 @@ public function testAsComponent(): void public function testEval(): void { $instance = new UserCountry( - $this->mockTree(CriterionContent::class, ['arguments' => ['country' => 'foo']]), - $this->mock(UserCountryDefinition::class), - $this->mock(UIFactory::class) + $this->stubTree(CriterionContent::class, ['arguments' => ['country' => 'foo']]), + $this->stub(UserCountryDefinition::class), + $this->stub(UIFactory::class) ); - $this->assertTrue($instance->eval($this->mockTree(ilObjUser::class, ['getCountry' => 'foo']))); + $this->assertTrue($instance->eval($this->stubTree(ilObjUser::class, ['getCountry' => 'foo']))); } public function testDefinition(): void { - $definition = $this->mock(UserCountryDefinition::class); + $definition = $this->stub(UserCountryDefinition::class); $instance = new UserCountry( - $this->mock(CriterionContent::class), + $this->stub(CriterionContent::class), $definition, - $this->mock(UIFactory::class) + $this->stub(UIFactory::class) ); $this->assertSame($definition, $instance->definition()); @@ -89,18 +89,18 @@ public function testDefinition(): void public function testKnownToNeverMatchWith(): void { $instance = new UserCountry( - $this->mock(CriterionContent::class), - $this->mock(UserCountryDefinition::class), - $this->mock(UIFactory::class) + $this->stub(CriterionContent::class), + $this->stub(UserCountryDefinition::class), + $this->stub(UIFactory::class) ); $second = new UserCountry( - $this->mock(CriterionContent::class), - $this->mock(UserCountryDefinition::class), - $this->mock(UIFactory::class) + $this->stub(CriterionContent::class), + $this->stub(UserCountryDefinition::class), + $this->stub(UIFactory::class) ); $this->assertTrue($instance->knownToNeverMatchWith($second)); - $this->assertFalse($instance->knownToNeverMatchWith($this->mock(Condition::class))); + $this->assertFalse($instance->knownToNeverMatchWith($this->stub(Condition::class))); } } diff --git a/components/ILIAS/LegalDocuments/tests/Condition/UserLanguageTest.php b/components/ILIAS/LegalDocuments/tests/Condition/UserLanguageTest.php index 844e0c4693f6..303847bd24f6 100755 --- a/components/ILIAS/LegalDocuments/tests/Condition/UserLanguageTest.php +++ b/components/ILIAS/LegalDocuments/tests/Condition/UserLanguageTest.php @@ -39,19 +39,19 @@ class UserLanguageTest extends TestCase public function testConstruct(): void { $this->assertInstanceOf(UserLanguage::class, new UserLanguage( - $this->mock(CriterionContent::class), - $this->mock(UserLanguageDefinition::class), - $this->mock(UI::class) + $this->stub(CriterionContent::class), + $this->stub(UserLanguageDefinition::class), + $this->stub(UI::class) )); } public function testAsComponent(): void { - $legacy = $this->mock(Legacy\Content::class); + $legacy = $this->stub(Legacy\Content::class); $instance = new UserLanguage( - $this->mockTree(CriterionContent::class, ['arguments' => ['lng' => 'foo']]), - $this->mock(UserLanguageDefinition::class), - $this->mockTree(UI::class, ['create' => ['legacy' => ['content' => $legacy]]]) + $this->stubTree(CriterionContent::class, ['arguments' => ['lng' => 'foo']]), + $this->stub(UserLanguageDefinition::class), + $this->stubTree(UI::class, ['create' => ['legacy' => ['content' => $legacy]]]) ); $this->assertSame($legacy, $instance->asComponent()); @@ -60,21 +60,21 @@ public function testAsComponent(): void public function testEval(): void { $instance = new UserLanguage( - $this->mockTree(CriterionContent::class, ['arguments' => ['lng' => 'foo']]), - $this->mock(UserLanguageDefinition::class), - $this->mock(UI::class) + $this->stubTree(CriterionContent::class, ['arguments' => ['lng' => 'foo']]), + $this->stub(UserLanguageDefinition::class), + $this->stub(UI::class) ); - $this->assertTrue($instance->eval($this->mockTree(ilObjUser::class, ['getLanguage' => 'foo']))); + $this->assertTrue($instance->eval($this->stubTree(ilObjUser::class, ['getLanguage' => 'foo']))); } public function testDefinition(): void { - $definition = $this->mock(UserLanguageDefinition::class); + $definition = $this->stub(UserLanguageDefinition::class); $instance = new UserLanguage( - $this->mock(CriterionContent::class), + $this->stub(CriterionContent::class), $definition, - $this->mock(UI::class) + $this->stub(UI::class) ); $this->assertSame($definition, $instance->definition()); @@ -83,18 +83,18 @@ public function testDefinition(): void public function testKnownToNeverMatchWith(): void { $instance = new UserLanguage( - $this->mock(CriterionContent::class), - $this->mock(UserLanguageDefinition::class), - $this->mock(UI::class) + $this->stub(CriterionContent::class), + $this->stub(UserLanguageDefinition::class), + $this->stub(UI::class) ); $second = new UserLanguage( - $this->mock(CriterionContent::class), - $this->mock(UserLanguageDefinition::class), - $this->mock(UI::class) + $this->stub(CriterionContent::class), + $this->stub(UserLanguageDefinition::class), + $this->stub(UI::class) ); $this->assertTrue($instance->knownToNeverMatchWith($second)); - $this->assertFalse($instance->knownToNeverMatchWith($this->mock(Condition::class))); + $this->assertFalse($instance->knownToNeverMatchWith($this->stub(Condition::class))); } } diff --git a/components/ILIAS/LegalDocuments/tests/ConductorTest.php b/components/ILIAS/LegalDocuments/tests/ConductorTest.php index e0a3931f4e13..ca22e9b7d548 100755 --- a/components/ILIAS/LegalDocuments/tests/ConductorTest.php +++ b/components/ILIAS/LegalDocuments/tests/ConductorTest.php @@ -57,25 +57,25 @@ class ConductorTest extends TestCase public function testConstruct(): void { - $this->assertInstanceOf(Conductor::class, new Conductor($this->mock(Container::class), $this->mock(Internal::class), $this->mock(Routing::class))); + $this->assertInstanceOf(Conductor::class, new Conductor($this->stub(Container::class), $this->stub(Internal::class), $this->stub(Routing::class))); } public function testProvide(): void { - $instance = new Conductor($this->mock(Container::class), $this->mock(Internal::class), $this->mock(Routing::class)); + $instance = new Conductor($this->stub(Container::class), $this->stub(Internal::class), $this->stub(Routing::class)); $this->assertInstanceOf(Provide::class, $instance->provide('foo')); } public function testLoginPageHTML(): void { $components = [ - $this->mock(Component::class), - $this->mock(Component::class), + $this->stub(Component::class), + $this->stub(Component::class), ]; - $space = $this->mock(Content::class); + $space = $this->stub(Content::class); - $container = $this->mockTree(Container::class, [ + $container = $this->stubTree(Container::class, [ 'ui' => [ 'renderer' => $this->mockMethod(Renderer::class, 'render', [ $components, @@ -85,24 +85,24 @@ public function testLoginPageHTML(): void $internal = $this->mockMethod(Internal::class, 'get', ['show-on-login-page', 'foo'], fn() => $components); - $instance = new Conductor($container, $internal, $this->mock(Routing::class)); + $instance = new Conductor($container, $internal, $this->stub(Routing::class)); $this->assertSame('rendered', $instance->loginPageHTML('foo')); } public function testLogoutText(): void { - $constraint = $this->mock(Constraint::class); - $component = $this->mock(Component::class); + $constraint = $this->stub(Constraint::class); + $component = $this->stub(Component::class); - $container = $this->mockTree(Container::class, [ + $container = $this->stubTree(Container::class, [ 'refinery' => ['to' => ['string' => $constraint]], 'http' => ['wrapper' => ['query' => $this->mockMethod(ArrayBasedRequestWrapper::class, 'retrieve', ['withdraw_consent', $constraint], 'foo')]], 'ui' => ['renderer' => $this->mockMethod(Renderer::class, 'render', [$component], 'rendered')], ]); - $internal = $this->mock(Internal::class); + $internal = $this->stub(Internal::class); $internal->method('get')->willReturnCallback(function ($param1, $param2) use (&$called, $component) { if ($param1 === 'logout-text' && $param2 === 'foo') { return static function () use ($component): Component { @@ -113,7 +113,7 @@ public function testLogoutText(): void return null; }); - $instance = new Conductor($container, $internal, $this->mock(Routing::class)); + $instance = new Conductor($container, $internal, $this->stub(Routing::class)); $logoutText = $instance->logoutText(); @@ -129,10 +129,10 @@ public function testModifyFooter(): void return $f; }; - $instance = new Conductor($this->mock(Container::class), $this->mockMethod(Internal::class, 'all', ['footer'], [ + $instance = new Conductor($this->stub(Container::class), $this->mockMethod(Internal::class, 'all', ['footer'], [ $modify_footer, $modify_footer, - ]), $this->mock(Routing::class)); + ]), $this->stub(Routing::class)); $this->assertSame($footer, $instance->modifyFooter($footer)); } @@ -156,12 +156,12 @@ public function testRedirectAgreeContent(): void $this->expectExceptionMessage('Not available.'); $routing = $this->mock(Routing::class); $routing->expects($this->once())->method('redirectToOriginalTarget'); - $constraint = $this->mock(Constraint::class); - $container = $this->mockTree(Container::class, [ + $constraint = $this->stub(Constraint::class); + $container = $this->stubTree(Container::class, [ 'refinery' => ['to' => ['string' => $constraint]], 'http' => ['wrapper' => ['query' => $this->mockMethod(ArrayBasedRequestWrapper::class, 'retrieve', ['id', $constraint], 'foo')]], ]); - $internal = $this->mock(Internal::class); + $internal = $this->stub(Internal::class); $internal = $this->mockMethod(Internal::class, 'get', ['agreement-form', 'foo'], function (string $g, string $cmd): Result { return new Error('Not available.'); }); @@ -182,7 +182,7 @@ public function testUsersWithHiddenOnlineStatus(): void fn() => [4, 5, 6], fn() => [5, 6], ]); - $instance = new Conductor($this->mock(Container::class), $internal, $this->mock(Routing::class)); + $instance = new Conductor($this->stub(Container::class), $internal, $this->stub(Routing::class)); $this->assertSame( [1, 2, 3, 4, 7, 8, 9], @@ -193,13 +193,13 @@ public function testUsersWithHiddenOnlineStatus(): void public function testUserCanReadInternalMail(): void { $constraints = [ - 'foo' => $this->mock(Constraint::class), - 'bar' => $this->mock(Constraint::class), + 'foo' => $this->stub(Constraint::class), + 'bar' => $this->stub(Constraint::class), ]; - $series = $this->mock(Transformation::class); + $series = $this->stub(Transformation::class); - $container = $this->mockTree(Container::class, [ + $container = $this->stubTree(Container::class, [ 'refinery' => ['in' => $this->mockMethod( InGroup::class, 'series', @@ -210,24 +210,24 @@ public function testUserCanReadInternalMail(): void $internal = $this->mockMethod(Internal::class, 'all', ['constrain-internal-mail'], $constraints); - $instance = new Conductor($container, $internal, $this->mock(Routing::class)); + $instance = new Conductor($container, $internal, $this->stub(Routing::class)); $this->assertSame($series, $instance->userCanReadInternalMail()); } public function testCanUseSoapApi(): void { $constraints = [ - 'foo' => $this->mock(Constraint::class), - 'bar' => $this->mock(Constraint::class), + 'foo' => $this->stub(Constraint::class), + 'bar' => $this->stub(Constraint::class), ]; - $container = $this->mockTree(Container::class, [ - 'refinery' => ['in' => $this->mockMethod(InGroup::class, 'series', [array_values($constraints)], $this->mock(Transformation::class))] + $container = $this->stubTree(Container::class, [ + 'refinery' => ['in' => $this->mockMethod(InGroup::class, 'series', [array_values($constraints)], $this->stub(Transformation::class))] ]); $internal = $this->mockMethod(Internal::class, 'all', ['use-soap-api'], $constraints); - $instance = new Conductor($container, $internal, $this->mock(Routing::class)); + $instance = new Conductor($container, $internal, $this->stub(Routing::class)); $this->assertInstanceOf(Transformation::class, $instance->canUseSoapApi()); } @@ -244,7 +244,7 @@ function () use (&$called): void { } ]); - $instance = new Conductor($this->mock(Container::class), $internal, $this->mock(Routing::class)); + $instance = new Conductor($this->stub(Container::class), $internal, $this->stub(Routing::class)); $instance->afterLogin(); @@ -253,13 +253,13 @@ function () use (&$called): void { public function testFindGotoLink(): void { - $foo = $this->mock(Target::class); + $foo = $this->stub(Target::class); $internal = $this->mockMethod(Internal::class, 'all', ['goto'], [ - $this->mockTree(GotoLink::class, ['name' => 'bar']), - $this->mockTree(GotoLink::class, ['name' => 'foo', 'target' => $foo]), + $this->stubTree(GotoLink::class, ['name' => 'bar']), + $this->stubTree(GotoLink::class, ['name' => 'foo', 'target' => $foo]), ]); - $instance = new Conductor($this->mock(Container::class), $internal, $this->mock(Routing::class)); + $instance = new Conductor($this->stub(Container::class), $internal, $this->stub(Routing::class)); $target = $instance->findGotoLink('foo'); $this->assertTrue($target->isOk()); @@ -270,23 +270,23 @@ public function testFindGotoLink(): void public function testIntercepting(): void { $intercepting = [ - 'foo' => $this->mock(Intercept::class), - 'bar' => $this->mock(Intercept::class) + 'foo' => $this->stub(Intercept::class), + 'bar' => $this->stub(Intercept::class) ]; $internal = $this->mockMethod(Internal::class, 'all', ['intercept'], $intercepting); - $instance = new Conductor($this->mock(Container::class), $internal, $this->mock(Routing::class)); + $instance = new Conductor($this->stub(Container::class), $internal, $this->stub(Routing::class)); $this->assertSame($intercepting, $instance->intercepting()); } public function testSelfRegistration(): void { $internal = $this->mockMethod(Internal::class, 'all', ['self-registration'], [ - $this->mock(SelfRegistration::class), + $this->stub(SelfRegistration::class), ]); - $instance = new Conductor($this->mock(Container::class), $internal, $this->mock(Routing::class)); + $instance = new Conductor($this->stub(Container::class), $internal, $this->stub(Routing::class)); $this->assertInstanceOf(Bundle::class, $instance->selfRegistration()); } @@ -298,13 +298,13 @@ public function testUserManagementFields(): void fn() => ['hoo' => 'har'], ]); - $instance = new Conductor($this->mock(Container::class), $internal, $this->mock(Routing::class)); + $instance = new Conductor($this->stub(Container::class), $internal, $this->stub(Routing::class)); $this->assertSame([ 'foo' => 'bar', 'baz' => 'hej', 'hoo' => 'har', - ], $instance->userManagementFields($this->mock(ilObjUser::class))); + ], $instance->userManagementFields($this->stub(ilObjUser::class))); } public static function agreeTypes(): array @@ -317,17 +317,17 @@ public static function agreeTypes(): array private function agreement(string $method, string $gui, string $key, ?ilGlobalTemplateInterface $main_template = null) { - $constraint = $this->mock(Constraint::class); + $constraint = $this->stub(Constraint::class); $ctrl = $this->mock(ilCtrl::class); $ctrl->expects($this->once())->method('setParameterByClass')->with($gui, 'id', 'foo'); - $container = $this->mockTree(Container::class, [ + $container = $this->stubTree(Container::class, [ 'refinery' => ['to' => ['string' => $constraint]], 'http' => ['wrapper' => ['query' => $this->mockMethod(ArrayBasedRequestWrapper::class, 'retrieve', ['id', $constraint], 'foo')]], 'ui' => [ - 'mainTemplate' => $main_template ?? $this->mock(ilGlobalTemplateInterface::class), - 'renderer' => $this->mock(Renderer::class), + 'mainTemplate' => $main_template ?? $this->stub(ilGlobalTemplateInterface::class), + 'renderer' => $this->stub(Renderer::class), ], 'ctrl' => $ctrl, ]); @@ -340,7 +340,7 @@ private function agreement(string $method, string $gui, string $key, ?ilGlobalTe return new Ok($fragment); }); - $instance = new Conductor($container, $internal, $this->mock(Routing::class)); + $instance = new Conductor($container, $internal, $this->stub(Routing::class)); return $instance->$method($gui, 'some cmd'); } diff --git a/components/ILIAS/LegalDocuments/tests/ConfigTest.php b/components/ILIAS/LegalDocuments/tests/ConfigTest.php index 5e8985fc03e7..283e624cc377 100755 --- a/components/ILIAS/LegalDocuments/tests/ConfigTest.php +++ b/components/ILIAS/LegalDocuments/tests/ConfigTest.php @@ -32,30 +32,30 @@ class ConfigTest extends TestCase public function testConstruct(): void { - $this->assertInstanceOf(Config::class, new Config($this->mock(Provide::class))); + $this->assertInstanceOf(Config::class, new Config($this->stub(Provide::class))); } public function testEditable(): void { - $this->assertFalse((new Config($this->mock(Provide::class)))->editable()); - $this->assertTrue((new Config($this->mock(Provide::class), true))->editable()); + $this->assertFalse((new Config($this->stub(Provide::class)))->editable()); + $this->assertTrue((new Config($this->stub(Provide::class), true))->editable()); } public function testAllowEditing(): void { - $this->assertTrue((new Config($this->mock(Provide::class)))->allowEditing()->editable()); + $this->assertTrue((new Config($this->stub(Provide::class)))->allowEditing()->editable()); } public function testEditableLegalDocuments(): void { - $readonly = $this->mock(Provide::class); + $readonly = $this->stub(Provide::class); $provide = $this->mockMethod(Provide::class, 'allowEditing', [], $readonly); $this->assertSame($readonly, (new Config($provide))->allowEditing()->legalDocuments()); } public function testNonEditableLegalDocuments(): void { - $provide = $this->mockMethod(Provide::class, 'allowEditing', [], $this->mock(Provide::class), $this->never()); + $provide = $this->mockMethod(Provide::class, 'allowEditing', [], $this->stub(Provide::class), $this->never()); $this->assertSame($provide, (new Config($provide))->legalDocuments()); } } diff --git a/components/ILIAS/LegalDocuments/tests/ConsumerSlots/SelfRegistration/BundleTest.php b/components/ILIAS/LegalDocuments/tests/ConsumerSlots/SelfRegistration/BundleTest.php index f2be56eaceb4..ddae8c4f7e71 100755 --- a/components/ILIAS/LegalDocuments/tests/ConsumerSlots/SelfRegistration/BundleTest.php +++ b/components/ILIAS/LegalDocuments/tests/ConsumerSlots/SelfRegistration/BundleTest.php @@ -41,20 +41,20 @@ public function testConstruct(): void public function testLegacyInputGUIs(): void { - $a = $this->mock(ilFormPropertyGUI::class); - $b = $this->mock(ilFormPropertyGUI::class); - $c = $this->mock(ilFormPropertyGUI::class); + $a = $this->stub(ilFormPropertyGUI::class); + $b = $this->stub(ilFormPropertyGUI::class); + $c = $this->stub(ilFormPropertyGUI::class); $bundle = new Bundle([ - $this->mockTree(SelfRegistration::class, ['legacyInputGUIs' => [$a]]), - $this->mockTree(SelfRegistration::class, ['legacyInputGUIs' => [$b, $c]]) + $this->stubTree(SelfRegistration::class, ['legacyInputGUIs' => [$a]]), + $this->stubTree(SelfRegistration::class, ['legacyInputGUIs' => [$b, $c]]) ]); $this->assertSame([$a, $b, $c], $bundle->legacyInputGUIs()); } public function testSaveLegacyForm(): void { - $form = $this->mock(ilPropertyFormGUI::class); + $form = $this->stub(ilPropertyFormGUI::class); $bundle = new Bundle([ $this->mockMethod(SelfRegistration::class, 'saveLegacyForm', [$form], true), @@ -66,7 +66,7 @@ public function testSaveLegacyForm(): void public function testUserCreation(): void { - $user = $this->mock(ilObjUser::class); + $user = $this->stub(ilObjUser::class); $self_registration = $this->mock(SelfRegistration::class); $self_registration->expects($this->exactly(2))->method('userCreation')->with($user); diff --git a/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/BlocksTest.php b/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/BlocksTest.php index cd463be632d5..a798a096a15d 100755 --- a/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/BlocksTest.php +++ b/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/BlocksTest.php @@ -27,7 +27,6 @@ use ILIAS\Refinery\Factory as Refinery; use ILIAS\HTTP\Wrapper\ArrayBasedRequestWrapper; use ILIAS\DI\UIServices; -use ILIAS\UI\Factory as UIFactory; use ILIAS\LegalDocuments\ConsumerToolbox\User; use ILIAS\LegalDocuments\ConsumerToolbox\UserSettings; use ILIAS\LegalDocuments\ConsumerToolbox\Settings; @@ -45,7 +44,6 @@ use ilObjUser; use ilSetting; use ilLanguage; -use ilGlobalTemplateInterface; use ilCtrl; use stdClass; use DateTimeImmutable; @@ -59,23 +57,23 @@ class BlocksTest extends TestCase public function testConstruct(): void { - $this->assertInstanceOf(Blocks::class, new Blocks('foo', $this->mock(Container::class), $this->mock(Provide::class))); + $this->assertInstanceOf(Blocks::class, new Blocks('foo', $this->stub(Container::class), $this->stub(Provide::class))); } public function testConstructors(): void { - $instance = new Blocks('foo', $this->mock(Container::class), $this->mock(Provide::class)); + $instance = new Blocks('foo', $this->stub(Container::class), $this->stub(Provide::class)); $this->assertInstanceOf(DefaultMappings::class, $instance->defaultMappings()); $this->assertInstanceOf(Marshal::class, $instance->marshal()); - $this->assertInstanceOf(SelectSetting::class, $instance->selectSettingsFrom($this->mock(KeyValueStore::class))); - $this->assertInstanceOf(KeyValueStore::class, $instance->readOnlyStore($this->mock(KeyValueStore::class))); - $this->assertInstanceOf(KeyValueStore::class, $instance->userStore($this->mock(ilObjUser::class))); + $this->assertInstanceOf(SelectSetting::class, $instance->selectSettingsFrom($this->stub(KeyValueStore::class))); + $this->assertInstanceOf(KeyValueStore::class, $instance->readOnlyStore($this->stub(KeyValueStore::class))); + $this->assertInstanceOf(KeyValueStore::class, $instance->userStore($this->stub(ilObjUser::class))); $this->assertInstanceOf(KeyValueStore::class, $instance->sessionStore()); $this->assertInstanceOf(User::class, $instance->user( - $this->mock(Settings::class), - $this->mock(UserSettings::class), - $this->mock(ilObjUser::class) + $this->stub(Settings::class), + $this->stub(UserSettings::class), + $this->stub(ilObjUser::class) )); } @@ -83,8 +81,8 @@ public function testGlobalStore(): void { $instance = new Blocks( 'foo', - $this->mockMethod(Container::class, 'settings', [], $this->mock(ilSetting::class)), - $this->mock(Provide::class) + $this->mockMethod(Container::class, 'settings', [], $this->stub(ilSetting::class)), + $this->stub(Provide::class) ); $this->assertInstanceOf(KeyValueStore::class, $instance->globalStore()); @@ -94,13 +92,13 @@ public function testGlobalStore(): void public function testUi(): void { $container = $this->mock(Container::class); - $container->expects($this->once())->method('ui')->willReturn($this->mock(UIServices::class)); - $container->expects($this->once())->method('language')->willReturn($this->mock(ilLanguage::class)); + $container->expects($this->once())->method('ui')->willReturn($this->stub(UIServices::class)); + $container->expects($this->once())->method('language')->willReturn($this->stub(ilLanguage::class)); $instance = new Blocks( 'foo', $container, - $this->mock(Provide::class) + $this->stub(Provide::class) ); $this->assertInstanceOf(UI::class, $instance->ui()); @@ -108,9 +106,9 @@ public function testUi(): void public function testRouting(): void { - $container = $this->mockMethod(Container::class, 'ctrl', [], $this->mock(ilCtrl::class)); + $container = $this->mockMethod(Container::class, 'ctrl', [], $this->stub(ilCtrl::class)); - $instance = new Blocks('foo', $container, $this->mock(Provide::class)); + $instance = new Blocks('foo', $container, $this->stub(Provide::class)); $this->assertInstanceOf(Routing::class, $instance->routing()); } @@ -119,10 +117,10 @@ public function testRetrieveQueryParameter(): void $selected = new stdClass(); $called = false; - $refinery = $this->mock(Refinery::class); - $transformation = $this->mock(Transformation::class); + $refinery = $this->stub(Refinery::class); + $transformation = $this->stub(Transformation::class); - $container = $this->mockTree(Container::class, [ + $container = $this->stubTree(Container::class, [ 'refinery' => $refinery, 'http' => [ 'wrapper' => [ @@ -131,7 +129,7 @@ public function testRetrieveQueryParameter(): void ], ]); - $instance = new Blocks('foo', $container, $this->mock(Provide::class)); + $instance = new Blocks('foo', $container, $this->stub(Provide::class)); $result = $instance->retrieveQueryParameter('bar', function (Refinery $r) use (&$called, $transformation, $refinery): object { $this->assertSame($refinery, $r); $called = true; @@ -147,9 +145,9 @@ public function testUserManagementAgreeDateField(): void $result = $this->mockTree(Result::class, ['value' => 'dummy']); $result->expects($this->once())->method('map')->willReturn($result); $result->expects($this->once())->method('except')->willReturn($result); - $user = $this->mock(ilObjUser::class); + $user = $this->stub(ilObjUser::class); $date = new DateTimeImmutable(); - $ldoc_user = $this->mockTree(User::class, [ + $ldoc_user = $this->stubTree(User::class, [ 'agreeDate' => ['value' => $date], 'acceptedVersion' => $result, ]); @@ -165,8 +163,8 @@ public function testUserManagementAgreeDateField(): void $instance = new Blocks( 'foo', - $this->mockTree(Container::class, ['language' => $language]), - $this->mock(Provide::class), + $this->stubTree(Container::class, ['language' => $language]), + $this->stub(Provide::class), function (DateTimeImmutable $d) use ($date) { $this->assertSame($date, $d); return 'formatted date'; @@ -185,7 +183,7 @@ public function testWithRequest(): void $data = new stdClass(); $called = false; - $container = $this->mockTree(Container::class, [ + $container = $this->stubTree(Container::class, [ 'http' => ['request' => $this->mockMethod(ServerRequestInterface::class, 'getMethod', [], 'POST')], ]); @@ -193,7 +191,7 @@ public function testWithRequest(): void $form->expects($this->once())->method('withRequest')->with($container->http()->request())->willReturn($form); $form->expects($this->once())->method('getData')->willReturn($data); - $instance = new Blocks('foo', $container, $this->mock(Provide::class)); + $instance = new Blocks('foo', $container, $this->stub(Provide::class)); $this->assertSame($form, $instance->withRequest($form, function ($x) use ($data, &$called) { $this->assertSame($data, $x); $called = true; @@ -203,13 +201,13 @@ public function testWithRequest(): void public function testWithoutRequest(): void { - $container = $this->mockTree(Container::class, [ + $container = $this->stubTree(Container::class, [ 'http' => ['request' => ['getMethod' => 'GET']], ]); - $form = $this->mock(Form::class); + $form = $this->stub(Form::class); - $instance = new Blocks('foo', $container, $this->mock(Provide::class)); + $instance = new Blocks('foo', $container, $this->stub(Provide::class)); $result = $instance->withRequest($form, $this->fail(...)); $this->assertSame($form, $result); } @@ -217,9 +215,9 @@ public function testWithoutRequest(): void public function testNotAvailable(): void { $called = false; - $container = $this->mockTree(Container::class, []); + $container = $this->stubTree(Container::class, []); - $instance = new Blocks('foo', $container, $this->mock(Provide::class), null, function () use (&$called): string { + $instance = new Blocks('foo', $container, $this->stub(Provide::class), null, function () use (&$called): string { $called = true; return 'bar'; }); diff --git a/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/ConsumerSlots/AgreementTest.php b/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/ConsumerSlots/AgreementTest.php index 550f34baa0d9..d9f18919487e 100755 --- a/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/ConsumerSlots/AgreementTest.php +++ b/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/ConsumerSlots/AgreementTest.php @@ -40,9 +40,9 @@ class AgreementTest extends TestCase public function testConstruct(): void { $this->assertInstanceOf(Agreement::class, new Agreement( - $this->mock(User::class), - $this->mock(UI::class), - $this->mock(Routing::class), + $this->stub(User::class), + $this->stub(UI::class), + $this->stub(Routing::class), $this->fail(...) )); } @@ -50,9 +50,9 @@ public function testConstruct(): void public function testShowAgreement(): void { $instance = new Agreement( - $this->mockTree(User::class, ['matchingDocument' => new Ok($this->mock(Document::class))]), - $this->mock(UI::class), - $this->mock(Routing::class), + $this->stubTree(User::class, ['matchingDocument' => new Ok($this->stub(Document::class))]), + $this->stub(UI::class), + $this->stub(Routing::class), $this->fail(...) ); @@ -62,10 +62,10 @@ public function testShowAgreement(): void public function testShowAgreementForm(): void { $instance = new Agreement( - $this->mockTree(User::class, ['matchingDocument' => new Ok($this->mock(Document::class))]), - $this->mock(UI::class), - $this->mock(Routing::class), - fn() => $this->mock(Component::class) + $this->stubTree(User::class, ['matchingDocument' => new Ok($this->stub(Document::class))]), + $this->stub(UI::class), + $this->stub(Routing::class), + fn() => $this->stub(Component::class) ); $this->assertInstanceOf(ShowOnScreenMessage::class, $instance->showAgreementForm('foo', 'bar')); @@ -74,13 +74,13 @@ public function testShowAgreementForm(): void public function testNeedsToAgree(): void { $instance = new Agreement( - $this->mockTree(User::class, [ + $this->stubTree(User::class, [ 'cannotAgree' => false, 'neverAgreed' => false, 'didNotAcceptCurrentVersion' => false, ]), - $this->mock(UI::class), - $this->mock(Routing::class), + $this->stub(UI::class), + $this->stub(Routing::class), $this->fail(...) ); @@ -90,12 +90,12 @@ public function testNeedsToAgree(): void public function testCannotAgree(): void { $instance = new Agreement( - $this->mockTree(User::class, [ + $this->stubTree(User::class, [ 'cannotAgree' => true, 'didNotAcceptCurrentVersion' => true, ]), - $this->mock(UI::class), - $this->mock(Routing::class), + $this->stub(UI::class), + $this->stub(Routing::class), $this->fail(...) ); @@ -105,12 +105,12 @@ public function testCannotAgree(): void public function testDidNotAcceptCurrentVersion(): void { $instance = new Agreement( - $this->mockTree(User::class, [ + $this->stubTree(User::class, [ 'cannotAgree' => false, 'needsToAcceptNewDocument' => true, ]), - $this->mock(UI::class), - $this->mock(Routing::class), + $this->stub(UI::class), + $this->stub(Routing::class), $this->fail(...) ); diff --git a/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/ConsumerSlots/ModifyFooterTest.php b/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/ConsumerSlots/ModifyFooterTest.php index 6c6e0d1c5084..bfa0b0c5883a 100755 --- a/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/ConsumerSlots/ModifyFooterTest.php +++ b/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/ConsumerSlots/ModifyFooterTest.php @@ -26,7 +26,6 @@ use ILIAS\LegalDocuments\Value\DocumentContent; use ilTemplate; use ILIAS\Data\Result\Ok; -use ILIAS\UI\Component\MainControls\Footer; use ILIAS\LegalDocuments\test\ContainerMock; use ILIAS\LegalDocuments\Provide; use ILIAS\LegalDocuments\ConsumerToolbox\User; @@ -43,9 +42,9 @@ class ModifyFooterTest extends TestCase public function testConstruct(): void { $this->assertInstanceOf(ModifyFooter::class, new ModifyFooter( - $this->mock(UI::class), - $this->mock(User::class), - $this->mock(Provide::class), + $this->stub(UI::class), + $this->stub(User::class), + $this->stub(Provide::class), $this->fail(...), $this->fail(...), null, @@ -58,11 +57,11 @@ public function testInvoke(): void $footer = fn() => $return; $instance = new ModifyFooter( - $this->mock(UI::class), - $this->mockTree(User::class, ['acceptedVersion' => new Ok($this->mock(DocumentContent::class))]), - $this->mock(Provide::class), + $this->stub(UI::class), + $this->stubTree(User::class, ['acceptedVersion' => new Ok($this->stub(DocumentContent::class))]), + $this->stub(Provide::class), fn() => 'rendered', - fn() => $this->mock(ilTemplate::class), + fn() => $this->stub(ilTemplate::class), null, ); @@ -71,7 +70,7 @@ public function testInvoke(): void public function testInvokeWithGotoLink(): void { - $dummy_uri = $this->mock(URI::class); + $dummy_uri = $this->stub(URI::class); $return = fn() => null; $footer = function ($id, $title, $uri) use ($dummy_uri, $return) { $this->assertSame('foo', $id); @@ -81,11 +80,11 @@ public function testInvokeWithGotoLink(): void }; $instance = new ModifyFooter( - $this->mockTree(UI::class, ['txt' => 'translated']), - $this->mockTree(User::class, ['acceptedVersion' => new Error('Not found.'), 'isLoggedIn' => false]), - $this->mockTree(Provide::class, ['id' => 'foo']), + $this->stubTree(UI::class, ['txt' => 'translated']), + $this->stubTree(User::class, ['acceptedVersion' => new Error('Not found.'), 'isLoggedIn' => false]), + $this->stubTree(Provide::class, ['id' => 'foo']), fn() => 'rendered', - fn() => $this->mock(ilTemplate::class), + fn() => $this->stub(ilTemplate::class), fn() => $dummy_uri, ); @@ -95,15 +94,15 @@ public function testInvokeWithGotoLink(): void public function testRenderModal(): void { $instance = new ModifyFooter( - $this->mock(UI::class), - $this->mock(User::class), - $this->mock(Provide::class), + $this->stub(UI::class), + $this->stub(User::class), + $this->stub(Provide::class), fn() => 'rendered', - fn() => $this->mock(ilTemplate::class), + fn() => $this->stub(ilTemplate::class), null ); - $modal = $instance->renderModal($this->mock(DocumentContent::class)); + $modal = $instance->renderModal($this->stub(DocumentContent::class)); $this->assertInstanceOf(Modal::class, $modal); } @@ -114,9 +113,9 @@ public function testWithdrawalButton(): void $template->expects($this->once())->method('get'); $instance = new ModifyFooter( - $this->mock(UI::class), - $this->mock(User::class), - $this->mock(Provide::class), + $this->stub(UI::class), + $this->stub(User::class), + $this->stub(Provide::class), fn() => 'rendered', fn() => $template, null diff --git a/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/ConsumerSlots/OnlineStatusFilterTest.php b/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/ConsumerSlots/OnlineStatusFilterTest.php index 4060a78beb8d..be53a06dc120 100755 --- a/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/ConsumerSlots/OnlineStatusFilterTest.php +++ b/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/ConsumerSlots/OnlineStatusFilterTest.php @@ -34,7 +34,7 @@ public function testConstruct(): void { $this->assertInstanceOf(OnlineStatusFilter::class, new OnlineStatusFilter( $this->fail(...), - $this->mock(ilRbacReview::class) + $this->stub(ilRbacReview::class) )); } @@ -47,7 +47,7 @@ public function testInvoke(): void define('SYSTEM_USER_ID', 9); } - $rbac = $this->mock(ilRbacReview::class); + $rbac = $this->stub(ilRbacReview::class); $rbac->method('isAssigned')->willReturnCallback(function (int $user, int $role) { $this->assertSame(SYSTEM_ROLE_ID, $role); return $user === 7; diff --git a/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/ConsumerSlots/PublicApiTest.php b/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/ConsumerSlots/PublicApiTest.php index 4ca2b17718cb..56099ae5559f 100644 --- a/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/ConsumerSlots/PublicApiTest.php +++ b/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/ConsumerSlots/PublicApiTest.php @@ -97,11 +97,11 @@ private function assertTrueFalseForMethod(string $method, callable $dpro_user_tr private function assertSameValues(string $method, array $compare): void { - $user = $this->mock(ilObjUser::class); - $dpro_user = fn($ret) => $this->mockTree(User::class, $dpro_user_tree($ret)); + $user = $this->stub(ilObjUser::class); + $dpro_user = fn($ret) => $this->stubTree(User::class, $dpro_user_tree($ret)); foreach ($compare as $pair) { - $this->assertSame($pair[0], (new PublicApi(true, fn() => $this->mockTree(User::class, $pair[1])))->$method($user)); + $this->assertSame($pair[0], (new PublicApi(true, fn() => $this->stubTree(User::class, $pair[1])))->$method($user)); } } } diff --git a/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/ConsumerSlots/SelfRegistrationTest.php b/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/ConsumerSlots/SelfRegistrationTest.php index 9abea2facec6..c345af562500 100755 --- a/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/ConsumerSlots/SelfRegistrationTest.php +++ b/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/ConsumerSlots/SelfRegistrationTest.php @@ -41,9 +41,9 @@ public function testConstruct(): void { $this->assertInstanceOf(SelfRegistration::class, new SelfRegistration( 'foo', - $this->mock(UI::class), - $this->mock(User::class), - $this->mock(Provide::class), + $this->stub(UI::class), + $this->stub(User::class), + $this->stub(Provide::class), $this->fail(...), $this->fail(...) )); @@ -53,12 +53,12 @@ public function testLegacyInputGUIs(): void { $instance = new SelfRegistration( 'foo', - $this->mock(UI::class), - $this->mockTree(User::class, ['matchingDocument' => new Ok($this->mock(Document::class))]), - $this->mock(Provide::class), + $this->stub(UI::class), + $this->stubTree(User::class, ['matchingDocument' => new Ok($this->stub(Document::class))]), + $this->stub(Provide::class), fn() => 'rendered', $this->fail(...), - $this->mock(...) + $this->stub(...) ); $guis = $instance->legacyInputGUIs(); @@ -69,24 +69,24 @@ public function testSaveLegacyForm(): void { $instance = new SelfRegistration( 'foo', - $this->mock(UI::class), - $this->mockTree(User::class, ['matchingDocument' => new Ok($this->mock(Document::class))]), - $this->mock(Provide::class), + $this->stub(UI::class), + $this->stubTree(User::class, ['matchingDocument' => new Ok($this->stub(Document::class))]), + $this->stub(Provide::class), $this->fail(...), $this->fail(...), $this->fail(...) ); - $this->assertTrue($instance->saveLegacyForm($this->mockTree(ilPropertyFormGUI::class, ['getInput' => true]))); + $this->assertTrue($instance->saveLegacyForm($this->stubTree(ilPropertyFormGUI::class, ['getInput' => true]))); } public function testSaveLegacyFormFailed(): void { $instance = new SelfRegistration( 'foo', - $this->mock(UI::class), - $this->mockTree(User::class, ['matchingDocument' => new Ok($this->mock(Document::class))]), - $this->mock(Provide::class), + $this->stub(UI::class), + $this->stubTree(User::class, ['matchingDocument' => new Ok($this->stub(Document::class))]), + $this->stub(Provide::class), $this->fail(...), $this->fail(...), $this->fail(...) @@ -103,15 +103,15 @@ public function testSaveLegacyFormFailed(): void public function testUserCreation(): void { - $user = $this->mock(ilObjUser::class); + $user = $this->stub(ilObjUser::class); $ldoc_user = $this->mock(User::class); $ldoc_user->expects($this->once())->method('acceptMatchingDocument'); $instance = new SelfRegistration( 'foo', - $this->mock(UI::class), - $this->mock(User::class), - $this->mock(Provide::class), + $this->stub(UI::class), + $this->stub(User::class), + $this->stub(Provide::class), $this->fail(...), function (ilObjUser $u) use ($user, $ldoc_user): User { $this->assertSame($user, $u); @@ -125,7 +125,7 @@ function (ilObjUser $u) use ($user, $ldoc_user): User { public function testUserCreationFailed(): void { - $user = $this->mock(ilObjUser::class); + $user = $this->stub(ilObjUser::class); $ldoc_user = $this->mock(User::class); $ldoc_user->expects($this->once())->method('acceptMatchingDocument')->willReturnCallback(function () { throw new \ILIAS\Data\NotOKException('This is not ok.'); @@ -135,9 +135,9 @@ public function testUserCreationFailed(): void $instance = new SelfRegistration( 'foo', - $this->mock(UI::class), - $this->mock(User::class), - $this->mock(Provide::class), + $this->stub(UI::class), + $this->stub(User::class), + $this->stub(Provide::class), $this->fail(...), function (ilObjUser $u) use ($user, $ldoc_user): User { $this->assertSame($user, $u); diff --git a/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/ConsumerSlots/ShowOnLoginPageTest.php b/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/ConsumerSlots/ShowOnLoginPageTest.php index af87a843c07e..ca54d16bfdb1 100755 --- a/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/ConsumerSlots/ShowOnLoginPageTest.php +++ b/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/ConsumerSlots/ShowOnLoginPageTest.php @@ -36,14 +36,14 @@ class ShowOnLoginPageTest extends TestCase public function testConstruct(): void { - $this->assertInstanceOf(ShowOnLoginPage::class, new ShowOnLoginPage($this->mock(Provide::class), $this->mock(UI::class), $this->fail(...))); + $this->assertInstanceOf(ShowOnLoginPage::class, new ShowOnLoginPage($this->stub(Provide::class), $this->stub(UI::class), $this->fail(...))); } public function testInvokeWithoutDocuments(): void { - $instance = new ShowOnLoginPage($this->mockTree(Provide::class, [ + $instance = new ShowOnLoginPage($this->stubTree(Provide::class, [ 'document' => ['repository' => ['countAll' => 0]], - ]), $this->mock(UI::class), $this->fail(...)); + ]), $this->stub(UI::class), $this->fail(...)); $this->assertSame([], $instance()); } @@ -53,7 +53,7 @@ public function testInvoke(): void $translated = 'Translated
'; $url = 'Dummy URL'; - $legacy = $this->mock(Legacy\Content::class); + $legacy = $this->stub(Legacy\Content::class); $legacy_factory = $this->mock(Legacy\Factory::class); $legacy_factory ->expects($this->once()) @@ -79,10 +79,10 @@ function (string $k, string $v) use (&$expected) { $template->expects($this->once())->method('get')->willReturn('Rendered'); - $instance = new ShowOnLoginPage($this->mockTree(Provide::class, [ + $instance = new ShowOnLoginPage($this->stubTree(Provide::class, [ 'document' => ['repository' => ['countAll' => 1]], 'publicPage' => ['url' => $url], - ]), $this->mockTree(UI::class, [ + ]), $this->stubTree(UI::class, [ 'txt' => $translated, 'create' => $this->mockMethod(UIFactory::class, 'legacy', [], $legacy_factory), ]), fn() => $template); diff --git a/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/ConsumerSlots/WithdrawProcessTest.php b/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/ConsumerSlots/WithdrawProcessTest.php index 78046b3dab63..0b2e5cfd0a2e 100755 --- a/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/ConsumerSlots/WithdrawProcessTest.php +++ b/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/ConsumerSlots/WithdrawProcessTest.php @@ -41,12 +41,12 @@ class WithdrawProcessTest extends TestCase public function testConstruct(): void { $this->assertInstanceOf(WithdrawProcess::class, new WithdrawProcess( - $this->mock(User::class), - $this->mock(UI::class), - $this->mock(Routing::class), - $this->mock(Settings::class), + $this->stub(User::class), + $this->stub(UI::class), + $this->stub(Routing::class), + $this->stub(Settings::class), $this->fail(...), - $this->mock(Provide::class), + $this->stub(Provide::class), $this->fail(...) )); } @@ -54,12 +54,12 @@ public function testConstruct(): void public function testShowValidatePasswordMessage(): void { $instance = new WithdrawProcess( - $this->mock(User::class), - $this->mock(UI::class), - $this->mock(Routing::class), - $this->mock(Settings::class), + $this->stub(User::class), + $this->stub(UI::class), + $this->stub(Routing::class), + $this->stub(Settings::class), fn() => 'internal', - $this->mock(Provide::class), + $this->stub(Provide::class), $this->fail(...) ); @@ -72,12 +72,12 @@ public function testShowValidatePasswordMessage(): void public function testIsOnGoing(): void { $instance = new WithdrawProcess( - $this->mockTree(User::class, ['withdrawalRequested' => ['value' => true]]), - $this->mock(UI::class), - $this->mock(Routing::class), - $this->mock(Settings::class), + $this->stubTree(User::class, ['withdrawalRequested' => ['value' => true]]), + $this->stub(UI::class), + $this->stub(Routing::class), + $this->stub(Settings::class), $this->fail(...), - $this->mock(Provide::class), + $this->stub(Provide::class), $this->fail(...) ); @@ -90,12 +90,12 @@ public function testWithdrawalRequested(): void $setting->expects($this->once())->method('update')->with(true); $instance = new WithdrawProcess( - $this->mockTree(User::class, ['cannotAgree' => false, 'neverAgreed' => false, 'withdrawalRequested' => $setting]), - $this->mock(UI::class), - $this->mock(Routing::class), - $this->mock(Settings::class), + $this->stubTree(User::class, ['cannotAgree' => false, 'neverAgreed' => false, 'withdrawalRequested' => $setting]), + $this->stub(UI::class), + $this->stub(Routing::class), + $this->stub(Settings::class), $this->fail(...), - $this->mock(Provide::class), + $this->stub(Provide::class), $this->fail(...) ); @@ -107,12 +107,12 @@ public function testWithdrawalRequested(): void public function testWithdrawalRequestedWithInvalidUser(): void { $instance = new WithdrawProcess( - $this->mockTree(User::class, ['cannotAgree' => true, 'neverAgreed' => false]), - $this->mock(UI::class), - $this->mock(Routing::class), - $this->mock(Settings::class), + $this->stubTree(User::class, ['cannotAgree' => true, 'neverAgreed' => false]), + $this->stub(UI::class), + $this->stub(Routing::class), + $this->stub(Settings::class), $this->fail(...), - $this->mock(Provide::class), + $this->stub(Provide::class), $this->fail(...) ); @@ -128,12 +128,12 @@ public function testWithdrawalFinished(): void $main_template->expects($this->once())->method('setOnScreenMessage'); $instance = new WithdrawProcess( - $this->mock(User::class), - $this->mockTree(UI::class, ['mainTemplate' => $main_template]), - $this->mock(Routing::class), - $this->mock(Settings::class), + $this->stub(User::class), + $this->stubTree(UI::class, ['mainTemplate' => $main_template]), + $this->stub(Routing::class), + $this->stub(Settings::class), fn() => null, - $this->mock(Provide::class), + $this->stub(Provide::class), $this->fail(...) ); @@ -143,12 +143,12 @@ public function testWithdrawalFinished(): void public function testShowWithdraw(): void { $instance = new WithdrawProcess( - $this->mock(User::class), - $this->mock(UI::class), - $this->mock(Routing::class), - $this->mock(Settings::class), + $this->stub(User::class), + $this->stub(UI::class), + $this->stub(Routing::class), + $this->stub(Settings::class), $this->fail(...), - $this->mock(Provide::class), + $this->stub(Provide::class), $this->fail(...) ); diff --git a/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/ConvertTest.php b/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/ConvertTest.php index 121bc396bf06..922eb268559a 100755 --- a/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/ConvertTest.php +++ b/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/ConvertTest.php @@ -33,14 +33,14 @@ class ConvertTest extends TestCase public function testConstruct(): void { - $this->assertInstanceOf(Convert::class, new Convert($this->mock(Transformation::class), $this->mock(Transformation::class))); + $this->assertInstanceOf(Convert::class, new Convert($this->stub(Transformation::class), $this->stub(Transformation::class))); } public function testGetter(): void { $this->assertGetter(Convert::class, [ - 'fromString' => $this->mock(Transformation::class), - 'toString' => $this->mock(Transformation::class), + 'fromString' => $this->stub(Transformation::class), + 'toString' => $this->stub(Transformation::class), ]); } } diff --git a/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/KeyValueStore/ILIASSettingStoreTest.php b/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/KeyValueStore/ILIASSettingStoreTest.php index 82307fdc4091..c0c6fe0f6445 100755 --- a/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/KeyValueStore/ILIASSettingStoreTest.php +++ b/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/KeyValueStore/ILIASSettingStoreTest.php @@ -33,7 +33,7 @@ class ILIASSettingStoreTest extends TestCase public function testConstruct(): void { - $this->assertInstanceOf(ILIASSettingStore::class, new ILIASSettingStore($this->mock(ilSetting::class))); + $this->assertInstanceOf(ILIASSettingStore::class, new ILIASSettingStore($this->stub(ilSetting::class))); } public function testValue(): void diff --git a/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/KeyValueStore/ReadOnlyStoreTest.php b/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/KeyValueStore/ReadOnlyStoreTest.php index d4695fbba04e..3aac4bf06020 100755 --- a/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/KeyValueStore/ReadOnlyStoreTest.php +++ b/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/KeyValueStore/ReadOnlyStoreTest.php @@ -34,7 +34,7 @@ class ReadOnlyStoreTest extends TestCase public function testConstruct(): void { - $this->assertInstanceOf(ReadOnlyStore::class, new ReadOnlyStore($this->mock(KeyValueStore::class))); + $this->assertInstanceOf(ReadOnlyStore::class, new ReadOnlyStore($this->stub(KeyValueStore::class))); } public function testValue(): void @@ -48,7 +48,7 @@ public function testUpdate(): void { $this->expectException(Exception::class); - $instance = new ReadOnlyStore($this->mock(KeyValueStore::class)); + $instance = new ReadOnlyStore($this->stub(KeyValueStore::class)); $instance->update('foo', 'bar'); } } diff --git a/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/KeyValueStore/UserPreferenceStoreTest.php b/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/KeyValueStore/UserPreferenceStoreTest.php index a0d7dc022e5e..41e7e222bdfa 100755 --- a/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/KeyValueStore/UserPreferenceStoreTest.php +++ b/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/KeyValueStore/UserPreferenceStoreTest.php @@ -33,7 +33,7 @@ class UserPreferenceStoreTest extends TestCase public function testConstruct(): void { - $this->assertInstanceOf(UserPreferenceStore::class, new UserPreferenceStore($this->mock(ilObjUser::class))); + $this->assertInstanceOf(UserPreferenceStore::class, new UserPreferenceStore($this->stub(ilObjUser::class))); } public function testValue(): void diff --git a/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/MarshalTest.php b/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/MarshalTest.php index 799f59417994..c61e4f676b14 100755 --- a/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/MarshalTest.php +++ b/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/MarshalTest.php @@ -38,16 +38,16 @@ class MarshalTest extends TestCase public function testConstruct(): void { - $this->assertInstanceOf(Marshal::class, new Marshal($this->mock(Refinery::class))); + $this->assertInstanceOf(Marshal::class, new Marshal($this->stub(Refinery::class))); } public function testDateTime(): void { - $from = $this->mock(Transformation::class); - $custom = $this->mock(Transformation::class); - $date = $this->mock(Transformation::class); + $from = $this->stub(Transformation::class); + $custom = $this->stub(Transformation::class); + $date = $this->stub(Transformation::class); - $refinery = $this->mockTree(Refinery::class, [ + $refinery = $this->stubTree(Refinery::class, [ 'in' => $this->mockMethod(In::class, 'series', [[$custom, $date]], $from), 'custom' => ['transformation' => $custom], 'to' => ['dateTime' => $date], @@ -60,10 +60,10 @@ public function testDateTime(): void public function testBoolean(): void { - $from = $this->mock(ByTrying::class); - $custom = $this->mock(Transformation::class); - $bool = $this->mock(Transformation::class); - $to = $this->mock(Transformation::class); + $from = $this->stub(ByTrying::class); + $custom = $this->stub(Transformation::class); + $bool = $this->stub(Transformation::class); + $to = $this->stub(Transformation::class); $refinery = $this->mockTree(Refinery::class, [ 'custom' => ['transformation' => $custom], @@ -78,16 +78,16 @@ public function testBoolean(): void public function testNullable(): void { - $decorate = $this->mockTree(Convert::class, [ - 'fromString' => $this->mock(Transformation::class), - 'toString' => $this->mock(Transformation::class), + $decorate = $this->stubTree(Convert::class, [ + 'fromString' => $this->stub(Transformation::class), + 'toString' => $this->stub(Transformation::class), ]); - $by_trying = $this->mock(ByTrying::class); - $nice_null = $this->mock(Transformation::class); - $null = $this->mock(Constraint::class); - $always = $this->mock(Transformation::class); - $series = $this->mock(Transformation::class); + $by_trying = $this->stub(ByTrying::class); + $nice_null = $this->stub(Transformation::class); + $null = $this->stub(Constraint::class); + $always = $this->stub(Transformation::class); + $series = $this->stub(Transformation::class); $refinery = $this->mockTree(Refinery::class, [ 'kindlyTo' => ['null' => $nice_null], @@ -110,9 +110,9 @@ public function testNullable(): void public function testString(): void { - $id = $this->mock(Transformation::class); + $id = $this->stub(Transformation::class); - $convert = (new Marshal($this->mockTree(Refinery::class, ['identity' => $id])))->string(); + $convert = (new Marshal($this->stubTree(Refinery::class, ['identity' => $id])))->string(); $this->assertSame($id, $convert->fromString()); $this->assertSame($id, $convert->toString()); } diff --git a/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/RoutingTest.php b/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/RoutingTest.php index f16dc69399c4..a2df394dac8b 100755 --- a/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/RoutingTest.php +++ b/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/RoutingTest.php @@ -36,8 +36,8 @@ class RoutingTest extends TestCase public function testConstruct(): void { $this->assertInstanceOf(Routing::class, new Routing( - $this->mock(ilCtrl::class), - $this->mock(SelectSetting::class), + $this->stub(ilCtrl::class), + $this->stub(SelectSetting::class), $this->fail(...), $this->fail(...) )); @@ -45,15 +45,15 @@ public function testConstruct(): void public function testCtrl(): void { - $ctrl = $this->mock(ilCtrl::class); - $this->assertSame($ctrl, (new Routing($ctrl, $this->mock(SelectSetting::class), $this->fail(...), $this->fail(...)))->ctrl()); + $ctrl = $this->stub(ilCtrl::class); + $this->assertSame($ctrl, (new Routing($ctrl, $this->stub(SelectSetting::class), $this->fail(...), $this->fail(...)))->ctrl()); } public function testLogoutUrl(): void { $this->assertSame('dummy logout url', (new Routing( - $this->mock(ilCtrl::class), - $this->mock(SelectSetting::class), + $this->stub(ilCtrl::class), + $this->stub(SelectSetting::class), $this->fail(...), fn() => 'dummy logout url' ))->logoutUrl()); @@ -66,11 +66,11 @@ public function testRedirectToStartingPage(): void $session = $this->mock(SelectSetting::class); $session->expects($this->once())->method('typed')->willReturnCallback(function (string $key, callable $proc) { $this->assertSame('orig_request_target', $key); - return $this->mockTree(Setting::class, ['value' => null]); + return $this->stubTree(Setting::class, ['value' => null]); }); (new Routing( - $this->mock(ilCtrl::class), + $this->stub(ilCtrl::class), $session, static function () use (&$called): void { $called = true; @@ -87,7 +87,7 @@ public function testRedirectToOriginalTarget(): void $setting->method('value')->willReturn('some url'); $setting->expects($this->once())->method('update')->with(null); - $session = $this->mock(SelectSetting::class); + $session = $this->stub(SelectSetting::class); $session->method('typed')->willReturnCallback(function (string $key, callable $proc) use ($setting) { $this->assertSame('orig_request_target', $key); diff --git a/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/SelectSettingTest.php b/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/SelectSettingTest.php index 47872990525d..11f86b8eb063 100755 --- a/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/SelectSettingTest.php +++ b/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/SelectSettingTest.php @@ -37,7 +37,7 @@ class SelectSettingTest extends TestCase public function testConstruct(): void { - $this->assertInstanceOf(SelectSetting::class, new SelectSetting($this->mock(KeyValueStore::class), $this->mock(Marshal::class))); + $this->assertInstanceOf(SelectSetting::class, new SelectSetting($this->stub(KeyValueStore::class), $this->stub(Marshal::class))); } public function testTyped(): void @@ -47,8 +47,8 @@ public function testTyped(): void $set_value = new stdClass(); $value = new stdClass(); - $marshal = $this->mock(Marshal::class); - $convert = $this->mockTree(Convert::class, [ + $marshal = $this->stub(Marshal::class); + $convert = $this->stubTree(Convert::class, [ 'fromString' => $this->mockMethod(Transformation::class, 'transform', [$read_value], $value), 'toString' => $this->mockMethod(Transformation::class, 'transform', [$set_value], $write_value), ]); diff --git a/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/SlotTest.php b/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/SlotTest.php index 05823e73895a..61cbd2d3e96b 100755 --- a/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/SlotTest.php +++ b/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/SlotTest.php @@ -45,9 +45,9 @@ public function testConstruct(): void { $this->assertInstanceOf(Slot::class, new Slot( 'foo', - $this->mock(Blocks::class), - $this->mock(LazyProvide::class), - $this->mock(Container::class) + $this->stub(Blocks::class), + $this->stub(LazyProvide::class), + $this->stub(Container::class) )); } @@ -55,9 +55,9 @@ public function testShowOnLoginPage(): void { $instance = new Slot( 'foo', - $this->mock(Blocks::class), - $this->mock(LazyProvide::class), - $this->mock(Container::class) + $this->stub(Blocks::class), + $this->stub(LazyProvide::class), + $this->stub(Container::class) ); $this->assertInstanceOf(ShowOnLoginPage::class, $instance->showOnLoginPage()); @@ -67,56 +67,56 @@ public function testWithdrawProcess(): void { $instance = new Slot( 'foo', - $this->mock(Blocks::class), - $this->mock(LazyProvide::class), - $this->mock(Container::class) + $this->stub(Blocks::class), + $this->stub(LazyProvide::class), + $this->stub(Container::class) ); - $this->assertInstanceOf(WithdrawProcess::class, $instance->withdrawProcess($this->mock(User::class), $this->mock(Settings::class), $this->fail(...))); + $this->assertInstanceOf(WithdrawProcess::class, $instance->withdrawProcess($this->stub(User::class), $this->stub(Settings::class), $this->fail(...))); } public function testAgreement(): void { $instance = new Slot( 'foo', - $this->mock(Blocks::class), - $this->mock(LazyProvide::class), - $this->mock(Container::class) + $this->stub(Blocks::class), + $this->stub(LazyProvide::class), + $this->stub(Container::class) ); - $this->assertInstanceOf(Agreement::class, $instance->agreement($this->mock(User::class), $this->mock(Settings::class))); + $this->assertInstanceOf(Agreement::class, $instance->agreement($this->stub(User::class), $this->stub(Settings::class))); } public function testModifyFooter(): void { $instance = new Slot( 'foo', - $this->mock(Blocks::class), - $this->mock(LazyProvide::class), - $this->mock(Container::class) + $this->stub(Blocks::class), + $this->stub(LazyProvide::class), + $this->stub(Container::class) ); - $this->assertInstanceOf(ModifyFooter::class, $instance->modifyFooter($this->mock(User::class))); + $this->assertInstanceOf(ModifyFooter::class, $instance->modifyFooter($this->stub(User::class))); } public function testSelfRegistration(): void { $instance = new Slot( 'foo', - $this->mock(Blocks::class), - $this->mock(LazyProvide::class), - $this->mock(Container::class) + $this->stub(Blocks::class), + $this->stub(LazyProvide::class), + $this->stub(Container::class) ); - $this->assertInstanceOf(SelfRegistration::class, $instance->selfRegistration($this->mock(User::class), $this->fail(...))); + $this->assertInstanceOf(SelfRegistration::class, $instance->selfRegistration($this->stub(User::class), $this->fail(...))); } public function testOnlineStatusFilter(): void { $instance = $instance = new Slot( 'foo', - $this->mock(Blocks::class), - $this->mock(LazyProvide::class), - $this->mock(Container::class) + $this->stub(Blocks::class), + $this->stub(LazyProvide::class), + $this->stub(Container::class) ); $this->assertInstanceOf(OnlineStatusFilter::class, $instance->onlineStatusFilter($this->fail(...))); diff --git a/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/UITest.php b/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/UITest.php index e1b49a8a7957..8d3eb0928f9f 100755 --- a/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/UITest.php +++ b/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/UITest.php @@ -36,19 +36,19 @@ class UITest extends TestCase public function testConstruct(): void { - $this->assertInstanceOf(UI::class, new UI('foo', $this->mock(UIServices::class), $this->mock(ilLanguage::class))); + $this->assertInstanceOf(UI::class, new UI('foo', $this->stub(UIServices::class), $this->stub(ilLanguage::class))); } public function testCreate(): void { - $ui_factory = $this->mock(UIFactory::class); - $this->assertSame($ui_factory, (new UI('foo', $this->mockTree(UIServices::class, ['factory' => $ui_factory]), $this->mock(ilLanguage::class)))->create()); + $ui_factory = $this->stub(UIFactory::class); + $this->assertSame($ui_factory, (new UI('foo', $this->stubTree(UIServices::class, ['factory' => $ui_factory]), $this->stub(ilLanguage::class)))->create()); } public function testMainTemplate(): void { - $template = $this->mock(ilGlobalTemplateInterface::class); - $this->assertSame($template, (new UI('foo', $this->mockTree(UIServices::class, ['mainTemplate' => $template]), $this->mock(ilLanguage::class)))->mainTemplate()); + $template = $this->stub(ilGlobalTemplateInterface::class); + $this->assertSame($template, (new UI('foo', $this->stubTree(UIServices::class, ['mainTemplate' => $template]), $this->stub(ilLanguage::class)))->mainTemplate()); } public function testTxt(): void @@ -68,7 +68,7 @@ function (string $txt) use (&$consecutive) { return $return; } ); - $instance = new UI('bar', $this->mock(UIServices::class), $language); + $instance = new UI('bar', $this->stub(UIServices::class), $language); $this->assertSame('baz', $instance->txt('foo')); } @@ -86,7 +86,7 @@ function (string $txt) use (&$consecutive) { } ); - $instance = new UI('bar', $this->mock(UIServices::class), $language); + $instance = new UI('bar', $this->stub(UIServices::class), $language); $this->assertSame('baz', $instance->txt('foo')); } } diff --git a/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/UserTest.php b/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/UserTest.php index 3ebd498aa278..df48f340ac40 100755 --- a/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/UserTest.php +++ b/components/ILIAS/LegalDocuments/tests/ConsumerToolbox/UserTest.php @@ -48,11 +48,11 @@ class UserTest extends TestCase public function testConstruct(): void { $this->assertInstanceOf(User::class, new User( - $this->mock(ilObjUser::class), - $this->mock(Settings::class), - $this->mock(UserSettings::class), - $this->mock(Provide::class), - $this->mock(Clock::class) + $this->stub(ilObjUser::class), + $this->stub(Settings::class), + $this->stub(UserSettings::class), + $this->stub(Provide::class), + $this->stub(Clock::class) )); } @@ -65,10 +65,10 @@ public function testIsLoggedIn(): void $instance = new User( $user, - $this->mock(Settings::class), - $this->mock(UserSettings::class), - $this->mock(Provide::class), - $this->mock(Clock::class) + $this->stub(Settings::class), + $this->stub(UserSettings::class), + $this->stub(Provide::class), + $this->stub(Clock::class) ); $this->assertFalse($instance->isLoggedIn()); @@ -88,10 +88,10 @@ public function testCannotAgree(): void $instance = new User( $user, - $this->mock(Settings::class), - $this->mock(UserSettings::class), - $this->mock(Provide::class), - $this->mock(Clock::class) + $this->stub(Settings::class), + $this->stub(UserSettings::class), + $this->stub(Provide::class), + $this->stub(Clock::class) ); $this->assertTrue($instance->cannotAgree()); @@ -110,11 +110,11 @@ public function testNeverAgreed(): void $user_settings->expects($this->exactly(2))->method('agreeDate')->willReturn($setting); $instance = new User( - $this->mock(ilObjUser::class), - $this->mock(Settings::class), + $this->stub(ilObjUser::class), + $this->stub(Settings::class), $user_settings, - $this->mock(Provide::class), - $this->mock(Clock::class) + $this->stub(Provide::class), + $this->stub(Clock::class) ); $this->assertTrue($instance->neverAgreed()); @@ -123,14 +123,14 @@ public function testNeverAgreed(): void public function testWithdrawalRequested(): void { - $setting = $this->mock(Setting::class); + $setting = $this->stub(Setting::class); $instance = new User( - $this->mock(ilObjUser::class), - $this->mock(Settings::class), + $this->stub(ilObjUser::class), + $this->stub(Settings::class), $this->mockMethod(UserSettings::class, 'withdrawalRequested', [], $setting), - $this->mock(Provide::class), - $this->mock(Clock::class) + $this->stub(Provide::class), + $this->stub(Clock::class) ); $this->assertSame($setting, $instance->withdrawalRequested()); @@ -138,14 +138,14 @@ public function testWithdrawalRequested(): void public function testAgreeDate(): void { - $setting = $this->mock(Setting::class); + $setting = $this->stub(Setting::class); $instance = new User( - $this->mock(ilObjUser::class), - $this->mock(Settings::class), + $this->stub(ilObjUser::class), + $this->stub(Settings::class), $this->mockMethod(UserSettings::class, 'agreeDate', [], $setting), - $this->mock(Provide::class), - $this->mock(Clock::class) + $this->stub(Provide::class), + $this->stub(Clock::class) ); $this->assertSame($setting, $instance->agreeDate()); @@ -153,18 +153,18 @@ public function testAgreeDate(): void public function testDidNotAcceptCurrentVersion(): void { - $user = $this->mock(ilObjUser::class); - $document = $this->mock(Document::class); + $user = $this->stub(ilObjUser::class); + $document = $this->stub(Document::class); $instance = new User( $user, - $this->mockTree(Settings::class, ['validateOnLogin' => ['value' => true]]), - $this->mock(UserSettings::class), - $this->mockTree(Provide::class, [ + $this->stubTree(Settings::class, ['validateOnLogin' => ['value' => true]]), + $this->stub(UserSettings::class), + $this->stubTree(Provide::class, [ 'document' => $this->mockMethod(ProvideDocument::class, 'chooseDocumentFor', [$user], new Ok($document)), 'history' => $this->mockMethod(ProvideHistory::class, 'alreadyAccepted', [$user, $document], false), ]), - $this->mock(Clock::class) + $this->stub(Clock::class) ); $this->assertTrue($instance->didNotAcceptCurrentVersion()); @@ -173,11 +173,11 @@ public function testDidNotAcceptCurrentVersion(): void public function testNeedsToAcceptNewDocumentWhereNeverAgreed(): void { $instance = new User( - $this->mock(ilObjUser::class), - $this->mock(Settings::class), - $this->mockTree(UserSettings::class, ['agreeDate' => ['value' => null]]), - $this->mock(Provide::class), - $this->mock(Clock::class) + $this->stub(ilObjUser::class), + $this->stub(Settings::class), + $this->stubTree(UserSettings::class, ['agreeDate' => ['value' => null]]), + $this->stub(Provide::class), + $this->stub(Clock::class) ); $this->assertTrue($instance->needsToAcceptNewDocument()); @@ -185,15 +185,15 @@ public function testNeedsToAcceptNewDocumentWhereNeverAgreed(): void public function testNeedsToAcceptNewDocumentReturnsTrue(): void { - $user = $this->mock(ilObjUser::class); + $user = $this->stub(ilObjUser::class); $history = $this->mockMethod(ProvideHistory::class, 'currentDocumentOfAcceptedVersion', [$user], new Error('Not found.')); $instance = new User( $user, - $this->mockTree(Settings::class, ['validateOnLogin' => ['value' => true]]), - $this->mockTree(UserSettings::class, ['agreeDate' => ['value' => new DateTimeImmutable()]]), - $this->mockTree(Provide::class, ['history' => $history]), - $this->mock(Clock::class) + $this->stubTree(Settings::class, ['validateOnLogin' => ['value' => true]]), + $this->stubTree(UserSettings::class, ['agreeDate' => ['value' => new DateTimeImmutable()]]), + $this->stubTree(Provide::class, ['history' => $history]), + $this->stub(Clock::class) ); $this->assertTrue($instance->needsToAcceptNewDocument()); @@ -201,19 +201,19 @@ public function testNeedsToAcceptNewDocumentReturnsTrue(): void public function testNeedsToAcceptNewDocumentReturnsFalse(): void { - $user = $this->mock(ilObjUser::class); - $document = $this->mock(Document::class); + $user = $this->stub(ilObjUser::class); + $document = $this->stub(Document::class); $history = $this->mockMethod(ProvideHistory::class, 'currentDocumentOfAcceptedVersion', [$user], new Ok($document)); $instance = new User( $user, - $this->mockTree(Settings::class, ['validateOnLogin' => ['value' => true]]), - $this->mockTree(UserSettings::class, ['agreeDate' => ['value' => new DateTimeImmutable()]]), - $this->mockTree(Provide::class, [ + $this->stubTree(Settings::class, ['validateOnLogin' => ['value' => true]]), + $this->stubTree(UserSettings::class, ['agreeDate' => ['value' => new DateTimeImmutable()]]), + $this->stubTree(Provide::class, [ 'document' => $this->mockMethod(ProvideDocument::class, 'documentMatches', [$document, $user], true), 'history' => $history, ]), - $this->mock(Clock::class) + $this->stub(Clock::class) ); $this->assertFalse($instance->needsToAcceptNewDocument()); @@ -221,17 +221,17 @@ public function testNeedsToAcceptNewDocumentReturnsFalse(): void public function testDoesntMatch(): void { - $document = $this->mock(Document::class); - $user = $this->mock(ilObjUser::class); + $document = $this->stub(Document::class); + $user = $this->stub(ilObjUser::class); $instance = new User( $user, - $this->mock(Settings::class), - $this->mock(UserSettings::class), - $this->mockTree(Provide::class, [ + $this->stub(Settings::class), + $this->stub(UserSettings::class), + $this->stubTree(Provide::class, [ 'document' => $this->mockMethod(ProvideDocument::class, 'documentMatches', [$document, $user], true), ]), - $this->mock(Clock::class) + $this->stub(Clock::class) ); $this->assertFalse($instance->doesntMatch($document)); @@ -239,17 +239,17 @@ public function testDoesntMatch(): void public function testMatchingDocument(): void { - $user = $this->mock(ilObjUser::class); - $result = $this->mock(Result::class); + $user = $this->stub(ilObjUser::class); + $result = $this->stub(Result::class); $instance = new User( $user, - $this->mock(Settings::class), - $this->mock(UserSettings::class), - $this->mockTree(Provide::class, [ + $this->stub(Settings::class), + $this->stub(UserSettings::class), + $this->stubTree(Provide::class, [ 'document' => $this->mockMethod(ProvideDocument::class, 'chooseDocumentFor', [$user], $result), ]), - $this->mock(Clock::class) + $this->stub(Clock::class) ); $this->assertSame($result, $instance->matchingDocument()); @@ -260,16 +260,16 @@ public function testAcceptedVersion(): void $this->ensureDefined('ANONYMOUS_USER_ID', 13); $this->ensureDefined('SYSTEM_USER_ID', 9); - $result = $this->mock(Result::class); + $result = $this->stub(Result::class); - $user = $this->mockTree(ilObjUser::class, ['getId' => 67]); + $user = $this->stubTree(ilObjUser::class, ['getId' => 67]); $instance = new User( $user, - $this->mock(Settings::class), - $this->mockTree(UserSettings::class, ['agreeDate' => ['value' => new DateTimeImmutable()]]), - $this->mockTree(Provide::class, ['history' => $this->mockMethod(ProvideHistory::class, 'acceptedVersion', [$user], $result)]), - $this->mock(Clock::class) + $this->stub(Settings::class), + $this->stubTree(UserSettings::class, ['agreeDate' => ['value' => new DateTimeImmutable()]]), + $this->stubTree(Provide::class, ['history' => $this->mockMethod(ProvideHistory::class, 'acceptedVersion', [$user], $result)]), + $this->stub(Clock::class) ); $this->assertSame($result, $instance->acceptedVersion()); @@ -280,14 +280,14 @@ public function testAcceptVersionError(): void $this->ensureDefined('ANONYMOUS_USER_ID', 13); $this->ensureDefined('SYSTEM_USER_ID', 9); - $user = $this->mockTree(ilObjUser::class, ['getId' => 67]); + $user = $this->stubTree(ilObjUser::class, ['getId' => 67]); $instance = new User( $user, - $this->mock(Settings::class), - $this->mockTree(UserSettings::class, ['agreeDate' => ['value' => null]]), - $this->mock(Provide::class), - $this->mock(Clock::class) + $this->stub(Settings::class), + $this->stubTree(UserSettings::class, ['agreeDate' => ['value' => null]]), + $this->stub(Provide::class), + $this->stub(Clock::class) ); $result = $instance->acceptedVersion(); @@ -297,8 +297,8 @@ public function testAcceptVersionError(): void public function testAcceptMatchingDocument(): void { - $user = $this->mock(ilObjUser::class); - $document = $this->mock(Document::class); + $user = $this->stub(ilObjUser::class); + $document = $this->stub(Document::class); $date = new DateTimeImmutable(); $history = $this->mock(ProvideHistory::class); @@ -309,13 +309,13 @@ public function testAcceptMatchingDocument(): void $instance = new User( $user, - $this->mock(Settings::class), - $this->mockTree(UserSettings::class, ['agreeDate' => $setting]), - $this->mockTree(Provide::class, [ + $this->stub(Settings::class), + $this->stubTree(UserSettings::class, ['agreeDate' => $setting]), + $this->stubTree(Provide::class, [ 'document' => $this->mockMethod(ProvideDocument::class, 'chooseDocumentFor', [$user], new Ok($document)), 'history' => $history, ]), - $this->mockTree(Clock::class, ['now' => $date]) + $this->stubTree(Clock::class, ['now' => $date]) ); $instance->acceptMatchingDocument(); @@ -324,11 +324,11 @@ public function testAcceptMatchingDocument(): void public function testIsLDAPUser(): void { $instance = new User( - $this->mockTree(ilObjUser::class, ['getAuthMode' => 'default']), - $this->mockTree(Settings::class, ['authMode' => ['value' => (string) ilAuthUtils::AUTH_LDAP]]), - $this->mock(UserSettings::class), - $this->mock(Provide::class), - $this->mock(Clock::class) + $this->stubTree(ilObjUser::class, ['getAuthMode' => 'default']), + $this->stubTree(Settings::class, ['authMode' => ['value' => (string) ilAuthUtils::AUTH_LDAP]]), + $this->stub(UserSettings::class), + $this->stub(Provide::class), + $this->stub(Clock::class) ); $this->assertTrue($instance->isLDAPUser()); @@ -338,11 +338,11 @@ public function testIsLDAPUser(): void public function testIsExternalUser(int $auth_mode, bool $is_external_account): void { $instance = new User( - $this->mockTree(ilObjUser::class, ['getAuthMode' => 'default']), - $this->mockTree(Settings::class, ['authMode' => ['value' => (string) $auth_mode]]), - $this->mock(UserSettings::class), - $this->mock(Provide::class), - $this->mock(Clock::class) + $this->stubTree(ilObjUser::class, ['getAuthMode' => 'default']), + $this->stubTree(Settings::class, ['authMode' => ['value' => (string) $auth_mode]]), + $this->stub(UserSettings::class), + $this->stub(Provide::class), + $this->stub(Clock::class) ); $this->assertSame($is_external_account, $instance->isExternalAccount()); @@ -351,15 +351,15 @@ public function testIsExternalUser(int $auth_mode, bool $is_external_account): v public function testFormat(): void { $instance = new User( - $this->mockTree(ilObjUser::class, [ + $this->stubTree(ilObjUser::class, [ 'getFullname' => 'foo', 'getLogin' => 'bar', 'getExternalAccount' => 'baz', ]), - $this->mock(Settings::class), - $this->mock(UserSettings::class), - $this->mock(Provide::class), - $this->mock(Clock::class) + $this->stub(Settings::class), + $this->stub(UserSettings::class), + $this->stub(Provide::class), + $this->stub(Clock::class) ); $this->assertSame('', $instance->format('')); @@ -368,14 +368,14 @@ public function testFormat(): void public function testRaw(): void { - $user = $this->mock(ilObjUser::class); + $user = $this->stub(ilObjUser::class); $instance = new User( $user, - $this->mock(Settings::class), - $this->mock(UserSettings::class), - $this->mock(Provide::class), - $this->mock(Clock::class) + $this->stub(Settings::class), + $this->stub(UserSettings::class), + $this->stub(Provide::class), + $this->stub(Clock::class) ); $this->assertSame($user, $instance->raw()); @@ -383,20 +383,20 @@ public function testRaw(): void public function testAcceptAnyDocument(): void { - $user = $this->mock(ilObjUser::class); + $user = $this->stub(ilObjUser::class); $history = $this->mock(ProvideHistory::class); - $doc = $this->mock(Document::class); + $doc = $this->stub(Document::class); $history->expects($this->once())->method('acceptDocument')->with($user, $doc); $instance = new User( $user, - $this->mock(Settings::class), - $this->mock(UserSettings::class), - $this->mockTree(Provide::class, [ + $this->stub(Settings::class), + $this->stub(UserSettings::class), + $this->stubTree(Provide::class, [ 'document' => ['repository' => ['all' => [$doc]]], 'history' => $history, ]), - $this->mock(Clock::class) + $this->stub(Clock::class) ); $instance->acceptAnyDocument(); diff --git a/components/ILIAS/LegalDocuments/tests/ContainerMock.php b/components/ILIAS/LegalDocuments/tests/ContainerMock.php index 05a7168d2ca9..a8c34f463960 100755 --- a/components/ILIAS/LegalDocuments/tests/ContainerMock.php +++ b/components/ILIAS/LegalDocuments/tests/ContainerMock.php @@ -20,15 +20,32 @@ namespace ILIAS\LegalDocuments\test; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\MockObject\Stub; use ReflectionClass; trait ContainerMock { + /** + * @template T of object + * @param class-string $class + * @return T&MockObject + */ private function mock(string $class) { return $this->getMockBuilder($class)->disableOriginalConstructor()->getMock(); } + /** + * @template T of object + * @param class-string $class + * @return T&Stub + */ + private function stub(string $class) + { + return $this->createStub($class); + } + private function mockMethod(string $class, string $method, array $args, $return, $times = null) { $times ??= $this->once(); @@ -51,23 +68,49 @@ private function assertGetter($class_or_instance, array $methods_and_values): vo } /** + * @template T of object + * @param class-string $class * @param array $tree + * @return T&MockObject */ private function mockTree(string $class, array $tree) { - $r = new ReflectionClass($class); - $mock = $this->mock($class); + $double = $this->mock($class); + $this->configureTree($double, $class, $tree); + + return $double; + } + + /** + * @template T of object + * @param class-string $class + * @param array $tree + * @return T&Stub + */ + private function stubTree(string $class, array $tree) + { + $double = $this->stub($class); + $this->configureTree($double, $class, $tree); + + return $double; + } + + /** + * @param class-string $class + * @param array $tree + */ + private function configureTree(Stub $double, string $class, array $tree): void + { + $reflection = new ReflectionClass($class); foreach ($tree as $name => $value) { - $type = (string) $r->getMethod($name)->getReturnType(); + $type = (string) $reflection->getMethod($name)->getReturnType(); $type = $type === 'self' ? $class : $type; $type = preg_replace('/^\?/', '', $type); - $mock->method($name)->willReturn( + $double->method($name)->willReturn( class_exists($type) || interface_exists($type) ? - (is_array($value) ? $this->mockTree($type, $value) : $value) : + (is_array($value) ? $this->stubTree($type, $value) : $value) : $value ); } - - return $mock; } } diff --git a/components/ILIAS/LegalDocuments/tests/DefaultMappingsTest.php b/components/ILIAS/LegalDocuments/tests/DefaultMappingsTest.php index 46e7e184146b..ad75fb89924b 100755 --- a/components/ILIAS/LegalDocuments/tests/DefaultMappingsTest.php +++ b/components/ILIAS/LegalDocuments/tests/DefaultMappingsTest.php @@ -44,20 +44,20 @@ class DefaultMappingsTest extends TestCase public function testConstruct(): void { - $this->assertInstanceOf(DefaultMappings::class, new DefaultMappings('foo', $this->mock(Container::class))); + $this->assertInstanceOf(DefaultMappings::class, new DefaultMappings('foo', $this->stub(Container::class))); } public function testConditionDefinitions(): void { $container = $this->mockTree(Container::class, [ 'ui' => [ - 'factory' => $this->mock(UI::class), - 'mainTemplate' => $this->mock(ilGlobalTemplateInterface::class), + 'factory' => $this->stub(UI::class), + 'mainTemplate' => $this->stub(ilGlobalTemplateInterface::class), ], 'language' => $this->mockMethod(ilLanguage::class, 'getInstalledLanguages', [], []), - 'rbac' => $this->mockMethod(RBACServices::class, 'review', [], $this->mock(ilRbacReview::class)), + 'rbac' => $this->mockMethod(RBACServices::class, 'review', [], $this->stub(ilRbacReview::class)), ]); - $container->expects($this->once())->method('offsetGet')->with('ilObjDataCache')->willReturn($this->mock(ilObjectDataCache::class)); + $container->expects($this->once())->method('offsetGet')->with('ilObjDataCache')->willReturn($this->stub(ilObjectDataCache::class)); $instance = new DefaultMappings('foo', $container); $result = $instance->conditionDefinitions(); @@ -71,20 +71,20 @@ public function testConditionDefinitions(): void public function testContentAsComponent(): void { - $legacy = $this->mock(Legacy\Content::class); + $legacy = $this->stub(Legacy\Content::class); $legacy_factory = $this->mock(Legacy\Factory::class); $legacy_factory ->expects($this->once()) ->method('content') ->willReturn($legacy); - $container = $this->mockTree(Container::class, [ + $container = $this->stubTree(Container::class, [ 'ui' => ['factory' => $this->mockMethod(UIFactory::class, 'legacy', [], $legacy_factory)], ]); $instance = new DefaultMappings('foo', $container); $map = $instance->contentAsComponent(); $this->assertSame(['html'], array_keys($map)); - $this->assertSame($legacy, $map['html']($this->mockTree(DocumentContent::class, ['value' => 'bar']))); + $this->assertSame($legacy, $map['html']($this->stubTree(DocumentContent::class, ['value' => 'bar']))); } } diff --git a/components/ILIAS/LegalDocuments/tests/DocumentId/NumberIdTest.php b/components/ILIAS/LegalDocuments/tests/DocumentId/NumberIdTest.php index f38ff37b8fe3..3149721d2d79 100755 --- a/components/ILIAS/LegalDocuments/tests/DocumentId/NumberIdTest.php +++ b/components/ILIAS/LegalDocuments/tests/DocumentId/NumberIdTest.php @@ -33,7 +33,7 @@ class NumberIdTest extends TestCase public function testConstruct(): void { - $this->assertInstanceOf(NumberId::class, new NumberId($this->mock(Document::class))); + $this->assertInstanceOf(NumberId::class, new NumberId($this->stub(Document::class))); } public function testNumber(): void diff --git a/components/ILIAS/LegalDocuments/tests/FileUpload/UploadHandlerTest.php b/components/ILIAS/LegalDocuments/tests/FileUpload/UploadHandlerTest.php index 0b9ed0cfc981..fc9e193879f9 100755 --- a/components/ILIAS/LegalDocuments/tests/FileUpload/UploadHandlerTest.php +++ b/components/ILIAS/LegalDocuments/tests/FileUpload/UploadHandlerTest.php @@ -65,7 +65,7 @@ public function testLinks(): void public function testInfoResultWithResult(): void { $value = 'Lorem ipsum'; - $document_content = $this->mockTree(DocumentContent::class, [ + $document_content = $this->stubTree(DocumentContent::class, [ 'value' => $value, 'type' => 'html', ]); diff --git a/components/ILIAS/LegalDocuments/tests/GotoLink/ConditionalGotoLinkTest.php b/components/ILIAS/LegalDocuments/tests/GotoLink/ConditionalGotoLinkTest.php index 9c5022fc4736..dea737e88b07 100755 --- a/components/ILIAS/LegalDocuments/tests/GotoLink/ConditionalGotoLinkTest.php +++ b/components/ILIAS/LegalDocuments/tests/GotoLink/ConditionalGotoLinkTest.php @@ -51,7 +51,7 @@ public function testName(): void public function testTarget(): void { - $target = $this->mock(Target::class); + $target = $this->stub(Target::class); $instance = new ConditionalGotoLink( 'foo', diff --git a/components/ILIAS/LegalDocuments/tests/Intercept/ConditionalInterceptTest.php b/components/ILIAS/LegalDocuments/tests/Intercept/ConditionalInterceptTest.php index 53de745f25e5..9cba137a8c8c 100755 --- a/components/ILIAS/LegalDocuments/tests/Intercept/ConditionalInterceptTest.php +++ b/components/ILIAS/LegalDocuments/tests/Intercept/ConditionalInterceptTest.php @@ -36,7 +36,7 @@ public function testConstruct(): void $this->assertInstanceOf(ConditionalIntercept::class, new ConditionalIntercept( $this->fail(...), 'foo', - $this->mock(Target::class) + $this->stub(Target::class) )); } @@ -45,7 +45,7 @@ public function testIntercept(): void $instance = new ConditionalIntercept( fn() => true, 'foo', - $this->mock(Target::class) + $this->stub(Target::class) ); $this->assertTrue($instance->intercept()); @@ -56,7 +56,7 @@ public function testId(): void $instance = new ConditionalIntercept( $this->fail(...), 'foo', - $this->mock(Target::class) + $this->stub(Target::class) ); $this->assertSame('foo', $instance->id()); @@ -64,7 +64,7 @@ public function testId(): void public function testTarget(): void { - $target = $this->mock(Target::class); + $target = $this->stub(Target::class); $instance = new ConditionalIntercept( $this->fail(...), 'foo', diff --git a/components/ILIAS/LegalDocuments/tests/Intercept/LazyInterceptTest.php b/components/ILIAS/LegalDocuments/tests/Intercept/LazyInterceptTest.php index 525447185a38..a840e875a136 100755 --- a/components/ILIAS/LegalDocuments/tests/Intercept/LazyInterceptTest.php +++ b/components/ILIAS/LegalDocuments/tests/Intercept/LazyInterceptTest.php @@ -39,7 +39,7 @@ public function testConstruct(): void public function testIntercept(): void { - $intercept = $this->mockTree(Intercept::class, ['intercept' => true]); + $intercept = $this->stubTree(Intercept::class, ['intercept' => true]); $instance = new LazyIntercept(fn() => $intercept); $this->assertTrue($intercept->intercept()); @@ -48,7 +48,7 @@ public function testIntercept(): void public function testId(): void { - $intercept = $this->mockTree(Intercept::class, ['id' => 'foo']); + $intercept = $this->stubTree(Intercept::class, ['id' => 'foo']); $instance = new LazyIntercept(fn() => $intercept); $this->assertSame('foo', $intercept->id()); @@ -56,8 +56,8 @@ public function testId(): void public function testTarget(): void { - $target = $this->mock(Target::class); - $intercept = $this->mockTree(Intercept::class, ['target' => $target]); + $target = $this->stub(Target::class); + $intercept = $this->stubTree(Intercept::class, ['target' => $target]); $instance = new LazyIntercept(fn() => $intercept); $this->assertSame($target, $intercept->target()); diff --git a/components/ILIAS/LegalDocuments/tests/LazyProvideTest.php b/components/ILIAS/LegalDocuments/tests/LazyProvideTest.php index a182d7c02b2f..611339499108 100755 --- a/components/ILIAS/LegalDocuments/tests/LazyProvideTest.php +++ b/components/ILIAS/LegalDocuments/tests/LazyProvideTest.php @@ -40,7 +40,7 @@ public function testConstruct(): void public function testMethods(string $method, $return = []): void { $called = false; - $provide = $this->mockTree(Provide::class, [$method => $return]); + $provide = $this->stubTree(Provide::class, [$method => $return]); $create = function () use (&$called, $provide) { $called = true; diff --git a/components/ILIAS/LegalDocuments/tests/Legacy/ConfirmationTest.php b/components/ILIAS/LegalDocuments/tests/Legacy/ConfirmationTest.php index 1df157b4f168..1eea8fec05eb 100755 --- a/components/ILIAS/LegalDocuments/tests/Legacy/ConfirmationTest.php +++ b/components/ILIAS/LegalDocuments/tests/Legacy/ConfirmationTest.php @@ -33,7 +33,7 @@ class ConfirmationTest extends TestCase public function testConstruct(): void { - $this->assertInstanceOf(Confirmation::class, new Confirmation($this->mock(ilLanguage::class), $this->fail(...))); + $this->assertInstanceOf(Confirmation::class, new Confirmation($this->stub(ilLanguage::class), $this->fail(...))); } public function testRender(): void diff --git a/components/ILIAS/LegalDocuments/tests/PageFragment/PageContentTest.php b/components/ILIAS/LegalDocuments/tests/PageFragment/PageContentTest.php index d6b48d253028..1cbf05cf8a0d 100755 --- a/components/ILIAS/LegalDocuments/tests/PageFragment/PageContentTest.php +++ b/components/ILIAS/LegalDocuments/tests/PageFragment/PageContentTest.php @@ -43,7 +43,7 @@ public function testRender(): void { $template = $this->mock(ilGlobalTemplateInterface::class); $template->expects($this->once())->method('setTitle')->with('foo'); - $components = [$this->mock(Component::class), $this->mock(Component::class)]; + $components = [$this->stub(Component::class), $this->stub(Component::class)]; $renderer = $this->mockMethod(Renderer::class, 'render', [$components], 'rendered'); $instance = new PageContent('foo', $components); diff --git a/components/ILIAS/LegalDocuments/tests/PageFragment/ShowOnScreenMessageTest.php b/components/ILIAS/LegalDocuments/tests/PageFragment/ShowOnScreenMessageTest.php index 417b507e6d13..7c09941420de 100755 --- a/components/ILIAS/LegalDocuments/tests/PageFragment/ShowOnScreenMessageTest.php +++ b/components/ILIAS/LegalDocuments/tests/PageFragment/ShowOnScreenMessageTest.php @@ -35,14 +35,14 @@ class ShowOnScreenMessageTest extends TestCase public function testConstruct(): void { - $this->assertInstanceOf(ShowOnScreenMessage::class, new ShowOnScreenMessage($this->mock(PageFragment::class), 'foo', 'bar', false)); + $this->assertInstanceOf(ShowOnScreenMessage::class, new ShowOnScreenMessage($this->stub(PageFragment::class), 'foo', 'bar', false)); } public function testRender(): void { $template = $this->mock(ilGlobalTemplateInterface::class); $template->expects($this->once())->method('setOnScreenMessage')->with('foo', 'bar', true); - $renderer = $this->mock(Renderer::class); + $renderer = $this->stub(Renderer::class); $page = $this->mockMethod(PageFragment::class, 'render', [$template, $renderer], 'rendered'); $instance = new ShowOnScreenMessage($page, 'foo', 'bar', true); diff --git a/components/ILIAS/LegalDocuments/tests/Provide/ProvideDocumentTest.php b/components/ILIAS/LegalDocuments/tests/Provide/ProvideDocumentTest.php index 7c387560eee0..26e0a9f04446 100755 --- a/components/ILIAS/LegalDocuments/tests/Provide/ProvideDocumentTest.php +++ b/components/ILIAS/LegalDocuments/tests/Provide/ProvideDocumentTest.php @@ -20,8 +20,6 @@ namespace ILIAS\LegalDocuments\test\Provide; -use ilCtrl; -use ILIAS\HTTP\Services; use ILIAS\UI\Component\Component; use ILIAS\LegalDocuments\Value\DocumentContent; use ILIAS\UI\Component\Input\Field\Group; @@ -31,23 +29,13 @@ use ILIAS\LegalDocuments\Value\Criterion; use ILIAS\LegalDocuments\Value\Document; use ILIAS\LegalDocuments\EditLinks; -use ILIAS\UI\Component\Legacy\Legacy; -use ILIAS\LegalDocuments\Legacy\Table as LegacyTable; -use ILIAS\LegalDocuments\Table as TableInterface; use ILIAS\LegalDocuments\Table\DocumentTable; -use ILIAS\UI\Component\Table\Action\Factory; -use ILIAS\UI\Factory as UIFactory; use ILIAS\LegalDocuments\test\ContainerMock; use ILIAS\DI\Container; use ILIAS\LegalDocuments\Repository\DocumentRepository; -use ILIAS\UI\Implementation\Component\Table\Action\Multi; use PHPUnit\Framework\TestCase; use ILIAS\LegalDocuments\Provide\ProvideDocument; use ILIAS\LegalDocuments\SelectionMap; -use ilGlobalTemplateInterface; -use ilLanguage; -use Psr\Http\Message\ServerRequestInterface; -use Psr\Http\Message\UriInterface; use stdClass; use ilObjUser; @@ -61,10 +49,10 @@ public function testConstruct(): void { $this->assertInstanceOf(ProvideDocument::class, new ProvideDocument( 'foo', - $this->mock(DocumentRepository::class), + $this->stub(DocumentRepository::class), new SelectionMap(), [], - $this->mockTree(Container::class, ['user' => ['getTimeZone' => 'europe/berlin']]) + $this->stubTree(Container::class, ['user' => ['getTimeZone' => 'europe/berlin']]) )); } @@ -74,7 +62,7 @@ public function testTableReadOnly(): void $uri = 'http://myIlias/ilias.php?baseClass=iladministrationgui&cmdNode=2g.qo.gq&cmdClass=ilLegalDocumentsAdministrationGUI&cmd=documents&ref_id=50'; - $container = $this->mockTree(Container::class, [ + $container = $this->stubTree(Container::class, [ 'ui' => [ 'factory' => [], 'mainTemplate' => [], @@ -85,7 +73,7 @@ public function testTableReadOnly(): void 'user' => ['getTimeZone' => 'europe/berlin'], ]); - $instance = new ProvideDocument('foo', $this->mock(DocumentRepository::class), new SelectionMap(), [], $container); + $instance = new ProvideDocument('foo', $this->stub(DocumentRepository::class), new SelectionMap(), [], $container); $this->assertInstanceOf(DocumentTable::class, $instance->table($dummy_gui)); } @@ -99,7 +87,7 @@ public function testTableEditable(): void $uri = 'http://myIlias/ilias.php?baseClass=iladministrationgui&cmdNode=2g.qo.gq&cmdClass=ilLegalDocumentsAdministrationGUI&cmd=documents&ref_id=50'; - $container = $this->mockTree(Container::class, [ + $container = $this->stubTree(Container::class, [ 'ui' => [ 'factory' => ['table' => ['action' => ['multi' => []]]], 'mainTemplate' => [], @@ -110,16 +98,16 @@ public function testTableEditable(): void 'user' => ['getTimeZone' => 'europe/berlin'], ]); - $instance = new ProvideDocument('foo', $this->mock(DocumentRepository::class), new SelectionMap(), [], $container); - $this->assertInstanceOf(DocumentTable::class, $instance->table($dummy_gui, $this->mock(EditLinks::class))); + $instance = new ProvideDocument('foo', $this->stub(DocumentRepository::class), new SelectionMap(), [], $container); + $this->assertInstanceOf(DocumentTable::class, $instance->table($dummy_gui, $this->stub(EditLinks::class))); } public function testChooseDocumentFor(): void { $document = $this->mockMethod(Document::class, 'criteria', [], []); - $user = $this->mock(ilObjUser::class); + $user = $this->stub(ilObjUser::class); - $criterion = $this->mockTree(Criterion::class, ['content' => ['type' => 'bar']]); + $criterion = $this->stubTree(Criterion::class, ['content' => ['type' => 'bar']]); $repository = $this->mockMethod(DocumentRepository::class, 'all', [], [ $this->mockMethod(Document::class, 'criteria', [], [$criterion]), @@ -133,7 +121,7 @@ public function testChooseDocumentFor(): void [$user], false )), - ]), [], $this->mock(Container::class)); + ]), [], $this->stub(Container::class)); $result = $instance->chooseDocumentFor($user); $this->assertTrue($result->isOk()); $this->assertSame($document, $result->value()); @@ -141,32 +129,32 @@ public function testChooseDocumentFor(): void public function testDocumentMatches(): void { - $criterion = $this->mockTree(Criterion::class, ['content' => ['type' => 'bar']]); + $criterion = $this->stubTree(Criterion::class, ['content' => ['type' => 'bar']]); $document = $this->mockMethod(Document::class, 'criteria', [], [$criterion]); - $user = $this->mock(ilObjUser::class); + $user = $this->stub(ilObjUser::class); - $instance = new ProvideDocument('doo', $this->mock(DocumentRepository::class), new SelectionMap([ + $instance = new ProvideDocument('doo', $this->stub(DocumentRepository::class), new SelectionMap([ 'bar' => $this->mockMethod(ConditionDefinition::class, 'withCriterion', [$criterion->content()], $this->mockMethod( Condition::class, 'eval', [$user], true )), - ]), [], $this->mock(Container::class)); + ]), [], $this->stub(Container::class)); $this->assertTrue($instance->documentMatches($document, $user)); } public function testRepository(): void { - $repository = $this->mock(DocumentRepository::class); - $instance = new ProvideDocument('foo', $repository, new SelectionMap(), [], $this->mock(Container::class)); + $repository = $this->stub(DocumentRepository::class); + $instance = new ProvideDocument('foo', $repository, new SelectionMap(), [], $this->stub(Container::class)); $this->assertSame($repository, $instance->repository()); } public function testHash(): void { - $instance = new ProvideDocument('foo', $this->mock(DocumentRepository::class), new SelectionMap(), [], $this->mock(Container::class)); + $instance = new ProvideDocument('foo', $this->stub(DocumentRepository::class), new SelectionMap(), [], $this->stub(Container::class)); $hash = $instance->hash(); $this->assertTrue(is_string($hash)); $this->assertSame(254, strlen($hash)); @@ -174,40 +162,40 @@ public function testHash(): void public function testToCondition(): void { - $condition = $this->mock(Condition::class); + $condition = $this->stub(Condition::class); $content = $this->mockMethod(CriterionContent::class, 'type', [], 'bar'); - $instance = new ProvideDocument('foo', $this->mock(DocumentRepository::class), new SelectionMap([ + $instance = new ProvideDocument('foo', $this->stub(DocumentRepository::class), new SelectionMap([ 'bar' => $this->mockMethod(ConditionDefinition::class, 'withCriterion', [$content], $condition), - ]), [], $this->mock(Container::class)); + ]), [], $this->stub(Container::class)); $this->assertSame($condition, $instance->toCondition($content)); } public function testConditionGroupsWithoutContent(): void { - $group = $this->mock(Group::class); + $group = $this->stub(Group::class); - $instance = new ProvideDocument('foo', $this->mock(DocumentRepository::class), new SelectionMap([ + $instance = new ProvideDocument('foo', $this->stub(DocumentRepository::class), new SelectionMap([ 'bar' => $this->mockMethod(ConditionDefinition::class, 'formGroup', [[]], $group), 'baz' => $this->mockMethod(ConditionDefinition::class, 'formGroup', [[]], $group), - ]), [], $this->mock(Container::class)); + ]), [], $this->stub(Container::class)); $this->assertSame(['bar' => $group, 'baz' => $group], $instance->conditionGroups()->choices()); } public function testConditionGroups(): void { - $group = $this->mock(Group::class); - $content = $this->mockTree(CriterionContent::class, [ + $group = $this->stub(Group::class); + $content = $this->stubTree(CriterionContent::class, [ 'type' => 'baz', 'arguments' => ['a', 'b', 'c'], ]); - $instance = new ProvideDocument('foo', $this->mock(DocumentRepository::class), new SelectionMap([ + $instance = new ProvideDocument('foo', $this->stub(DocumentRepository::class), new SelectionMap([ 'bar' => $this->mockMethod(ConditionDefinition::class, 'formGroup', [[]], $group), 'baz' => $this->mockMethod(ConditionDefinition::class, 'formGroup', [$content->arguments()], $group), - ]), [], $this->mock(Container::class)); + ]), [], $this->stub(Container::class)); $this->assertSame(['bar' => $group, 'baz' => $group], $instance->conditionGroups($content)->choices()); } @@ -230,14 +218,14 @@ public function testValidateCriteriaContent(): void }) )->willReturn($condition); - $instance = new ProvideDocument('foo', $this->mock(DocumentRepository::class), new SelectionMap([ + $instance = new ProvideDocument('foo', $this->stub(DocumentRepository::class), new SelectionMap([ 'hoo' => $this->mockMethod(ConditionDefinition::class, 'withCriterion', [$existing_content], $condition), 'foo' => $definition, - ]), [], $this->mock(Container::class)); + ]), [], $this->stub(Container::class)); $result = $instance->validateCriteriaContent([ - $this->mockTree(Criterion::class, ['content' => $existing_content]), - $this->mockTree(Criterion::class, ['content' => $other_existing_content]), + $this->stubTree(Criterion::class, ['content' => $existing_content]), + $this->stubTree(Criterion::class, ['content' => $other_existing_content]), ], $content); $this->assertTrue($result->isOk()); $this->assertSame($content, $result->value()); @@ -247,9 +235,9 @@ public function testDuplicateCriteriaContent(): void { $content = new CriterionContent('foo', ['bar']); - $instance = new ProvideDocument('foo', $this->mock(DocumentRepository::class), new SelectionMap(), [], $this->mock(Container::class)); + $instance = new ProvideDocument('foo', $this->stub(DocumentRepository::class), new SelectionMap(), [], $this->stub(Container::class)); $result = $instance->validateCriteriaContent([ - $this->mockTree(Criterion::class, ['content' => new CriterionContent('foo', ['bar'])]) + $this->stubTree(Criterion::class, ['content' => new CriterionContent('foo', ['bar'])]) ], $content); $this->assertFalse($result->isOk()); $this->assertSame(ProvideDocument::CRITERION_ALREADY_EXISTS, $result->error()); @@ -263,13 +251,13 @@ public function testNeverMatchingCriteriaContent(): void $condition = $this->mock(Condition::class); $condition->expects($this->once())->method('knownToNeverMatchWith')->with($condition)->willReturn(true); - $instance = new ProvideDocument('foo', $this->mock(DocumentRepository::class), new SelectionMap([ + $instance = new ProvideDocument('foo', $this->stub(DocumentRepository::class), new SelectionMap([ 'hoo' => $this->mockMethod(ConditionDefinition::class, 'withCriterion', [$existing_content], $condition), 'foo' => $this->mockMethod(ConditionDefinition::class, 'withCriterion', [$content], $condition), - ]), [], $this->mock(Container::class)); + ]), [], $this->stub(Container::class)); $result = $instance->validateCriteriaContent([ - $this->mockTree(Criterion::class, ['content' => $existing_content]), + $this->stubTree(Criterion::class, ['content' => $existing_content]), ], $content); $this->assertFalse($result->isOk()); $this->assertSame(ProvideDocument::CRITERION_WOULD_NEVER_MATCH, $result->error()); @@ -277,15 +265,15 @@ public function testNeverMatchingCriteriaContent(): void public function testContentAsComponent(): void { - $content = $this->mockTree(DocumentContent::class, ['type' => 'html']); - $component = $this->mock(Component::class); + $content = $this->stubTree(DocumentContent::class, ['type' => 'html']); + $component = $this->stub(Component::class); - $instance = new ProvideDocument('foo', $this->mock(DocumentRepository::class), new SelectionMap(), [ + $instance = new ProvideDocument('foo', $this->stub(DocumentRepository::class), new SelectionMap(), [ 'html' => function (DocumentContent $c) use ($content, $component): Component { $this->assertSame($content, $c); return $component; } - ], $this->mock(Container::class)); + ], $this->stub(Container::class)); $this->assertSame($component, $instance->contentAsComponent($content)); } diff --git a/components/ILIAS/LegalDocuments/tests/Provide/ProvideHistoryTest.php b/components/ILIAS/LegalDocuments/tests/Provide/ProvideHistoryTest.php index b9722eda4c77..939fa059ae3d 100755 --- a/components/ILIAS/LegalDocuments/tests/Provide/ProvideHistoryTest.php +++ b/components/ILIAS/LegalDocuments/tests/Provide/ProvideHistoryTest.php @@ -47,13 +47,13 @@ class ProvideHistoryTest extends TestCase public function testConstruct(): void { - $this->assertInstanceOf(ProvideHistory::class, new ProvideHistory('foo', $this->mock(HistoryRepository::class), $this->mock(ProvideDocument::class), $this->mock(Container::class))); + $this->assertInstanceOf(ProvideHistory::class, new ProvideHistory('foo', $this->stub(HistoryRepository::class), $this->stub(ProvideDocument::class), $this->stub(Container::class))); } public function testTable(): void { $dummy_gui = new stdClass(); - $legacy = $this->mock(Legacy\Content::class); + $legacy = $this->stub(Legacy\Content::class); $legacy_factory = $this->mock(Legacy\Factory::class); $legacy_factory ->expects($this->once()) @@ -62,12 +62,12 @@ public function testTable(): void $table = $this->mockMethod(LegacyTable::class, 'getHTML', [], 'table html'); - $container = $this->mockTree(Container::class, [ - 'ctrl' => $this->mock(ilCtrl::class), - 'language' => $this->mock(ilLanguage::class), + $container = $this->stubTree(Container::class, [ + 'ctrl' => $this->stub(ilCtrl::class), + 'language' => $this->stub(ilLanguage::class), 'ui' => [ 'factory' => $this->mockMethod(UIFactory::class, 'legacy', [], $legacy_factory), - 'mainTemplate' => $this->mock(ilGlobalTemplateInterface::class) + 'mainTemplate' => $this->stub(ilGlobalTemplateInterface::class) ], ]); @@ -78,52 +78,52 @@ public function testTable(): void return $table; }; - $instance = new ProvideHistory('foo', $this->mock(HistoryRepository::class), $this->mock(ProvideDocument::class), $container, $create_table_gui); + $instance = new ProvideHistory('foo', $this->stub(HistoryRepository::class), $this->stub(ProvideDocument::class), $container, $create_table_gui); $this->assertSame($legacy, $instance->table($dummy_gui, 'dummy command', 'reset command', 'auto complete command')); } public function testAcceptDocument(): void { - $user = $this->mock(ilObjUser::class); - $document = $this->mock(Document::class); + $user = $this->stub(ilObjUser::class); + $document = $this->stub(Document::class); $repository = $this->mock(HistoryRepository::class); $repository->expects($this->once())->method('acceptDocument')->with($user, $document); - $instance = new ProvideHistory('foo', $repository, $this->mock(ProvideDocument::class), $this->mock(Container::class)); + $instance = new ProvideHistory('foo', $repository, $this->stub(ProvideDocument::class), $this->stub(Container::class)); $instance->acceptDocument($user, $document); } public function testAlreadyAccepted(): void { - $user = $this->mock(ilObjUser::class); - $document = $this->mock(Document::class); + $user = $this->stub(ilObjUser::class); + $document = $this->stub(Document::class); $repository = $this->mockMethod(HistoryRepository::class, 'alreadyAccepted', [$user, $document], true); - $instance = new ProvideHistory('foo', $repository, $this->mock(ProvideDocument::class), $this->mock(Container::class)); + $instance = new ProvideHistory('foo', $repository, $this->stub(ProvideDocument::class), $this->stub(Container::class)); $this->assertTrue($instance->alreadyAccepted($user, $document)); } public function testAcceptedVersion(): void { - $user = $this->mock(ilObjUser::class); + $user = $this->stub(ilObjUser::class); - $result = $this->mock(Result::class); + $result = $this->stub(Result::class); $repository = $this->mockMethod(HistoryRepository::class, 'acceptedVersion', [$user], $result); - $instance = new ProvideHistory('foo', $repository, $this->mock(ProvideDocument::class), $this->mock(Container::class)); + $instance = new ProvideHistory('foo', $repository, $this->stub(ProvideDocument::class), $this->stub(Container::class)); $this->assertSame($result, $instance->acceptedVersion($user)); } public function testCurrentDocumentOfAcceptedVersion(): void { - $user = $this->mock(ilObjUser::class); - $result = $this->mock(Result::class); + $user = $this->stub(ilObjUser::class); + $result = $this->stub(Result::class); $repository = $this->mockMethod(HistoryRepository::class, 'currentDocumentOfAcceptedVersion', [$user], $result); - $instance = new ProvideHistory('foo', $repository, $this->mock(ProvideDocument::class), $this->mock(Container::class)); + $instance = new ProvideHistory('foo', $repository, $this->stub(ProvideDocument::class), $this->stub(Container::class)); $this->assertSame($result, $instance->currentDocumentOfAcceptedVersion($user)); } diff --git a/components/ILIAS/LegalDocuments/tests/Provide/ProvidePublicPageTest.php b/components/ILIAS/LegalDocuments/tests/Provide/ProvidePublicPageTest.php index daf6f88b2ea9..43a0a0fdc5f4 100755 --- a/components/ILIAS/LegalDocuments/tests/Provide/ProvidePublicPageTest.php +++ b/components/ILIAS/LegalDocuments/tests/Provide/ProvidePublicPageTest.php @@ -34,7 +34,7 @@ class ProvidePublicPageTest extends TestCase public function testConstruct(): void { - $this->assertInstanceOf(ProvidePublicPage::class, new ProvidePublicPage('foo', $this->mock(ilCtrl::class))); + $this->assertInstanceOf(ProvidePublicPage::class, new ProvidePublicPage('foo', $this->stub(ilCtrl::class))); } public function testUrl(): void diff --git a/components/ILIAS/LegalDocuments/tests/Provide/ProvideWithdrawalTest.php b/components/ILIAS/LegalDocuments/tests/Provide/ProvideWithdrawalTest.php index 27e21b3e81ac..c3c01d42347c 100755 --- a/components/ILIAS/LegalDocuments/tests/Provide/ProvideWithdrawalTest.php +++ b/components/ILIAS/LegalDocuments/tests/Provide/ProvideWithdrawalTest.php @@ -37,8 +37,8 @@ public function testConstruct(): void { $this->assertInstanceOf(ProvideWithdrawal::class, new ProvideWithdrawal( 'foo', - $this->mock(ilCtrl::class), - $this->mock(ilAuthSession::class) + $this->stub(ilCtrl::class), + $this->stub(ilAuthSession::class) )); } @@ -46,8 +46,8 @@ public function testBeginProcessURL(): void { $instance = new ProvideWithdrawal( 'foo', - $this->mock(ilCtrl::class), - $this->mock(ilAuthSession::class), + $this->stub(ilCtrl::class), + $this->stub(ilAuthSession::class), function (array $params): string { $this->assertSame(['withdraw_consent' => 'foo'], $params); return 'logout url'; diff --git a/components/ILIAS/LegalDocuments/tests/ProvideTest.php b/components/ILIAS/LegalDocuments/tests/ProvideTest.php index 6431a8bf7a42..b5dd69dc1dd6 100755 --- a/components/ILIAS/LegalDocuments/tests/ProvideTest.php +++ b/components/ILIAS/LegalDocuments/tests/ProvideTest.php @@ -40,13 +40,13 @@ class ProvideTest extends TestCase public function testConstruct(): void { - $this->assertInstanceOf(Provide::class, new Provide('foo', $this->mock(Internal::class), $this->mock(Container::class))); + $this->assertInstanceOf(Provide::class, new Provide('foo', $this->stub(Internal::class), $this->stub(Container::class))); } public function testWithdrawal(): void { - $container = $this->mockTree(Container::class, ['ctrl' => $this->mock(ilCtrl::class)]); - $container->expects($this->once())->method('offsetGet')->with('ilAuthSession')->willReturn($this->mock(ilAuthSession::class)); + $container = $this->mockTree(Container::class, ['ctrl' => $this->stub(ilCtrl::class)]); + $container->expects($this->once())->method('offsetGet')->with('ilAuthSession')->willReturn($this->stub(ilAuthSession::class)); $instance = new Provide('foo', $this->mockMethod(Internal::class, 'get', ['withdraw'], 'foo'), $container); @@ -55,7 +55,7 @@ public function testWithdrawal(): void public function testPublicPage(): void { - $container = $this->mockTree(Container::class, ['ctrl' => $this->mock(ilCtrl::class)]); + $container = $this->stubTree(Container::class, ['ctrl' => $this->stub(ilCtrl::class)]); $this->assertInstanceOf(ProvidePublicPage::class, (new Provide('foo', $this->mockMethod( Internal::class, @@ -67,25 +67,25 @@ public function testPublicPage(): void public function testDocument(): void { - $document = $this->mock(ProvideDocument::class); + $document = $this->stub(ProvideDocument::class); $internal = $this->mockMethod(Internal::class, 'get', ['document', 'foo'], $document); - $instance = new Provide('foo', $internal, $this->mock(Container::class)); + $instance = new Provide('foo', $internal, $this->stub(Container::class)); $this->assertSame($document, $instance->document()); } public function testHistory(): void { - $history = $this->mock(ProvideHistory::class); + $history = $this->stub(ProvideHistory::class); $internal = $this->mockMethod(Internal::class, 'get', ['history', 'foo'], $history); - $instance = new Provide('foo', $internal, $this->mock(Container::class)); + $instance = new Provide('foo', $internal, $this->stub(Container::class)); $this->assertSame($history, $instance->history()); } public function testAllowEditing(): void { - $document = $this->mock(ProvideDocument::class); + $document = $this->stub(ProvideDocument::class); $internal = $this->mock(Internal::class); $consecutive = [ @@ -104,23 +104,23 @@ function ($a, $b) use (&$consecutive, $document) { } ); - $instance = new Provide('foo', $internal, $this->mock(Container::class)); + $instance = new Provide('foo', $internal, $this->stub(Container::class)); $instance->document(); $instance->allowEditing()->document(); } public function testPublicApi(): void { - $public_api = $this->mock(PublicApi::class); + $public_api = $this->stub(PublicApi::class); $internal = $this->mockMethod(Internal::class, 'get', ['public-api', 'foo'], $public_api); - $instance = new Provide('foo', $internal, $this->mock(Container::class)); + $instance = new Provide('foo', $internal, $this->stub(Container::class)); $this->assertSame($public_api, $instance->publicApi()); } public function testId(): void { - $this->assertSame('foo', (new Provide('foo', $this->mock(Internal::class), $this->mock(Container::class)))->id()); + $this->assertSame('foo', (new Provide('foo', $this->stub(Internal::class), $this->stub(Container::class)))->id()); } } diff --git a/components/ILIAS/LegalDocuments/tests/Repository/DatabaseDocumentRepositoryTest.php b/components/ILIAS/LegalDocuments/tests/Repository/DatabaseDocumentRepositoryTest.php index e0adbce80d76..b34ee98c0edd 100755 --- a/components/ILIAS/LegalDocuments/tests/Repository/DatabaseDocumentRepositoryTest.php +++ b/components/ILIAS/LegalDocuments/tests/Repository/DatabaseDocumentRepositoryTest.php @@ -34,6 +34,6 @@ class DatabaseDocumentRepositoryTest extends TestCase public function testConstruct(): void { - $this->assertInstanceOf(DatabaseDocumentRepository::class, new DatabaseDocumentRepository('foo', $this->mock(ilDBInterface::class), $this->mock(UserAction::class))); + $this->assertInstanceOf(DatabaseDocumentRepository::class, new DatabaseDocumentRepository('foo', $this->stub(ilDBInterface::class), $this->stub(UserAction::class))); } } diff --git a/components/ILIAS/LegalDocuments/tests/Repository/DatabaseHistoryRepositoryTest.php b/components/ILIAS/LegalDocuments/tests/Repository/DatabaseHistoryRepositoryTest.php index 00a1ffaffbd6..984268de8caf 100755 --- a/components/ILIAS/LegalDocuments/tests/Repository/DatabaseHistoryRepositoryTest.php +++ b/components/ILIAS/LegalDocuments/tests/Repository/DatabaseHistoryRepositoryTest.php @@ -35,6 +35,6 @@ class DatabaseHistoryRepositoryTest extends TestCase public function testConstruct(): void { - $this->assertInstanceOf(DatabaseHistoryRepository::class, new DatabaseHistoryRepository('foo', $this->mock(DocumentRepositoryMeta::class), $this->mock(ilDBInterface::class), $this->mock(UserAction::class))); + $this->assertInstanceOf(DatabaseHistoryRepository::class, new DatabaseHistoryRepository('foo', $this->stub(DocumentRepositoryMeta::class), $this->stub(ilDBInterface::class), $this->stub(UserAction::class))); } } diff --git a/components/ILIAS/LegalDocuments/tests/Repository/ReadOnlyDocumentRepositoryTest.php b/components/ILIAS/LegalDocuments/tests/Repository/ReadOnlyDocumentRepositoryTest.php index 789a8ff65d1a..2dba1034886d 100755 --- a/components/ILIAS/LegalDocuments/tests/Repository/ReadOnlyDocumentRepositoryTest.php +++ b/components/ILIAS/LegalDocuments/tests/Repository/ReadOnlyDocumentRepositoryTest.php @@ -33,6 +33,6 @@ class ReadOnlyDocumentRepositoryTest extends TestCase public function testConstruct(): void { - $this->assertInstanceOf(ReadOnlyDocumentRepository::class, new ReadOnlyDocumentRepository($this->mock(DocumentRepository::class))); + $this->assertInstanceOf(ReadOnlyDocumentRepository::class, new ReadOnlyDocumentRepository($this->stub(DocumentRepository::class))); } } diff --git a/components/ILIAS/LegalDocuments/tests/Setup/AgentTest.php b/components/ILIAS/LegalDocuments/tests/Setup/AgentTest.php index 8efa3b303483..79f5f037993f 100755 --- a/components/ILIAS/LegalDocuments/tests/Setup/AgentTest.php +++ b/components/ILIAS/LegalDocuments/tests/Setup/AgentTest.php @@ -38,47 +38,47 @@ class AgentTest extends TestCase public function testConstruct(): void { - $this->assertInstanceOf(Agent::class, new Agent($this->mock(Refinery::class))); + $this->assertInstanceOf(Agent::class, new Agent($this->stub(Refinery::class))); } public function testHasConfig(): void { - $this->assertFalse((new Agent($this->mock(Refinery::class)))->hasConfig()); + $this->assertFalse((new Agent($this->stub(Refinery::class)))->hasConfig()); } public function testGetArrayToConfigTransformation(): void { - $identity = $this->mock(Transformation::class); - $this->assertSame($identity, (new Agent($this->mockTree(Refinery::class, ['identity' => $identity])))->getArrayToConfigTransformation()); + $identity = $this->stub(Transformation::class); + $this->assertSame($identity, (new Agent($this->stubTree(Refinery::class, ['identity' => $identity])))->getArrayToConfigTransformation()); } public function testGetInstallObjective(): void { - $this->assertInstanceOf(NullObjective::class, (new Agent($this->mock(Refinery::class)))->getInstallObjective()); + $this->assertInstanceOf(NullObjective::class, (new Agent($this->stub(Refinery::class)))->getInstallObjective()); } public function testGetUpdateObjective(): void { - $this->assertInstanceOf(ilDatabaseUpdateStepsExecutedObjective::class, (new Agent($this->mock(Refinery::class)))->getUpdateObjective()); + $this->assertInstanceOf(ilDatabaseUpdateStepsExecutedObjective::class, (new Agent($this->stub(Refinery::class)))->getUpdateObjective()); } public function testGetBuildArtifactObjective(): void { - $this->assertInstanceOf(ConsumerObjective::class, (new Agent($this->mock(Refinery::class)))->getBuildObjective()); + $this->assertInstanceOf(ConsumerObjective::class, (new Agent($this->stub(Refinery::class)))->getBuildObjective()); } public function testGetStatusObjective(): void { - $this->assertInstanceOf(\ilDatabaseUpdateStepsMetricsCollectedObjective::class, (new Agent($this->mock(Refinery::class)))->getStatusObjective($this->mock(Storage::class))); + $this->assertInstanceOf(\ilDatabaseUpdateStepsMetricsCollectedObjective::class, (new Agent($this->stub(Refinery::class)))->getStatusObjective($this->stub(Storage::class))); } public function testGetMigrations(): void { - $this->assertSame([], (new Agent($this->mock(Refinery::class)))->getMigrations()); + $this->assertSame([], (new Agent($this->stub(Refinery::class)))->getMigrations()); } public function testGetNamedObjectives(): void { - $this->assertSame([], (new Agent($this->mock(Refinery::class)))->getNamedObjectives()); + $this->assertSame([], (new Agent($this->stub(Refinery::class)))->getNamedObjectives()); } } diff --git a/components/ILIAS/LegalDocuments/tests/SlotConstructorTest.php b/components/ILIAS/LegalDocuments/tests/SlotConstructorTest.php index 966ca5817b29..599be3bb7b31 100755 --- a/components/ILIAS/LegalDocuments/tests/SlotConstructorTest.php +++ b/components/ILIAS/LegalDocuments/tests/SlotConstructorTest.php @@ -40,48 +40,48 @@ class SlotConstructorTest extends TestCase public function testConstruct(): void { - $this->assertInstanceOf(SlotConstructor::class, new SlotConstructor('foo', $this->mock(Container::class), $this->mock(UserAction::class))); + $this->assertInstanceOf(SlotConstructor::class, new SlotConstructor('foo', $this->stub(Container::class), $this->stub(UserAction::class))); } public function testId(): void { - $this->assertSame('foo', (new SlotConstructor('foo', $this->mock(Container::class), $this->mock(UserAction::class)))->id()); + $this->assertSame('foo', (new SlotConstructor('foo', $this->stub(Container::class), $this->stub(UserAction::class)))->id()); } public function testHistory(): void { - $document = $this->mockTree(ProvideDocument::class, ['repository' => $this->mock(DatabaseDocumentRepository::class)]); - $instance = new SlotConstructor('foo', $this->mock(Container::class), $this->mock(UserAction::class)); + $document = $this->stubTree(ProvideDocument::class, ['repository' => $this->stub(DatabaseDocumentRepository::class)]); + $instance = new SlotConstructor('foo', $this->stub(Container::class), $this->stub(UserAction::class)); $this->assertInstanceOf(ProvideHistory::class, $instance->history($document)); } public function testDocument(): void { - $instance = new SlotConstructor('foo', $this->mock(Container::class), $this->mock(UserAction::class)); - $this->assertInstanceOf(ProvideDocument::class, $instance->document($this->mock(DocumentRepository::class), new SelectionMap(), [])); + $instance = new SlotConstructor('foo', $this->stub(Container::class), $this->stub(UserAction::class)); + $this->assertInstanceOf(ProvideDocument::class, $instance->document($this->stub(DocumentRepository::class), new SelectionMap(), [])); } public function testDocumentRepository(): void { - $instance = new SlotConstructor('foo', $this->mock(Container::class), $this->mock(UserAction::class)); + $instance = new SlotConstructor('foo', $this->stub(Container::class), $this->stub(UserAction::class)); $this->assertInstanceOf(DatabaseDocumentRepository::class, $instance->documentRepository()); } public function testReadOnlyDocuments(): void { - $instance = new SlotConstructor('foo', $this->mock(Container::class), $this->mock(UserAction::class)); - $this->assertInstanceOf(ReadOnlyDocumentRepository::class, $instance->readOnlyDocuments($this->mock(DocumentRepository::class))); + $instance = new SlotConstructor('foo', $this->stub(Container::class), $this->stub(UserAction::class)); + $this->assertInstanceOf(ReadOnlyDocumentRepository::class, $instance->readOnlyDocuments($this->stub(DocumentRepository::class))); } public function testWithdrawalFinished(): void { $called = false; - $container = $this->mockTree(Container::class, [ - 'http' => ['request' => $this->mockTree(ServerRequestInterface::class, ['getQueryParams' => ['withdrawal_finished' => 'foo']])] + $container = $this->stubTree(Container::class, [ + 'http' => ['request' => $this->stubTree(ServerRequestInterface::class, ['getQueryParams' => ['withdrawal_finished' => 'foo']])] ]); - $instance = new SlotConstructor('foo', $container, $this->mock(UserAction::class)); + $instance = new SlotConstructor('foo', $container, $this->stub(UserAction::class)); $proc = $instance->withdrawalFinished(function () use (&$called): void { $called = true; @@ -96,11 +96,11 @@ public function testWithdrawalFinishedWithoutQueryParam(): void { $called = false; - $container = $this->mockTree(Container::class, [ - 'http' => ['request' => $this->mockTree(ServerRequestInterface::class, ['getQueryParams' => []])] + $container = $this->stubTree(Container::class, [ + 'http' => ['request' => $this->stubTree(ServerRequestInterface::class, ['getQueryParams' => []])] ]); - $instance = new SlotConstructor('foo', $container, $this->mock(UserAction::class)); + $instance = new SlotConstructor('foo', $container, $this->stub(UserAction::class)); $proc = $instance->withdrawalFinished(function () use (&$called): void { $called = true; diff --git a/components/ILIAS/LegalDocuments/tests/SmoothTableConfigTest.php b/components/ILIAS/LegalDocuments/tests/SmoothTableConfigTest.php index 0feffcfc46dc..e522694aa1cd 100755 --- a/components/ILIAS/LegalDocuments/tests/SmoothTableConfigTest.php +++ b/components/ILIAS/LegalDocuments/tests/SmoothTableConfigTest.php @@ -32,6 +32,6 @@ class SmoothTableConfigTest extends TestCase public function testConstruct(): void { - $this->assertInstanceOf(SmoothTableConfig::class, new SmoothTableConfig($this->mock(ilTable2GUI::class))); + $this->assertInstanceOf(SmoothTableConfig::class, new SmoothTableConfig($this->stub(ilTable2GUI::class))); } } diff --git a/components/ILIAS/LegalDocuments/tests/SmoothTableFilterTest.php b/components/ILIAS/LegalDocuments/tests/SmoothTableFilterTest.php index 9a702acb0249..bc99ed62673f 100755 --- a/components/ILIAS/LegalDocuments/tests/SmoothTableFilterTest.php +++ b/components/ILIAS/LegalDocuments/tests/SmoothTableFilterTest.php @@ -32,6 +32,6 @@ class SmoothTableFilterTest extends TestCase public function testConstruct(): void { - $this->assertInstanceOf(SmoothTableFilter::class, new SmoothTableFilter($this->mock(ilTable2GUI::class), 'foo')); + $this->assertInstanceOf(SmoothTableFilter::class, new SmoothTableFilter($this->stub(ilTable2GUI::class), 'foo')); } } diff --git a/components/ILIAS/LegalDocuments/tests/StartUpStepTest.php b/components/ILIAS/LegalDocuments/tests/StartUpStepTest.php index fcc1662f58f5..52e6d54f8aa5 100755 --- a/components/ILIAS/LegalDocuments/tests/StartUpStepTest.php +++ b/components/ILIAS/LegalDocuments/tests/StartUpStepTest.php @@ -34,20 +34,20 @@ class StartUpStepTest extends TestCase public function testConstruct(): void { - $this->assertInstanceOf(StartUpStep::class, new StartUpStep($this->mock(ilCtrl::class), $this->mock(Conductor::class))); + $this->assertInstanceOf(StartUpStep::class, new StartUpStep($this->stub(ilCtrl::class), $this->stub(Conductor::class))); } public function testShouldStoreRequestTarget(): void { - $instance = new StartUpStep($this->mock(ilCtrl::class), $this->mock(Conductor::class)); + $instance = new StartUpStep($this->stub(ilCtrl::class), $this->stub(Conductor::class)); $this->assertTrue($instance->shouldStoreRequestTarget()); } public function testShouldInterceptRequest(): void { - $instance = new StartUpStep($this->mock(ilCtrl::class), $this->mockTree(Conductor::class, ['intercepting' => [ - $this->mockTree(Intercept::class, ['intercept' => false]), - $this->mockTree(Intercept::class, ['intercept' => true]), + $instance = new StartUpStep($this->stub(ilCtrl::class), $this->stubTree(Conductor::class, ['intercepting' => [ + $this->stubTree(Intercept::class, ['intercept' => false]), + $this->stubTree(Intercept::class, ['intercept' => true]), ]])); $this->assertTrue($instance->shouldInterceptRequest()); @@ -60,9 +60,9 @@ public function testExecute(): void $ctrl->expects($this->once())->method('getLinkTargetByClass')->with(['foo'], 'bar')->willReturn('link'); $ctrl->expects($this->once())->method('redirectToURL')->with('link'); - $instance = new StartUpStep($ctrl, $this->mockTree(Conductor::class, ['intercepting' => [ - $this->mockTree(Intercept::class, ['intercept' => false, 'id' => 'ho', 'target' => ['guiName' => 'dummy', 'guiPath' => ['dummy'], 'command' => 'hej']]), - $this->mockTree(Intercept::class, ['intercept' => true, 'id' => 'baz', 'target' => ['guiName' => 'foo', 'guiPath' => ['foo'], 'command' => 'bar']]), + $instance = new StartUpStep($ctrl, $this->stubTree(Conductor::class, ['intercepting' => [ + $this->stubTree(Intercept::class, ['intercept' => false, 'id' => 'ho', 'target' => ['guiName' => 'dummy', 'guiPath' => ['dummy'], 'command' => 'hej']]), + $this->stubTree(Intercept::class, ['intercept' => true, 'id' => 'baz', 'target' => ['guiName' => 'foo', 'guiPath' => ['foo'], 'command' => 'bar']]), ]])); $instance->execute(); @@ -70,11 +70,11 @@ public function testExecute(): void public function testIsInFulfillment(): void { - $ctrl = $this->mockTree(ilCtrl::class, ['getCmdClass' => 'foo']); + $ctrl = $this->stubTree(ilCtrl::class, ['getCmdClass' => 'foo']); - $instance = new StartUpStep($ctrl, $this->mockTree(Conductor::class, ['intercepting' => [ - $this->mockTree(Intercept::class, ['intercept' => true, 'target' => ['guiName' => 'HEJ']]), - $this->mockTree(Intercept::class, ['intercept' => true, 'target' => ['guiName' => 'FOO']]), + $instance = new StartUpStep($ctrl, $this->stubTree(Conductor::class, ['intercepting' => [ + $this->stubTree(Intercept::class, ['intercept' => true, 'target' => ['guiName' => 'HEJ']]), + $this->stubTree(Intercept::class, ['intercept' => true, 'target' => ['guiName' => 'FOO']]), ]])); $this->assertTrue($instance->isInFulfillment()); diff --git a/components/ILIAS/LegalDocuments/tests/Table/DocumentModalTest.php b/components/ILIAS/LegalDocuments/tests/Table/DocumentModalTest.php index 29b681f60c5a..d61325bf75e8 100755 --- a/components/ILIAS/LegalDocuments/tests/Table/DocumentModalTest.php +++ b/components/ILIAS/LegalDocuments/tests/Table/DocumentModalTest.php @@ -42,25 +42,25 @@ class DocumentModalTest extends TestCase public function testConstruct(): void { - $this->assertInstanceOf(DocumentModal::class, new DocumentModal($this->mock(UIServices::class), $this->fail(...))); + $this->assertInstanceOf(DocumentModal::class, new DocumentModal($this->stub(UIServices::class), $this->fail(...))); } public function testCreate(): void { - $content = $this->mockTree(DocumentContent::class, ['title' => 'foo']); - $component = $this->mock(Component::class); - $signal = $this->mock(Signal::class); - $modal_component = $this->mockTree(Lightbox::class, ['getShowSignal' => $signal]); + $content = $this->stubTree(DocumentContent::class, ['title' => 'foo']); + $component = $this->stub(Component::class); + $signal = $this->stub(Signal::class); + $modal_component = $this->stubTree(Lightbox::class, ['getShowSignal' => $signal]); $button_component = $this->mock(Shy::class); $button_component->expects($this->once())->method('withOnClick')->with($signal)->willReturn($button_component); - $text_page = $this->mock(LightboxTextPage::class); + $text_page = $this->stub(LightboxTextPage::class); $modal = $this->mock(ModalFactory::class); $modal->expects($this->once())->method('lightboxTextPage')->with('rendered', 'foo')->willReturn($text_page); $modal->expects($this->once())->method('lightbox')->with([$text_page])->willReturn($modal_component); - $instance = new DocumentModal($this->mockTree(UIServices::class, [ + $instance = new DocumentModal($this->stubTree(UIServices::class, [ 'renderer' => $this->mockMethod(Renderer::class, 'render', [$component], 'rendered'), 'factory' => [ 'modal' => $modal, diff --git a/components/ILIAS/LegalDocuments/tests/Table/DocumentTableTest.php b/components/ILIAS/LegalDocuments/tests/Table/DocumentTableTest.php index adc6e3bf86f4..cb90300ce759 100755 --- a/components/ILIAS/LegalDocuments/tests/Table/DocumentTableTest.php +++ b/components/ILIAS/LegalDocuments/tests/Table/DocumentTableTest.php @@ -22,14 +22,9 @@ use ilCtrl; use ILIAS\Data\Factory; -use ILIAS\LegalDocuments\EditLinks; use ILIAS\UI\Component\Component; -use ILIAS\UI\Factory as UIFactory; use ILIAS\LegalDocuments\Value\CriterionContent; use ILIAS\LegalDocuments\Value\Criterion; -use ILIAS\LegalDocuments\Value\Document; -use ILIAS\LegalDocuments\TableSelection; -use ILIAS\LegalDocuments\TableConfig; use ILIAS\LegalDocuments\test\ContainerMock; use ILIAS\LegalDocuments\Table\DocumentModal; use ILIAS\LegalDocuments\ConsumerToolbox\UI; @@ -39,7 +34,6 @@ use ilObjUser; use PHPUnit\Framework\TestCase; use ILIAS\LegalDocuments\Table\DocumentTable; -use DateTimeImmutable; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\UriInterface; @@ -51,58 +45,58 @@ class DocumentTableTest extends TestCase public function testConstruct(): void { - $uri = $this->mock(UriInterface::class); + $uri = $this->stub(UriInterface::class); $uri->method('__toString')->willReturn('http://myIlias/ilias.php?baseClass=iladministrationgui&cmdNode=2g.qo.gq&cmdClass=ilLegalDocumentsAdministrationGUI&cmd=documents&ref_id=50'); - $request = $this->mock(ServerRequestInterface::class); + $request = $this->stub(ServerRequestInterface::class); $request->method("getUri")->willReturn($uri); $this->assertInstanceOf(DocumentTable::class, new DocumentTable( $this->fail(...), - $this->mock(DocumentRepository::class), - $this->mock(UI::class), - $this->mock(DocumentModal::class), - $this->mock(ilLegalDocumentsAdministrationGUI::class), + $this->stub(DocumentRepository::class), + $this->stub(UI::class), + $this->stub(DocumentModal::class), + $this->stub(ilLegalDocumentsAdministrationGUI::class), null, $request, new Factory(), - $this->mock(ilCtrl::class), - $this->mock(Renderer::class), - $this->mockTree(ilObjUser::class, ['getTimeZone' => 'europe/berlin']) + $this->stub(ilCtrl::class), + $this->stub(Renderer::class), + $this->stubTree(ilObjUser::class, ['getTimeZone' => 'europe/berlin']) )); } public function testCriterionName(): void { - $uri = $this->mock(UriInterface::class); + $uri = $this->stub(UriInterface::class); $uri->method('__toString')->willReturn('http://myIlias/ilias.php?baseClass=iladministrationgui&cmdNode=2g.qo.gq&cmdClass=ilLegalDocumentsAdministrationGUI&cmd=documents&ref_id=50'); - $request = $this->mock(ServerRequestInterface::class); + $request = $this->stub(ServerRequestInterface::class); $request->method("getUri")->willReturn($uri); - $content = $this->mock(CriterionContent::class); - $component = $this->mock(Component::class); + $content = $this->stub(CriterionContent::class); + $component = $this->stub(Component::class); $instance = new DocumentTable( function (CriterionContent $c) use ($content, $component) { $this->assertSame($content, $c); return $component; }, - $this->mock(DocumentRepository::class), - $this->mock(UI::class), - $this->mock(DocumentModal::class), - $this->mock(ilLegalDocumentsAdministrationGUI::class), + $this->stub(DocumentRepository::class), + $this->stub(UI::class), + $this->stub(DocumentModal::class), + $this->stub(ilLegalDocumentsAdministrationGUI::class), null, $request, new Factory(), - $this->mock(ilCtrl::class), - $this->mock(Renderer::class), - $this->mockTree(ilObjUser::class, ['getTimeZone' => 'europe/berlin']) + $this->stub(ilCtrl::class), + $this->stub(Renderer::class), + $this->stubTree(ilObjUser::class, ['getTimeZone' => 'europe/berlin']) ); $this->assertSame( $component, - $instance->criterionName($this->mockTree(Criterion::class, ['content' => $content])) + $instance->criterionName($this->stubTree(Criterion::class, ['content' => $content])) ); } } diff --git a/components/ILIAS/LegalDocuments/tests/Table/HistoryTableTest.php b/components/ILIAS/LegalDocuments/tests/Table/HistoryTableTest.php index 7163ad5e2686..6abe2a03251e 100755 --- a/components/ILIAS/LegalDocuments/tests/Table/HistoryTableTest.php +++ b/components/ILIAS/LegalDocuments/tests/Table/HistoryTableTest.php @@ -43,12 +43,12 @@ class HistoryTableTest extends TestCase public function testConstruct(): void { $this->assertInstanceOf(HistoryTable::class, new HistoryTable( - $this->mock(HistoryRepository::class), - $this->mock(ProvideDocument::class), + $this->stub(HistoryRepository::class), + $this->stub(ProvideDocument::class), 'reset', 'auto-complete-link', - $this->mock(UI::class), - $this->mock(DocumentModal::class), + $this->stub(UI::class), + $this->stub(DocumentModal::class), $this->fail(...) )); } @@ -59,12 +59,12 @@ public function testColumns(): void $ui->expects($this->exactly(6))->method('txt')->willReturnCallback(fn($key) => 'txt: ' . $key); $instance = new HistoryTable( - $this->mock(HistoryRepository::class), - $this->mock(ProvideDocument::class), + $this->stub(HistoryRepository::class), + $this->stub(ProvideDocument::class), 'reset', 'auto-complete-link', $ui, - $this->mock(DocumentModal::class), + $this->stub(DocumentModal::class), $this->fail(...) ); @@ -91,17 +91,17 @@ class_exists(ilDateTime::class, true); // Trigger autoload to ensure IL_CAL_UNIX $config->expects($this->once())->method('setSelectableColumns')->with('firstname', 'lastname', 'criteria'); $config->expects($this->once())->method('asFilter')->with('reset command')->willReturn($filter); - $ui = $this->mock(UI::class); + $ui = $this->stub(UI::class); $ui->method('txt')->willReturnCallback(fn($key) => 'txt: ' . $key); $instance = new HistoryTable( - $this->mock(HistoryRepository::class), - $this->mock(ProvideDocument::class), + $this->stub(HistoryRepository::class), + $this->stub(ProvideDocument::class), 'reset command', 'auto-complete-link', $ui, - $this->mock(DocumentModal::class), - $this->mock(...) + $this->stub(DocumentModal::class), + $this->stub(...) ); $instance->config($config); @@ -118,8 +118,8 @@ public function testRows(): void 4, 34 )->willReturn([ - $this->mock(History::class), - $this->mock(History::class), + $this->stub(History::class), + $this->stub(History::class), ]); $selection = $this->mockTree(TableSelection::class, [ @@ -133,12 +133,12 @@ public function testRows(): void $instance = new HistoryTable( $repository, - $this->mock(ProvideDocument::class), + $this->stub(ProvideDocument::class), 'reset command', 'auto-complete-link', - $this->mock(UI::class), - $this->mock(DocumentModal::class), - $this->mock(...), + $this->stub(UI::class), + $this->stub(DocumentModal::class), + $this->stub(...), fn(DateTimeImmutable $date) => 'formated' ); @@ -162,12 +162,12 @@ public function testRows(): void public function testName(): void { $instance = new HistoryTable( - $this->mock(HistoryRepository::class), - $this->mock(ProvideDocument::class), + $this->stub(HistoryRepository::class), + $this->stub(ProvideDocument::class), 'reset command', 'auto-complete-link', - $this->mock(UI::class), - $this->mock(DocumentModal::class), + $this->stub(UI::class), + $this->stub(DocumentModal::class), $this->fail(...) ); diff --git a/components/ILIAS/LegalDocuments/tests/UserActionTest.php b/components/ILIAS/LegalDocuments/tests/UserActionTest.php index dbbf1e5449a1..24ef42a0d3a6 100755 --- a/components/ILIAS/LegalDocuments/tests/UserActionTest.php +++ b/components/ILIAS/LegalDocuments/tests/UserActionTest.php @@ -34,14 +34,14 @@ class UserActionTest extends TestCase public function testConstruct(): void { - $this->assertInstanceOf(UserAction::class, new UserAction($this->mock(ilObjUser::class), $this->mock(Clock::class))); + $this->assertInstanceOf(UserAction::class, new UserAction($this->stub(ilObjUser::class), $this->stub(Clock::class))); } public function testModifiedNow(): void { $date = new DateTimeImmutable(); - $instance = new UserAction($this->mockTree(ilObjUser::class, ['getId' => 34]), $this->mockTree(Clock::class, ['now' => $date])); + $instance = new UserAction($this->stubTree(ilObjUser::class, ['getId' => 34]), $this->stubTree(Clock::class, ['now' => $date])); $edit = $instance->modifiedNow(); $this->assertSame(34, $edit->user()); diff --git a/components/ILIAS/LegalDocuments/tests/Value/CriterionTest.php b/components/ILIAS/LegalDocuments/tests/Value/CriterionTest.php index 1636a9f4881c..88574f3dac58 100755 --- a/components/ILIAS/LegalDocuments/tests/Value/CriterionTest.php +++ b/components/ILIAS/LegalDocuments/tests/Value/CriterionTest.php @@ -34,16 +34,16 @@ class CriterionTest extends TestCase public function testConstruct(): void { - $this->assertInstanceOf(Criterion::class, new Criterion(8, $this->mock(CriterionContent::class), $this->mock(Edit::class), $this->mock(Edit::class))); + $this->assertInstanceOf(Criterion::class, new Criterion(8, $this->stub(CriterionContent::class), $this->stub(Edit::class), $this->stub(Edit::class))); } public function testGetter(): void { $this->assertGetter(Criterion::class, [ 'id' => 8, - 'content' => $this->mock(CriterionContent::class), - 'lastModification' => $this->mock(Edit::class), - 'creation' => $this->mock(Edit::class), + 'content' => $this->stub(CriterionContent::class), + 'lastModification' => $this->stub(Edit::class), + 'creation' => $this->stub(Edit::class), ]); } } diff --git a/components/ILIAS/LegalDocuments/tests/Value/DocumentTest.php b/components/ILIAS/LegalDocuments/tests/Value/DocumentTest.php index b487f8530787..6338bbda5181 100755 --- a/components/ILIAS/LegalDocuments/tests/Value/DocumentTest.php +++ b/components/ILIAS/LegalDocuments/tests/Value/DocumentTest.php @@ -35,16 +35,16 @@ class DocumentTest extends TestCase public function testConstruct(): void { - $this->assertInstanceOf(Document::class, new Document(47, $this->mock(Meta::class), $this->mock(DocumentContent::class), [])); + $this->assertInstanceOf(Document::class, new Document(47, $this->stub(Meta::class), $this->stub(DocumentContent::class), [])); } public function testGetter(): void { $this->assertGetter(Document::class, [ 'id' => 80, - 'meta' => $this->mock(Meta::class), - 'content' => $this->mock(DocumentContent::class), - 'criteria' => [$this->mock(Criterion::class), $this->mock(Criterion::class)], + 'meta' => $this->stub(Meta::class), + 'content' => $this->stub(DocumentContent::class), + 'criteria' => [$this->stub(Criterion::class), $this->stub(Criterion::class)], ]); } } diff --git a/components/ILIAS/LegalDocuments/tests/Value/EditTest.php b/components/ILIAS/LegalDocuments/tests/Value/EditTest.php index 73049786f66d..7d737582cd6e 100755 --- a/components/ILIAS/LegalDocuments/tests/Value/EditTest.php +++ b/components/ILIAS/LegalDocuments/tests/Value/EditTest.php @@ -33,14 +33,14 @@ class EditTest extends TestCase public function testConstruct(): void { - $this->assertInstanceOf(Edit::class, new Edit(93, $this->mock(DateTimeImmutable::class))); + $this->assertInstanceOf(Edit::class, new Edit(93, $this->stub(DateTimeImmutable::class))); } public function testGetter(): void { $this->assertGetter(Edit::class, [ 'user' => 39, - 'time' => $this->mock(DateTimeImmutable::class), + 'time' => $this->stub(DateTimeImmutable::class), ]); } } diff --git a/components/ILIAS/LegalDocuments/tests/Value/HistoryTest.php b/components/ILIAS/LegalDocuments/tests/Value/HistoryTest.php index 71cb218f4d7e..85a96fa649c5 100755 --- a/components/ILIAS/LegalDocuments/tests/Value/HistoryTest.php +++ b/components/ILIAS/LegalDocuments/tests/Value/HistoryTest.php @@ -36,16 +36,16 @@ class HistoryTest extends TestCase public function testConstruct(): void { - $this->assertInstanceOf(History::class, new History($this->mock(Document::class), $this->mock(Edit::class), [], $this->mock(DocumentContent::class))); + $this->assertInstanceOf(History::class, new History($this->stub(Document::class), $this->stub(Edit::class), [], $this->stub(DocumentContent::class))); } public function testGetter(): void { $this->assertGetter(History::class, [ - 'currentDocument' => $this->mock(Document::class), - 'creation' => $this->mock(Edit::class), - 'criteriaContent' => [$this->mock(CriterionContent::class)], - 'documentContent' => $this->mock(DocumentContent::class), + 'currentDocument' => $this->stub(Document::class), + 'creation' => $this->stub(Edit::class), + 'criteriaContent' => [$this->stub(CriterionContent::class)], + 'documentContent' => $this->stub(DocumentContent::class), ]); } } diff --git a/components/ILIAS/LegalDocuments/tests/Value/MetaTest.php b/components/ILIAS/LegalDocuments/tests/Value/MetaTest.php index 21bd766b6be5..2344ba69842d 100755 --- a/components/ILIAS/LegalDocuments/tests/Value/MetaTest.php +++ b/components/ILIAS/LegalDocuments/tests/Value/MetaTest.php @@ -33,15 +33,15 @@ class MetaTest extends TestCase public function testConstruct(): void { - $this->assertInstanceOf(Meta::class, new Meta(8, $this->mock(Edit::class), $this->mock(Edit::class))); + $this->assertInstanceOf(Meta::class, new Meta(8, $this->stub(Edit::class), $this->stub(Edit::class))); } public function testGetter(): void { $this->assertGetter(Meta::class, [ 'sorting' => 348, - 'lastModification' => $this->mock(Edit::class), - 'creation' => $this->mock(Edit::class), + 'lastModification' => $this->stub(Edit::class), + 'creation' => $this->stub(Edit::class), ]); } } diff --git a/components/ILIAS/LegalDocuments/tests/WiringTest.php b/components/ILIAS/LegalDocuments/tests/WiringTest.php index d2bf5b73d63e..15aa585fa9bf 100755 --- a/components/ILIAS/LegalDocuments/tests/WiringTest.php +++ b/components/ILIAS/LegalDocuments/tests/WiringTest.php @@ -32,6 +32,7 @@ use PHPUnit\Framework\TestCase; use ILIAS\LegalDocuments\Wiring; use ILIAS\LegalDocuments\SelectionMap; +use PHPUnit\Framework\MockObject\MockObject; require_once __DIR__ . '/ContainerMock.php'; @@ -41,32 +42,32 @@ class WiringTest extends TestCase public function testConstruct(): void { - $this->assertInstanceOf(Wiring::class, new Wiring($this->mock(SlotConstructor::class), $this->mock(Map::class))); + $this->assertInstanceOf(Wiring::class, new Wiring($this->stub(SlotConstructor::class), $this->stub(Map::class))); } public function testAfterLogin(): void { - $map = $this->mock(Map::class); $proc = $this->fail(...); + $map = $this->mapExpecting('add', ['after-login', $proc]); - $instance = new Wiring($this->mock(SlotConstructor::class), $this->mockMethod(Map::class, 'add', ['after-login', $proc], $map)); + $instance = new Wiring($this->stub(SlotConstructor::class), $map); $this->assertSame($map, $instance->afterLogin($proc)->map()); } public function testShowInFooter(): void { - $map = $this->mock(Map::class); $proc = $this->fail(...); + $map = $this->mapExpecting('set', ['footer', 'foo', $proc]); - $instance = new Wiring($this->mockTree(SlotConstructor::class, ['id' => 'foo']), $this->mockMethod(Map::class, 'set', ['footer', 'foo', $proc], $map)); + $instance = new Wiring($this->stubTree(SlotConstructor::class, ['id' => 'foo']), $map); $this->assertSame($map, $instance->showInFooter($proc)->map()); } public function testCanWithdraw(): void { - $withdraw_process = $this->mock(WithdrawProcess::class); + $withdraw_process = $this->stub(WithdrawProcess::class); - $instance = new Wiring($this->mock(SlotConstructor::class), new Map()); + $instance = new Wiring($this->stub(SlotConstructor::class), new Map()); $map = $instance->canWithdraw($withdraw_process)->map()->value(); @@ -86,14 +87,14 @@ public function testCanWithdraw(): void public function testShowOnLoginPage(): void { $proc = $this->fail(...); - $instance = new Wiring($this->mockTree(SlotConstructor::class, ['id' => 'foo']), new Map()); + $instance = new Wiring($this->stubTree(SlotConstructor::class, ['id' => 'foo']), new Map()); $this->assertSame(['show-on-login-page' => ['foo' => $proc]], $instance->showOnLoginPage($proc)->map()->value()); } public function testHasAgreement(): void { - $instance = new Wiring($this->mock(SlotConstructor::class), new Map()); - $map = $instance->hasAgreement($this->mock(Agreement::class), 'bar')->map()->value(); + $instance = new Wiring($this->stub(SlotConstructor::class), new Map()); + $map = $instance->hasAgreement($this->stub(Agreement::class), 'bar')->map()->value(); $this->assertSame([ 'public-page', @@ -110,8 +111,8 @@ public function testHasAgreement(): void public function testHasHistory(): void { - $document = $this->mock(ProvideDocument::class); - $history = $this->mock(ProvideHistory::class); + $document = $this->stub(ProvideDocument::class); + $history = $this->stub(ProvideHistory::class); $slot = $this->mockMethod(SlotConstructor::class, 'history', [$document], $history); $slot->method('id')->willReturn('foo'); $map = $this->mockTree(Map::class, ['value' => ['document' => ['foo' => $document]]]); @@ -123,43 +124,43 @@ public function testHasHistory(): void public function testOnSelfRegistration(): void { - $map = $this->mock(Map::class); - $self_registration = $this->mock(SelfRegistration::class); + $self_registration = $this->stub(SelfRegistration::class); + $map = $this->mapExpecting('add', ['self-registration', $self_registration]); - $instance = new Wiring($this->mock(SlotConstructor::class), $this->mockMethod(Map::class, 'add', ['self-registration', $self_registration], $map)); + $instance = new Wiring($this->stub(SlotConstructor::class), $map); $this->assertSame($map, $instance->onSelfRegistration($self_registration)->map()); } public function testHasOnlineStatusFilter(): void { - $map = $this->mock(Map::class); $proc = $this->fail(...); + $map = $this->mapExpecting('add', ['filter-online-users', $proc]); - $instance = new Wiring($this->mock(SlotConstructor::class), $this->mockMethod(Map::class, 'add', ['filter-online-users', $proc], $map)); + $instance = new Wiring($this->stub(SlotConstructor::class), $map); $this->assertSame($map, $instance->hasOnlineStatusFilter($proc)->map()); } public function testCanReadInternalMails(): void { - $map = $this->mock(Map::class); - $constraint = $this->mock(Constraint::class); + $constraint = $this->stub(Constraint::class); + $map = $this->mapExpecting('add', ['constrain-internal-mail', $constraint]); - $instance = new Wiring($this->mock(SlotConstructor::class), $this->mockMethod(Map::class, 'add', ['constrain-internal-mail', $constraint], $map)); + $instance = new Wiring($this->stub(SlotConstructor::class), $map); $this->assertSame($map, $instance->canReadInternalMails($constraint)->map()); } public function testCanUseSoapApi(): void { - $map = $this->mock(Map::class); - $constraint = $this->mock(Constraint::class); + $constraint = $this->stub(Constraint::class); + $map = $this->mapExpecting('add', ['use-soap-api', $constraint]); - $instance = new Wiring($this->mock(SlotConstructor::class), $this->mockMethod(Map::class, 'add', ['use-soap-api', $constraint], $map)); + $instance = new Wiring($this->stub(SlotConstructor::class), $map); $this->assertSame($map, $instance->canUseSoapApi($constraint)->map()); } public function testHasDocuments(): void { - $instance = new Wiring($this->mock(SlotConstructor::class), new Map()); + $instance = new Wiring($this->stub(SlotConstructor::class), new Map()); $map = $instance->hasDocuments([], new SelectionMap())->map()->value(); $this->assertSame([ @@ -173,12 +174,12 @@ public function testHasDocuments(): void public function testHasUserManagementFields(): void { - $map = $this->mock(Map::class); $proc = $this->fail(...); + $map = $this->mapExpecting('set', ['user-management-fields', 'foo', $proc]); $instance = new Wiring( - $this->mockTree(SlotConstructor::class, ['id' => 'foo']), - $this->mockMethod(Map::class, 'set', ['user-management-fields', 'foo', $proc], $map) + $this->stubTree(SlotConstructor::class, ['id' => 'foo']), + $map ); $this->assertSame($map, $instance->hasUserManagementFields($proc)->map()); @@ -186,12 +187,12 @@ public function testHasUserManagementFields(): void public function testHasPublicApi(): void { - $map = $this->mock(Map::class); - $public_api = $this->mock(PublicApi::class); + $public_api = $this->stub(PublicApi::class); + $map = $this->mapExpecting('set', ['public-api', 'foo', $public_api]); $instance = new Wiring( - $this->mockTree(SlotConstructor::class, ['id' => 'foo']), - $this->mockMethod(Map::class, 'set', ['public-api', 'foo', $public_api], $map) + $this->stubTree(SlotConstructor::class, ['id' => 'foo']), + $map ); $this->assertSame($map, $instance->hasPublicApi($public_api)->map()); @@ -199,12 +200,12 @@ public function testHasPublicApi(): void public function testHasPublicPage(): void { - $map = $this->mock(Map::class); $public_page = fn() => null; + $map = $this->mapExpecting('set', ['public-page', 'foo']); $instance = new Wiring( - $this->mockTree(SlotConstructor::class, ['id' => 'foo']), - $this->mockMethod(Map::class, 'set', ['public-page', 'foo'], $map) + $this->stubTree(SlotConstructor::class, ['id' => 'foo']), + $map ); $this->assertSame($map, $instance->hasPublicPage($public_page)->map()); @@ -212,21 +213,32 @@ public function testHasPublicPage(): void public function testHasPublicPageWithGotoLink(): void { - $m = $this->mock(Map::class); - $map = $this->mockMethod(Map::class, 'add', ['goto'], $m); $public_page = fn() => null; + $map = $this->mock(Map::class); + $map->expects($this->once())->method('add')->with('goto')->willReturnSelf(); $instance = new Wiring( - $this->mockTree(SlotConstructor::class, ['id' => 'foo']), + $this->stubTree(SlotConstructor::class, ['id' => 'foo']), $this->mockMethod(Map::class, 'set', ['public-page', 'foo'], $map) ); - $this->assertSame($m, $instance->hasPublicPage($public_page, 'foo')->map()); + $this->assertSame($map, $instance->hasPublicPage($public_page, 'foo')->map()); } public function testMap(): void + { + $map = $this->stub(Map::class); + $this->assertSame($map, (new Wiring($this->stub(SlotConstructor::class), $map))->map()); + } + + /** + * @param list $arguments + */ + private function mapExpecting(string $method, array $arguments): Map&MockObject { $map = $this->mock(Map::class); - $this->assertSame($map, (new Wiring($this->mock(SlotConstructor::class), $map))->map()); + $map->expects($this->once())->method($method)->with(...$arguments)->willReturnSelf(); + + return $map; } }