diff --git a/components/ILIAS/Bibliographic/tests/ilBibtechParserTest.php b/components/ILIAS/Bibliographic/tests/ilBibtechParserTest.php index 435b02716f23..d6e44662898a 100755 --- a/components/ILIAS/Bibliographic/tests/ilBibtechParserTest.php +++ b/components/ILIAS/Bibliographic/tests/ilBibtechParserTest.php @@ -37,7 +37,7 @@ protected function setUp(): void $DIC['ilDB'] = $this->createMock(ilDBInterface::class); $DIC['refinery'] = new Factory( new ILIAS\Data\Factory(), - $this->getMockBuilder(ilLanguage::class)->disableOriginalConstructor()->getMock() + $this->createStub(ilLanguage::class) ); } @@ -49,9 +49,9 @@ protected function tearDown(): void public function testParseBibtechAsArray(): void { - $ilBiblEntryFactory = $this->createMock(ilBiblEntryFactoryInterface::class); - $ilBiblFieldFactory = $this->createMock(ilBiblFieldFactoryInterface::class); - $ilBiblAttributeFactory = $this->createMock(ilBiblAttributeFactoryInterface::class); + $ilBiblEntryFactory = $this->createStub(ilBiblEntryFactoryInterface::class); + $ilBiblFieldFactory = $this->createStub(ilBiblFieldFactoryInterface::class); + $ilBiblAttributeFactory = $this->createStub(ilBiblAttributeFactoryInterface::class); $reader = new ilBiblTexFileReader( $ilBiblEntryFactory, $ilBiblFieldFactory, @@ -97,9 +97,9 @@ public function testParseBibtechAsArray(): void public function testParseBibtechAsItems(): void { $ilBiblEntryFactory = $this->createMock(ilBiblEntryFactoryInterface::class); - $ilBiblFieldFactory = $this->createMock(ilBiblFieldFactoryInterface::class); - $ilBiblAttributeFactory = $this->createMock(ilBiblAttributeFactoryInterface::class); - $ilObjBibliographic = $this->createMock(ilObjBibliographic::class); + $ilBiblFieldFactory = $this->createStub(ilBiblFieldFactoryInterface::class); + $ilBiblAttributeFactory = $this->createStub(ilBiblAttributeFactoryInterface::class); + $ilObjBibliographic = $this->createStub(ilObjBibliographic::class); $reader = new ilBiblTexFileReader( $ilBiblEntryFactory, diff --git a/components/ILIAS/Bibliographic/tests/ilRisParserTest.php b/components/ILIAS/Bibliographic/tests/ilRisParserTest.php index 098438cde26c..14491a46655d 100644 --- a/components/ILIAS/Bibliographic/tests/ilRisParserTest.php +++ b/components/ILIAS/Bibliographic/tests/ilRisParserTest.php @@ -37,7 +37,7 @@ protected function setUp(): void $DIC['ilDB'] = $this->createMock(ilDBInterface::class); $DIC['refinery'] = new Factory( new ILIAS\Data\Factory(), - $this->getMockBuilder(ilLanguage::class)->disableOriginalConstructor()->getMock() + $this->createStub(ilLanguage::class) ); } @@ -49,9 +49,9 @@ protected function tearDown(): void public function testParseRisAsArray(): void { - $ilBiblEntryFactory = $this->createMock(ilBiblEntryFactoryInterface::class); - $ilBiblFieldFactory = $this->createMock(ilBiblFieldFactoryInterface::class); - $ilBiblAttributeFactory = $this->createMock(ilBiblAttributeFactoryInterface::class); + $ilBiblEntryFactory = $this->createStub(ilBiblEntryFactoryInterface::class); + $ilBiblFieldFactory = $this->createStub(ilBiblFieldFactoryInterface::class); + $ilBiblAttributeFactory = $this->createStub(ilBiblAttributeFactoryInterface::class); $reader = new ilBiblRisFileReader( $ilBiblEntryFactory, $ilBiblFieldFactory, @@ -94,9 +94,9 @@ public function testParseRisAsArray(): void public function testParseRisAsItems(): void { $ilBiblEntryFactory = $this->createMock(ilBiblEntryFactoryInterface::class); - $ilBiblFieldFactory = $this->createMock(ilBiblFieldFactoryInterface::class); - $ilBiblAttributeFactory = $this->createMock(ilBiblAttributeFactoryInterface::class); - $ilObjBibliographic = $this->createMock(ilObjBibliographic::class); + $ilBiblFieldFactory = $this->createStub(ilBiblFieldFactoryInterface::class); + $ilBiblAttributeFactory = $this->createStub(ilBiblAttributeFactoryInterface::class); + $ilObjBibliographic = $this->createStub(ilObjBibliographic::class); $reader = new ilBiblRisFileReader( $ilBiblEntryFactory, diff --git a/components/ILIAS/Cache/tests/CacheTest.php b/components/ILIAS/Cache/tests/CacheTest.php index 515342dc72ac..3cb2ce046fef 100755 --- a/components/ILIAS/Cache/tests/CacheTest.php +++ b/components/ILIAS/Cache/tests/CacheTest.php @@ -43,10 +43,9 @@ class CacheTest extends TestCase protected function setUp(): void { - $language_mock = $this->createMock(\ilLanguage::class); $this->refinery = new Factory( new \ILIAS\Data\Factory(), - $language_mock + $this->createStub(\ilLanguage::class) ); // prevent chached values between tests $static_flush = new PHPStatic($this->getConfig(Config::PHPSTATIC)); diff --git a/components/ILIAS/Cache/tests/Setup/ilGlobalCacheSetupAgentTest.php b/components/ILIAS/Cache/tests/Setup/ilGlobalCacheSetupAgentTest.php index a670c733a96c..0c065e3e349a 100755 --- a/components/ILIAS/Cache/tests/Setup/ilGlobalCacheSetupAgentTest.php +++ b/components/ILIAS/Cache/tests/Setup/ilGlobalCacheSetupAgentTest.php @@ -42,7 +42,7 @@ class ilGlobalCacheSetupAgentTest extends TestCase public function setUp(): void { - $refinery = new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class)); + $refinery = new Refinery($this->createStub(DataFactory::class), $this->createStub(\ilLanguage::class)); $this->obj = new TestObj($refinery); } @@ -242,7 +242,7 @@ public function testGetMemcachedServerInactive(): void public function testGetInstallObjectives(): void { - $setup_conf_mock = $this->createMock(\ilGlobalCacheSettingsAdapter::class); + $setup_conf_mock = $this->createStub(\ilGlobalCacheSettingsAdapter::class); $objective_collection = $this->obj->getInstallObjective($setup_conf_mock); $this->assertEquals('Store configuration of components/ILIAS/GlobalCache_', $objective_collection->getLabel()); @@ -251,7 +251,7 @@ public function testGetInstallObjectives(): void public function testGetUpdateObjective(): void { - $setup_conf_mock = $this->createMock(\ilGlobalCacheSettingsAdapter::class); + $setup_conf_mock = $this->createStub(\ilGlobalCacheSettingsAdapter::class); $objective_collection = $this->obj->getUpdateObjective($setup_conf_mock); $this->assertEquals('Store configuration of components/ILIAS/GlobalCache_', $objective_collection->getLabel()); diff --git a/components/ILIAS/Component/tests/Dependencies/OfComponentTest.php b/components/ILIAS/Component/tests/Dependencies/OfComponentTest.php index db6bdaa33bd6..44229d1de132 100644 --- a/components/ILIAS/Component/tests/Dependencies/OfComponentTest.php +++ b/components/ILIAS/Component/tests/Dependencies/OfComponentTest.php @@ -26,12 +26,15 @@ class OfComponentTest extends TestCase { - protected Component $component; + /** + * @var \PHPUnit\Framework\MockObject\Stub&\ILIAS\Component\Component + */ + protected \PHPUnit\Framework\MockObject\Stub $component; protected D\OfComponent $of_component; public function setUp(): void { - $this->component = $this->createMock(Component::class); + $this->component = $this->createStub(Component::class); $this->of_component = new D\OfComponent( $this->component ); diff --git a/components/ILIAS/Component/tests/Dependencies/ResolverTest.php b/components/ILIAS/Component/tests/Dependencies/ResolverTest.php index be44a8a658ad..fc90ac4ca05b 100644 --- a/components/ILIAS/Component/tests/Dependencies/ResolverTest.php +++ b/components/ILIAS/Component/tests/Dependencies/ResolverTest.php @@ -43,7 +43,7 @@ public function testEmptyComponentSet(): void public function testResolvePull(): void { - $component = $this->createMock(Component::class); + $component = $this->createStub(Component::class); $name = TestInterface::class; @@ -69,7 +69,7 @@ public function testPullFailsNotExistent(): void { $this->expectException(\LogicException::class); - $component = $this->createMock(Component::class); + $component = $this->createStub(Component::class); $name = TestInterface::class; @@ -84,7 +84,7 @@ public function testPullFailsDuplicate(): void { $this->expectException(\LogicException::class); - $component = $this->createMock(Component::class); + $component = $this->createStub(Component::class); $name = TestInterface::class; @@ -101,7 +101,7 @@ public function testPullFailsDuplicate(): void public function testEmptySeek(): void { - $component = $this->createMock(Component::class); + $component = $this->createStub(Component::class); $name = TestInterface::class; @@ -116,7 +116,7 @@ public function testEmptySeek(): void public function testResolveSeek(): void { - $component = $this->createMock(Component::class); + $component = $this->createStub(Component::class); $name = TestInterface::class; @@ -146,7 +146,7 @@ public function testResolveSeek(): void public function testResolveUseOneOption(): void { - $component = $this->createMock(Component::class); + $component = $this->createStub(Component::class); $name = TestInterface::class; @@ -172,7 +172,7 @@ public function testUseFailsNotExistent(): void { $this->expectException(\LogicException::class); - $component = $this->createMock(Component::class); + $component = $this->createStub(Component::class); $name = TestInterface::class; @@ -187,7 +187,7 @@ public function testUseFailsDuplicate(): void { $this->expectException(\LogicException::class); - $component = $this->createMock(Component::class); + $component = $this->createStub(Component::class); $name = TestInterface::class; @@ -204,7 +204,7 @@ public function testUseFailsDuplicate(): void public function testUseDisambiguateDuplicateSpecific(): void { - $component = $this->createMock(Component::class); + $component = $this->createStub(Component::class); $name = TestInterface::class; @@ -238,7 +238,7 @@ public function testUseDisambiguateDuplicateSpecific(): void public function testUseDisambiguateDuplicateGeneric(): void { - $component = $this->createMock(Component::class); + $component = $this->createStub(Component::class); $name = TestInterface::class; @@ -275,7 +275,7 @@ public function testFindSimpleCycle(): void { $this->expectException(\LogicException::class); - $component = $this->createMock(Component::class); + $component = $this->createStub(Component::class); $name = TestInterface::class; $name2 = TestInterface2::class; @@ -296,7 +296,7 @@ public function testFindLongerCycle(): void { $this->expectException(\LogicException::class); - $component = $this->createMock(Component::class); + $component = $this->createStub(Component::class); $name = TestInterface::class; $name2 = TestInterface2::class; diff --git a/components/ILIAS/Component/tests/Settings/ilPluginsOverviewTableTest.php b/components/ILIAS/Component/tests/Settings/ilPluginsOverviewTableTest.php index ab4e6ec4ac2f..b5512aee13cf 100755 --- a/components/ILIAS/Component/tests/Settings/ilPluginsOverviewTableTest.php +++ b/components/ILIAS/Component/tests/Settings/ilPluginsOverviewTableTest.php @@ -28,18 +28,27 @@ class ilPluginsOverviewTableTest extends TestCase { - protected ilObjComponentSettingsGUI $parent_gui; - protected ilCtrl $ctrl; + /** + * @var \PHPUnit\Framework\MockObject\Stub&\ilObjComponentSettingsGUI + */ + protected \PHPUnit\Framework\MockObject\Stub $parent_gui; + /** + * @var \PHPUnit\Framework\MockObject\Stub&\ilCtrl + */ + protected \PHPUnit\Framework\MockObject\Stub $ctrl; protected Factory $ui; - protected Renderer $renderer; + /** + * @var \PHPUnit\Framework\MockObject\Stub&\ILIAS\UI\Renderer + */ + protected \PHPUnit\Framework\MockObject\Stub $renderer; protected ilLanguage $lng; protected function setUp(): void { - $this->parent_gui = $this->createMock(ilObjComponentSettingsGUI::class); - $this->ctrl = $this->createMock(ilCtrl::class); + $this->parent_gui = $this->createStub(ilObjComponentSettingsGUI::class); + $this->ctrl = $this->createStub(ilCtrl::class); $this->ui = $this->createMock(Factory::class); - $this->renderer = $this->createMock(Renderer::class); + $this->renderer = $this->createStub(Renderer::class); $this->lng = $this->createMock(ilLanguage::class); $this->lng->method("txt") ->willReturnCallback(fn($id) => $id); @@ -300,7 +309,7 @@ public function withDataWrapper(array $data) public function testGetActionsPluginNotInstalled(): void { - $shy = $this->createMock(Shy::class); + $shy = $this->createStub(Shy::class); $standard = $this->createMock(Standard::class); $standard @@ -368,7 +377,7 @@ protected function getDropdownButton(string $caption, string $command): Shy public function testGetActionsPluginInstalled(): void { - $shy = $this->createMock(Shy::class); + $shy = $this->createStub(Shy::class); $standard = $this->createMock(Standard::class); $standard diff --git a/components/ILIAS/Component/tests/ilArtifactComponentRepositoryTest.php b/components/ILIAS/Component/tests/ilArtifactComponentRepositoryTest.php index 82659be5eebc..d9368252399c 100755 --- a/components/ILIAS/Component/tests/ilArtifactComponentRepositoryTest.php +++ b/components/ILIAS/Component/tests/ilArtifactComponentRepositoryTest.php @@ -82,7 +82,10 @@ class ilArtifactComponentRepositoryTest extends TestCase ]; protected Data\Factory $data_factory; - protected Data\Version $ilias_version; + /** + * @var \PHPUnit\Framework\MockObject\Stub&\ILIAS\Data\Version + */ + protected \PHPUnit\Framework\MockObject\Stub $ilias_version; protected ilPluginStateDB $plugin_state_db; protected ilArtifactComponentRepository $db; protected ilComponentInfo $mod1; @@ -100,7 +103,7 @@ class ilArtifactComponentRepositoryTest extends TestCase protected function setUp(): void { $this->data_factory = new Data\Factory(); - $this->ilias_version = $this->createMock(Data\Version::class); + $this->ilias_version = $this->createStub(Data\Version::class); $this->plugin_state_db = new class () implements ilPluginStateDB { public function isPluginActivated(string $id): bool { @@ -491,15 +494,15 @@ public function testSetCurrentPluginVersionCallsStateDB(): void $DB_VERSION = 1000; $plugin_state_db = $this->createMock(ilPluginStateDB::class); - $plugin_state_db + $plugin_state_db->expects($this->atLeastOnce()) ->method("isPluginActivated") ->with("plg1") ->willReturn(true); - $plugin_state_db + $plugin_state_db->expects($this->atLeastOnce()) ->method("getCurrentPluginVersion") ->with("plg1") ->willReturn($this->data_factory->version("1.8.0")); - $plugin_state_db + $plugin_state_db->expects($this->atLeastOnce()) ->method("getCurrentPluginDBVersion") ->with("plg1") ->willReturn(42); @@ -541,7 +544,7 @@ public function testSetCurrentPluginVersionCallsStateDBTriggersRebuild(): void $VERSION = $this->data_factory->version("1000.0.0"); $DB_VERSION = 1000; - $plugin_state_db = $this->createMock(ilPluginStateDB::class); + $plugin_state_db = $this->createStub(ilPluginStateDB::class); $db = new class ($this->data_factory, $plugin_state_db, $this->ilias_version) extends ilArtifactComponentRepository { public int $build_called = 0; protected function buildDatabase(): void @@ -631,7 +634,7 @@ protected function readPluginData(): array public function testSetActivationTriggersRebuild(): void { - $plugin_state_db = $this->createMock(ilPluginStateDB::class); + $plugin_state_db = $this->createStub(ilPluginStateDB::class); $db = new class ($this->data_factory, $plugin_state_db, $this->ilias_version) extends ilArtifactComponentRepository { public int $build_called = 0; protected function buildDatabase(): void @@ -710,7 +713,7 @@ protected function readPluginData(): array public function testRemoveStateInformationOfTriggersRebuild(): void { - $plugin_state_db = $this->createMock(ilPluginStateDB::class); + $plugin_state_db = $this->createStub(ilPluginStateDB::class); $db = new class ($this->data_factory, $plugin_state_db, $this->ilias_version) extends ilArtifactComponentRepository { public int $build_called = 0; protected function buildDatabase(): void diff --git a/components/ILIAS/Component/tests/ilPluginStateDBOverIlDBInterfaceTest.php b/components/ILIAS/Component/tests/ilPluginStateDBOverIlDBInterfaceTest.php index 8add6312c554..5a243f67d3c9 100755 --- a/components/ILIAS/Component/tests/ilPluginStateDBOverIlDBInterfaceTest.php +++ b/components/ILIAS/Component/tests/ilPluginStateDBOverIlDBInterfaceTest.php @@ -52,7 +52,7 @@ protected function setUp(): void public function testIsPluginActivated(): void { - $handle = $this->createMock(\ilDBStatement::class); + $handle = $this->createStub(\ilDBStatement::class); $this->il_db->expects($this->once()) ->method("query") @@ -70,7 +70,7 @@ public function testIsPluginActivated(): void public function testGetCurrentPluginVersion(): void { - $handle = $this->createMock(\ilDBStatement::class); + $handle = $this->createStub(\ilDBStatement::class); $this->il_db->expects($this->once()) ->method("query") @@ -88,7 +88,7 @@ public function testGetCurrentPluginVersion(): void public function testGetCurrentPluginDBVersion(): void { - $handle = $this->createMock(\ilDBStatement::class); + $handle = $this->createStub(\ilDBStatement::class); $this->il_db->expects($this->once()) ->method("query") @@ -106,7 +106,7 @@ public function testGetCurrentPluginDBVersion(): void public function testSetCurrentPluginVersionKnownPlugin(): void { - $handle = $this->createMock(\ilDBStatement::class); + $handle = $this->createStub(\ilDBStatement::class); $this->il_db->expects($this->once()) ->method("query") @@ -139,7 +139,7 @@ public function testSetCurrentPluginVersionKnownPlugin(): void public function testSetCurrentPluginVersionUnknownPlugin(): void { - $handle = $this->createMock(\ilDBStatement::class); + $handle = $this->createStub(\ilDBStatement::class); $this->il_db->expects($this->once()) ->method("query") @@ -177,7 +177,7 @@ public function testSetActivationNotExistingPlugin(): void public function testSetActivationTrue(): void { - $handle = $this->createMock(\ilDBStatement::class); + $handle = $this->createStub(\ilDBStatement::class); $this->il_db->expects($this->once()) ->method("query") @@ -207,7 +207,7 @@ public function testSetActivationTrue(): void public function testSetActivationFalse(): void { - $handle = $this->createMock(\ilDBStatement::class); + $handle = $this->createStub(\ilDBStatement::class); $this->il_db->expects($this->once()) ->method("query") diff --git a/components/ILIAS/EventHandling/tests/EventTest.php b/components/ILIAS/EventHandling/tests/EventTest.php index 20d6c5c1e035..cc7d02b0b909 100755 --- a/components/ILIAS/EventHandling/tests/EventTest.php +++ b/components/ILIAS/EventHandling/tests/EventTest.php @@ -60,17 +60,15 @@ protected function setUp(): void ); $this->setGlobalVariable( "ilSetting", - $this->createMock(ilSetting::class) + $this->createStub(ilSetting::class) ); - $component_repository = $this->createMock(ilComponentRepository::class); $this->setGlobalVariable( "component.repository", - $component_repository + $this->createStub(ilComponentRepository::class) ); - $component_factory = $this->createMock(ilComponentFactory::class); $this->setGlobalVariable( "component.factory", - $component_factory + $this->createStub(ilComponentFactory::class) ); } diff --git a/components/ILIAS/File/tests/Capabilities/CapabilityTest.php b/components/ILIAS/File/tests/Capabilities/CapabilityTest.php index 709ae75f4b2c..cd2d4f3db968 100644 --- a/components/ILIAS/File/tests/Capabilities/CapabilityTest.php +++ b/components/ILIAS/File/tests/Capabilities/CapabilityTest.php @@ -30,15 +30,28 @@ use ILIAS\File\Capabilities\TypeResolver; use ILIAS\File\Capabilities\Context; +#[\PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations] class CapabilityTest extends TestCase { /** - * @var (\ilWorkspaceAccessHandler & \PHPUnit\Framework\MockObject\MockObject) + * @var \ilWorkspaceAccessHandler&\PHPUnit\Framework\MockObject\Stub + */ + public \PHPUnit\Framework\MockObject\Stub $workspace_access_handler; + /** + * @var \PHPUnit\Framework\MockObject\MockObject&\ILIAS\File\Capabilities\TypeResolver */ - public MockObject $workspace_access_handler; public MockObject $type_resolver; + /** + * @var \PHPUnit\Framework\MockObject\MockObject&\ilObjFileInfoRepository + */ private MockObject $file_info_repository; + /** + * @var \PHPUnit\Framework\MockObject\MockObject&\ilAccessHandler + */ private MockObject $access; + /** + * @var \PHPUnit\Framework\MockObject\MockObject&\ILIAS\WOPI\Discovery\ActionRepository + */ private MockObject $action_repository; private CapabilityBuilder $capability_builder; @@ -54,24 +67,20 @@ protected function setUp(): void $this->file_info_repository = $this->createMock(\ilObjFileInfoRepository::class); $this->access = $this->createMock(\ilAccessHandler::class); - $ctrl = $this->createMock(\ilCtrlInterface::class); $this->action_repository = $this->createMock(ActionRepository::class); - $http = $this->createMock(Services::class); - $static_url = $this->createMock(URIBuilder::class); $this->type_resolver = $this->createMock(TypeResolver::class); - $this->workspace_access_handler = $this->createMock(ilWorkspaceAccessHandler::class); + $this->workspace_access_handler = $this->createStub(ilWorkspaceAccessHandler::class); $this->type_resolver->method('resolveTypeByObjectId') - ->withAnyParameters() ->willReturn('file'); $this->capability_builder = new CapabilityBuilder( $this->file_info_repository, $this->access, - $ctrl, + $this->createStub(\ilCtrlInterface::class), $this->action_repository, - $http, - $static_url, + $this->createStub(Services::class), + $this->createStub(URIBuilder::class), $this->type_resolver, $this->workspace_access_handler ); @@ -249,7 +258,7 @@ function (string $permission) use ($permissions): bool { $file_info->method('shouldDownloadDirectly') ->willReturn(!$infopage_first); - $this->file_info_repository->method('getByObjectId') + $this->file_info_repository->expects($this->atLeastOnce())->method('getByObjectId') ->with($context->getObjectId()) ->willReturn($file_info); diff --git a/components/ILIAS/File/tests/ilModulesFileTest.php b/components/ILIAS/File/tests/ilModulesFileTest.php index 8916b0b619ae..b82dc7c3a904 100755 --- a/components/ILIAS/File/tests/ilModulesFileTest.php +++ b/components/ILIAS/File/tests/ilModulesFileTest.php @@ -44,6 +44,9 @@ class ilModulesFileTest extends TestCase * @var ilDBInterface|MockObject */ protected ?MockObject $db_mock = null; + /** + * @var \PHPUnit\Framework\MockObject\MockObject&\ILIAS\ResourceStorage\Manager\Manager + */ protected MockObject $manager_mock; protected function setUp(): void @@ -185,7 +188,7 @@ function (string $id) use (&$consecutive): ?ResourceIdentification { ->with($rid) ->willReturn($revision); - $this->manager_mock + $this->manager_mock->expects($this->atLeastOnce()) ->method('getResource') ->with($rid) ->willReturn($resource); diff --git a/components/ILIAS/FileDelivery/tests/FileDeliveryTypes/FileDeliveryTypeFactoryTest.php b/components/ILIAS/FileDelivery/tests/FileDeliveryTypes/FileDeliveryTypeFactoryTest.php index 17ac9f670be3..93ec84bbc171 100755 --- a/components/ILIAS/FileDelivery/tests/FileDeliveryTypes/FileDeliveryTypeFactoryTest.php +++ b/components/ILIAS/FileDelivery/tests/FileDeliveryTypes/FileDeliveryTypeFactoryTest.php @@ -49,9 +49,7 @@ class FileDeliveryTypeFactoryTest extends TestCase protected function setUp(): void { parent::setUp(); - - $http = $this->getMockBuilder(Services::class)->disableOriginalConstructor()->getMock(); - $this->subject = new FileDeliveryTypeFactory($http); + $this->subject = new FileDeliveryTypeFactory($this->createStub(Services::class)); } diff --git a/components/ILIAS/FileDelivery/tests/FileDeliveryTypes/XAccelTest.php b/components/ILIAS/FileDelivery/tests/FileDeliveryTypes/XAccelTest.php index 731d884e4c2d..b59a3f0abe58 100755 --- a/components/ILIAS/FileDelivery/tests/FileDeliveryTypes/XAccelTest.php +++ b/components/ILIAS/FileDelivery/tests/FileDeliveryTypes/XAccelTest.php @@ -57,9 +57,7 @@ class XAccelTest extends TestCase */ protected function setUp(): void { - $this->httpServiceMock = $this->getMockBuilder(Services::class) - ->disableOriginalConstructor() - ->getMock(); + $this->httpServiceMock = $this->createMock(Services::class); } #[Test] @@ -67,9 +65,7 @@ public function testPrepareWhichShouldSucceed(): void { $expectedContentValue = ''; - $response = $this->getMockBuilder(ResponseInterface::class) - ->disableOriginalConstructor() - ->getMock(); + $response = $this->createMock(ResponseInterface::class); $response->expects($this->once()) ->method('withHeader') @@ -99,9 +95,7 @@ public function testDeliverWithNormalPathWhichShouldSucceed(): void $expectedHeader = 'X-Accel-Redirect'; $path = './normal/path'; - $response = $this->getMockBuilder(ResponseInterface::class) - ->disableOriginalConstructor() - ->getMock(); + $response = $this->createMock(ResponseInterface::class); $response->expects($this->once()) ->method('withHeader') @@ -131,9 +125,7 @@ public function testDeliverWithDataPathWhichShouldSucceed(): void $path = './data/path/to/what/ever'; $expectedPath = '/secured-data/path/to/what/ever'; - $response = $this->getMockBuilder(ResponseInterface::class) - ->disableOriginalConstructor() - ->getMock(); + $response = $this->createMock(ResponseInterface::class); $response->expects($this->once()) ->method('withHeader') diff --git a/components/ILIAS/FileDelivery/tests/FileDeliveryTypes/XSendfileTest.php b/components/ILIAS/FileDelivery/tests/FileDeliveryTypes/XSendfileTest.php index 388c91c30d57..adec05f053cb 100755 --- a/components/ILIAS/FileDelivery/tests/FileDeliveryTypes/XSendfileTest.php +++ b/components/ILIAS/FileDelivery/tests/FileDeliveryTypes/XSendfileTest.php @@ -51,9 +51,7 @@ class XSendfileTest extends TestCase */ protected function setUp(): void { - $this->httpServiceMock = $this->getMockBuilder(Services::class) - ->disableOriginalConstructor() - ->getMock(); + $this->httpServiceMock = $this->createMock(Services::class); } #[Test] @@ -62,9 +60,7 @@ public function testSendFileWithXSendHeaderWhichShouldSucceed(): void $expectedHeader = 'X-Sendfile'; $filePath = __FILE__; - $response = $this->getMockBuilder(ResponseInterface::class) - ->disableOriginalConstructor() - ->getMock(); + $response = $this->createMock(ResponseInterface::class); $response->expects($this->once()) ->method('withHeader') diff --git a/components/ILIAS/FileServices/tests/UploadPolicyResolverTest.php b/components/ILIAS/FileServices/tests/UploadPolicyResolverTest.php index 033c69ad799f..26f7309ae19e 100755 --- a/components/ILIAS/FileServices/tests/UploadPolicyResolverTest.php +++ b/components/ILIAS/FileServices/tests/UploadPolicyResolverTest.php @@ -27,8 +27,8 @@ class UploadPolicyResolverTest extends TestCase { public function testLimitedPolicy(): void { - $rbac_mock = $this->createMock(\ilRbacReview::class); - $user_mock = $this->createMock(\ilObjUser::class); + $rbac_mock = $this->createStub(\ilRbacReview::class); + $user_mock = $this->createStub(\ilObjUser::class); $general_policy = new \UploadPolicy( 1, @@ -94,8 +94,8 @@ public function testLimitedPolicy(): void public function testPolicyWithStartAndEndDate(): void { - $rbac_mock = $this->createMock(\ilRbacReview::class); - $user_mock = $this->createMock(\ilObjUser::class); + $rbac_mock = $this->createStub(\ilRbacReview::class); + $user_mock = $this->createStub(\ilObjUser::class); $running_policy = $this->buildPolicy( 'Running', diff --git a/components/ILIAS/FileServices/tests/ilServicesFileServicesTest.php b/components/ILIAS/FileServices/tests/ilServicesFileServicesTest.php index 5297fbae3a58..f76e410180f0 100755 --- a/components/ILIAS/FileServices/tests/ilServicesFileServicesTest.php +++ b/components/ILIAS/FileServices/tests/ilServicesFileServicesTest.php @@ -75,7 +75,7 @@ public function testBlacklistedUpload(): void ->method('isByPassAllowedForCurrentUser') ->willReturn(false); - $stream = $this->createMock(FileStream::class); + $stream = $this->createStub(FileStream::class); $meta = new Metadata('filename.pdf', 42, 'application/pdf'); $processor = new ilFileServicesPreProcessor( @@ -98,7 +98,7 @@ public function testBlacklistedUploadWithPermission(): void ->method('isByPassAllowedForCurrentUser') ->willReturn(true); - $stream = $this->createMock(FileStream::class); + $stream = $this->createStub(FileStream::class); $meta = new Metadata('filename.pdf', 42, 'application/pdf'); $processor = new ilFileServicesPreProcessor( @@ -130,7 +130,7 @@ public function testRenamingNonWhitelistedFile(): void public function testActualWhitelist(): void { $settings_mock = $this->createMock(ilSetting::class); - $ini_mock = $this->createMock(ilIniFile::class); + $ini_mock = $this->createStub(ilIniFile::class); $ref = new stdClass(); $ref->ref_id = 32; diff --git a/components/ILIAS/Filesystem/tests/Finder/FinderTest.php b/components/ILIAS/Filesystem/tests/Finder/FinderTest.php index 95b07854befb..2c513b31f889 100755 --- a/components/ILIAS/Filesystem/tests/Finder/FinderTest.php +++ b/components/ILIAS/Filesystem/tests/Finder/FinderTest.php @@ -33,7 +33,7 @@ class FinderTest extends TestCase { private function getFlatFileSystemStructure(): Filesystem\Filesystem&\PHPUnit\Framework\MockObject\MockObject { - $fileSystem = $this->getMockBuilder(Filesystem\Filesystem::class)->getMock(); + $fileSystem = $this->createMock(Filesystem\Filesystem::class); $metadata = [ new Filesystem\DTO\Metadata('file_1.txt', MetadataType::FILE), @@ -57,7 +57,7 @@ private function getFlatFileSystemStructure(): Filesystem\Filesystem&\PHPUnit\Fr private function getNestedFileSystemStructure(): Filesystem\Filesystem&\PHPUnit\Framework\MockObject\MockObject { - $fileSystem = $this->getMockBuilder(Filesystem\Filesystem::class)->getMock(); + $fileSystem = $this->createMock(Filesystem\Filesystem::class); $rootMetadata = [ new Filesystem\DTO\Metadata('file_1.txt', MetadataType::FILE), @@ -114,7 +114,7 @@ private function getNestedFileSystemStructure(): Filesystem\Filesystem&\PHPUnit\ */ private function getNestedFileSystemStructureWithAnUnlistableDirectory( ): Filesystem\Filesystem&\PHPUnit\Framework\MockObject\MockObject { - $fileSystem = $this->getMockBuilder(Filesystem\Filesystem::class)->getMock(); + $fileSystem = $this->createMock(Filesystem\Filesystem::class); $rootMetadata = [ new Filesystem\DTO\Metadata('file_1.txt', MetadataType::FILE), @@ -162,7 +162,7 @@ private function getNestedFileSystemStructureWithAnUnlistableDirectory( public function testFinderWillFindNoFilesOrFoldersInAnEmptyDirectory(): void { - $fileSystem = $this->getMockBuilder(Filesystem\Filesystem::class)->getMock(); + $fileSystem = $this->createMock(Filesystem\Filesystem::class); $fileSystem ->method('listContents') @@ -367,7 +367,7 @@ public function testFinderCanLimitTheResultSet(): void public function testFinderLimitRejectsNegativeValues(): void { - $fs = $this->getMockBuilder(Filesystem\Filesystem::class)->getMock(); + $fs = $this->createStub(Filesystem\Filesystem::class); $finder = (new Finder($fs))->in(['/']); $this->expectException(InvalidArgumentException::class); $finder->limit(-1); @@ -375,7 +375,7 @@ public function testFinderLimitRejectsNegativeValues(): void public function testFinderHasAnyDetectsMatchingAndMissingResults(): void { - $empty_fs = $this->getMockBuilder(Filesystem\Filesystem::class)->getMock(); + $empty_fs = $this->createMock(Filesystem\Filesystem::class); $empty_fs->method('listContents')->willReturn([]); $empty_finder = (new Finder($empty_fs))->in(['/']); $this->assertFalse($empty_finder->hasAny()); diff --git a/components/ILIAS/GlobalScreen/tests/MainMenu/FactoryImplTest.php b/components/ILIAS/GlobalScreen/tests/MainMenu/FactoryImplTest.php index 3a9274ec2a39..396f912ef476 100755 --- a/components/ILIAS/GlobalScreen/tests/MainMenu/FactoryImplTest.php +++ b/components/ILIAS/GlobalScreen/tests/MainMenu/FactoryImplTest.php @@ -38,7 +38,10 @@ class FactoryImplTest extends TestCase { protected IdentificationInterface $id; - protected StaticMainMenuProvider $provider; + /** + * @var \PHPUnit\Framework\MockObject\Stub&\ILIAS\GlobalScreen\Scope\MainMenu\Provider\StaticMainMenuProvider + */ + protected \PHPUnit\Framework\MockObject\Stub $provider; protected IdentificationFactory $identification; protected MainMenuItemFactory $factory; @@ -51,7 +54,7 @@ protected function setUp(): void parent::setUp(); $this->identification = new IdentificationFactory(new NullProviderFactory()); - $this->provider = $this->getMockBuilder(StaticMainMenuProvider::class)->getMock(); + $this->provider = $this->createStub(StaticMainMenuProvider::class); $this->id = $this->identification->core($this->provider)->identifier('dummy'); diff --git a/components/ILIAS/GlobalScreen/tests/Notification/BaseNotificationSetUpTBD.php b/components/ILIAS/GlobalScreen/tests/Notification/BaseNotificationSetUpTBD.php index 03d9ecba7368..4a33facd0a53 100644 --- a/components/ILIAS/GlobalScreen/tests/Notification/BaseNotificationSetUpTBD.php +++ b/components/ILIAS/GlobalScreen/tests/Notification/BaseNotificationSetUpTBD.php @@ -126,9 +126,9 @@ public function mainControls(): I\MainControls\Factory public function getDIC(): Container { $mocks = [ - 'ui' => $this->createMock(UIServices::class), - 'ui.factory' => $this->createMock(\ILIAS\UI\Factory::class), - 'provider_factory' => $this->createMock(ProviderFactory::class), + 'ui' => $this->createStub(UIServices::class), + 'ui.factory' => $this->createStub(\ILIAS\UI\Factory::class), + 'provider_factory' => $this->createStub(ProviderFactory::class), ]; return new class ($mocks) extends Container { public function globalScreen(): Services diff --git a/components/ILIAS/GlobalScreen/tests/Toast/BaseToastSetUp.php b/components/ILIAS/GlobalScreen/tests/Toast/BaseToastSetUp.php index 9c6aae664794..c9c8668703e4 100755 --- a/components/ILIAS/GlobalScreen/tests/Toast/BaseToastSetUp.php +++ b/components/ILIAS/GlobalScreen/tests/Toast/BaseToastSetUp.php @@ -44,19 +44,17 @@ abstract class BaseToastSetUp extends TestCase protected function setUp(): void { parent::setUp(); - - $ui_mock = $this->createMock(UIServices::class); $this->provider = $this->createMock(ToastProvider::class); $this->provider->method('getProviderNameForPresentation')->willReturn('Provider'); - $this->factory = (new ToastServices($ui_mock))->factory(); + $this->factory = (new ToastServices($this->createStub(UIServices::class)))->factory(); } public function getDIC(): Container { $mocks = [ - 'ui' => $this->createMock(UIServices::class), - 'ui.factory' => $this->createMock(Factory::class), - 'provider_factory' => $this->createMock(ProviderFactory::class), + 'ui' => $this->createStub(UIServices::class), + 'ui.factory' => $this->createStub(Factory::class), + 'provider_factory' => $this->createStub(ProviderFactory::class), ]; return new class ($mocks) extends Container { public function globalScreen(): Services diff --git a/components/ILIAS/GlobalScreen/tests/Toast/Collector/ToastCollectorTest.php b/components/ILIAS/GlobalScreen/tests/Toast/Collector/ToastCollectorTest.php index b46ecf4018d5..1694d88effb9 100755 --- a/components/ILIAS/GlobalScreen/tests/Toast/Collector/ToastCollectorTest.php +++ b/components/ILIAS/GlobalScreen/tests/Toast/Collector/ToastCollectorTest.php @@ -38,8 +38,8 @@ public function testGetToasts(): void $collector = new ToastCollector([$provider]); $this->assertSame([], $collector->getToasts()); - $id_one = $this->createMock(IdentificationInterface::class); - $id_two = $this->createMock(IdentificationInterface::class); + $id_one = $this->createStub(IdentificationInterface::class); + $id_two = $this->createStub(IdentificationInterface::class); $toast1 = $this->factory->standard( $id_one, diff --git a/components/ILIAS/GlobalScreen/tests/Toast/StandardToastTest.php b/components/ILIAS/GlobalScreen/tests/Toast/StandardToastTest.php index 312458615bde..1a3966ef423c 100755 --- a/components/ILIAS/GlobalScreen/tests/Toast/StandardToastTest.php +++ b/components/ILIAS/GlobalScreen/tests/Toast/StandardToastTest.php @@ -29,7 +29,7 @@ class StandardToastTest extends BaseToastSetUp { public function testStandardToast(): void { - $id = $this->createMock(IdentificationInterface::class); + $id = $this->createStub(IdentificationInterface::class); $standard_toast = $this->factory->standard( $id, @@ -80,7 +80,7 @@ public static function reservedActionsProvider(): \Iterator #[DataProvider('reservedActionsProvider')] public function testReservedActions(ToastAction $action): void { - $id = $this->createMock(IdentificationInterface::class); + $id = $this->createStub(IdentificationInterface::class); $standard_toast = $this->factory->standard( $id, diff --git a/components/ILIAS/GlobalScreen/tests/Toast/ToastServicesTest.php b/components/ILIAS/GlobalScreen/tests/Toast/ToastServicesTest.php index 1240da16c6ff..7ddbfa683546 100755 --- a/components/ILIAS/GlobalScreen/tests/Toast/ToastServicesTest.php +++ b/components/ILIAS/GlobalScreen/tests/Toast/ToastServicesTest.php @@ -29,7 +29,7 @@ class ToastServicesTest extends TestCase { public function testFactory(): void { - $ui_mock = $this->createMock(UIServices::class); + $ui_mock = $this->createStub(UIServices::class); $services = new ToastServices($ui_mock); $this->assertInstanceOf(ToastFactory::class, $services->factory()); diff --git a/components/ILIAS/GlobalScreen/tests/ilServicesGlobalScreenTest.php b/components/ILIAS/GlobalScreen/tests/ilServicesGlobalScreenTest.php index a900baaf10a5..2924c8143b85 100755 --- a/components/ILIAS/GlobalScreen/tests/ilServicesGlobalScreenTest.php +++ b/components/ILIAS/GlobalScreen/tests/ilServicesGlobalScreenTest.php @@ -37,6 +37,9 @@ protected function setUp(): void if (!defined('ROOT_FOLDER_ID')) { define('ROOT_FOLDER_ID', 24); } + if (!defined('ANONYMOUS_USER_ID')) { + define('ANONYMOUS_USER_ID', 13); + } $this->ROOT_FOLDER_ID = ROOT_FOLDER_ID; } diff --git a/components/ILIAS/HTTP/tests/Services/AbstractBaseTestCase.php b/components/ILIAS/HTTP/tests/Services/AbstractBaseTestCase.php index 035a57059925..36d314ba357d 100644 --- a/components/ILIAS/HTTP/tests/Services/AbstractBaseTestCase.php +++ b/components/ILIAS/HTTP/tests/Services/AbstractBaseTestCase.php @@ -31,7 +31,7 @@ abstract class AbstractBaseTestCase extends TestCase { /** - * @var MockObject|RequestInterface + * @var \PHPUnit\Framework\MockObject\MockObject&\Psr\Http\Message\ServerRequestInterface */ protected MockObject $request_interface; diff --git a/components/ILIAS/HTTP/tests/Services/SuperGlobalDropInReplacementTest.php b/components/ILIAS/HTTP/tests/Services/SuperGlobalDropInReplacementTest.php index b30e5a0465d1..12ed8aaa1b11 100755 --- a/components/ILIAS/HTTP/tests/Services/SuperGlobalDropInReplacementTest.php +++ b/components/ILIAS/HTTP/tests/Services/SuperGlobalDropInReplacementTest.php @@ -32,7 +32,7 @@ private function getRefinery(): Refinery { return new Refinery( new DataFactory(), - $this->getMockBuilder(ilLanguage::class)->disableOriginalConstructor()->getMock() + $this->createStub(ilLanguage::class) ); } diff --git a/components/ILIAS/HTTP/tests/Services/WrapperTest.php b/components/ILIAS/HTTP/tests/Services/WrapperTest.php index e41e3bc506de..413056622941 100755 --- a/components/ILIAS/HTTP/tests/Services/WrapperTest.php +++ b/components/ILIAS/HTTP/tests/Services/WrapperTest.php @@ -39,11 +39,8 @@ class WrapperTest extends AbstractBaseTestCase protected function setUp(): void { parent::setUp(); - $language = $this->getMockBuilder('\ilLanguage') - ->disableOriginalConstructor() - ->getMock(); - $this->refinery = new Factory(new \ILIAS\Data\Factory(), $language); + $this->refinery = new Factory(new \ILIAS\Data\Factory(), $this->createStub('\ilLanguage')); } diff --git a/components/ILIAS/Init/tests/InitCtrlServiceTest.php b/components/ILIAS/Init/tests/InitCtrlServiceTest.php index 38397a6e974b..1079e82444a7 100755 --- a/components/ILIAS/Init/tests/InitCtrlServiceTest.php +++ b/components/ILIAS/Init/tests/InitCtrlServiceTest.php @@ -35,7 +35,7 @@ public function testCtrlServiceInitializationWithoutRefinery(): void { $dic = new Container(); // $dic['ilDB'] = $this->createMock(ilDBInterface::class); - $dic['http'] = $this->createMock(HttpService::class); + $dic['http'] = $this->createStub(HttpService::class); $this->expectException(ilCtrlException::class); $this->expectExceptionMessage("Cannot initialize ilCtrl if Refinery Factory is not yet available."); @@ -46,7 +46,7 @@ public function testCtrlServiceInitializationWithoutHttpServices(): void { $dic = new Container(); // $dic['ilDB'] = $this->createMock(ilDBInterface::class); - $dic['refinery'] = $this->createMock(Refinery::class); + $dic['refinery'] = $this->createStub(Refinery::class); $this->expectException(ilCtrlException::class); $this->expectExceptionMessage("Cannot initialize ilCtrl if HTTP Services are not yet available."); @@ -67,16 +67,16 @@ public function testCtrlServiceInitializationWithoutHttpServices(): void public function testCtrlServiceInitializationSuccess(): void { $dic = new Container(); - $dic['refinery'] = $this->createMock(Refinery::class); + $dic['refinery'] = $this->createStub(Refinery::class); // $dic['ilDB'] = $this->createMock(ilDBInterface::class); - $dic['http.response_sender_strategy'] = $this->createMock(DefaultResponseSenderStrategy::class); - $dic['http'] = $this->createMock(HttpService::class); + $dic['http.response_sender_strategy'] = $this->createStub(DefaultResponseSenderStrategy::class); + $dic['http'] = $this->createStub(HttpService::class); $dic['http'] ->method('request') ->willReturn( - $this->createMock(ServerRequestInterface::class) + $this->createStub(ServerRequestInterface::class) ); - $dic['component.factory'] = $this->createMock(ilComponentFactory::class); + $dic['component.factory'] = $this->createStub(ilComponentFactory::class); $this->assertFalse(isset($dic['ilCtrl'])); diff --git a/components/ILIAS/MainMenu/tests/ilServicesMainMenuTest.php b/components/ILIAS/MainMenu/tests/ilServicesMainMenuTest.php index ae351a87ccea..da654470674f 100755 --- a/components/ILIAS/MainMenu/tests/ilServicesMainMenuTest.php +++ b/components/ILIAS/MainMenu/tests/ilServicesMainMenuTest.php @@ -65,8 +65,7 @@ protected function setUp(): void } $this->dic_backup = is_object($DIC) ? clone $DIC : $DIC; $this->dic_mock = $DIC = new Container(); - $provider_factory_mock = $this->createMock(ProviderFactory::class); - $gs_mock = $DIC['global_screen'] = new Services($provider_factory_mock); + $gs_mock = $DIC['global_screen'] = new Services($this->createStub(ProviderFactory::class)); $this->db_mock = $DIC['ilDB'] = $this->createMock(ilDBInterface::class); $this->dic_mock['ilUser'] = $DIC['ilUser'] = $this->createMock(ilObjUser::class); $this->dic_mock['ilSetting'] = $DIC['ilSetting'] = $this->createMock(ilSetting::class); @@ -86,7 +85,7 @@ protected function tearDown(): void /** @noinspection PhpArrayIndexImmediatelyRewrittenInspection */ public function testTypeHandlers(): void { - $provider = new CustomMainBarProvider($this->dic_mock, $this->createMock(ilMainMenuAccess::class)); + $provider = new CustomMainBarProvider($this->dic_mock, $this->createStub(ilMainMenuAccess::class)); $type_info = $provider->provideTypeInformation(); $this->assertInstanceOf(TypeInformationCollection::class, $type_info); @@ -127,8 +126,8 @@ public function testTypeHandlers(): void ); // RepositoryLink Item - $this->dic_mock['ilObjDataCache'] = $this->createMock(ilObjectDataCache::class); - $this->dic_mock['static_url'] = $this->createMock(\ILIAS\StaticURL\Services::class); + $this->dic_mock['ilObjDataCache'] = $this->createStub(ilObjectDataCache::class); + $this->dic_mock['static_url'] = $this->createStub(\ILIAS\StaticURL\Services::class); $item_type_info = $type_info->get(RepositoryLink::class); $renderer = $item_type_info->getRenderer(); $this->assertInstanceOf(ilMMRepositoryLinkItemRenderer::class, $renderer); @@ -141,8 +140,8 @@ public function testTypeHandlers(): void public function testStandardTopItems(): void { - $this->dic_mock['lng'] = $this->createMock(ilLanguage::class); - $this->dic_mock['tree'] = $this->createMock(ilTree::class); + $this->dic_mock['lng'] = $this->createStub(ilLanguage::class); + $this->dic_mock['tree'] = $this->createStub(ilTree::class); $standard_top_items = new StandardTopItemsProvider($this->dic_mock); $items = $standard_top_items->getStaticTopItems(); $item_identifications = array_map( diff --git a/components/ILIAS/OrgUnit/tests/ilModulesOrgUnitPermissionTest.php b/components/ILIAS/OrgUnit/tests/ilModulesOrgUnitPermissionTest.php index e0d60ef533f8..5c0bd32f79dd 100644 --- a/components/ILIAS/OrgUnit/tests/ilModulesOrgUnitPermissionTest.php +++ b/components/ILIAS/OrgUnit/tests/ilModulesOrgUnitPermissionTest.php @@ -41,8 +41,8 @@ public function testOrgUnitPermissionConstruction(): void public function testOrgUnitPermissionModification(): void { - $mock_operation = $this->createMock(ilOrgUnitOperation::class); - $mock_context = $this->createMock(ilOrgUnitOperationContext::class); + $mock_operation = $this->createStub(ilOrgUnitOperation::class); + $mock_context = $this->createStub(ilOrgUnitOperationContext::class); $permission = new ilOrgUnitPermission(666); $this->assertEquals(666, $permission->getId()); diff --git a/components/ILIAS/OrgUnit/tests/ilModulesOrgUnitTest.php b/components/ILIAS/OrgUnit/tests/ilModulesOrgUnitTest.php index 98f6766da727..2d18d94d66d4 100644 --- a/components/ILIAS/OrgUnit/tests/ilModulesOrgUnitTest.php +++ b/components/ILIAS/OrgUnit/tests/ilModulesOrgUnitTest.php @@ -35,7 +35,10 @@ class ilModulesOrgUnitTest extends TestCase * @var ilDBInterface|\PHPUnit\Framework\MockObject\MockObject */ protected $db_mock; - protected $manager_mock; + /** + * @var \PHPUnit\Framework\MockObject\Stub&\ILIAS\ResourceStorage\Manager\Manager + */ + protected \PHPUnit\Framework\MockObject\Stub $manager_mock; private PHPUnit\Framework\MockObject\MockObject $component_factory_mock; protected function setUp(): void @@ -45,9 +48,9 @@ protected function setUp(): void $DIC = new Container(); $DIC['resource_storage'] = $this->storage_mock = $this->createMock(Services::class); - $this->manager_mock = $this->createMock(Manager::class); + $this->manager_mock = $this->createStub(Manager::class); $DIC['ilUser'] = $this->createMock(ilObjUser::class); - $DIC['ilUser']->expects($this->any())->method('getPref')->willReturn('en'); + $DIC['ilUser']->method('getPref')->willReturn('en'); $DIC['ilDB'] = $this->db_mock = $this->createMock(ilDBInterface::class); $DIC['upload'] = $this->createMock(FileUpload::class); $DIC['ilias'] = $this->createMock(ILIAS::class); diff --git a/components/ILIAS/OrgUnit/tests/ilModulesOrgUnitTypeTest.php b/components/ILIAS/OrgUnit/tests/ilModulesOrgUnitTypeTest.php index 15cd22d74e8f..277031229376 100644 --- a/components/ILIAS/OrgUnit/tests/ilModulesOrgUnitTypeTest.php +++ b/components/ILIAS/OrgUnit/tests/ilModulesOrgUnitTypeTest.php @@ -44,28 +44,21 @@ class ilModulesOrgUnitTypeTest extends TestCase public function getRefinery(): \ILIAS\Refinery\Factory { $data_factory = new \ILIAS\Data\Factory(); - $language = $this->createMock(ilLanguage::class); - $refinery = new \ILIAS\Refinery\Factory($data_factory, $language); + $refinery = new \ILIAS\Refinery\Factory($data_factory, $this->createStub(ilLanguage::class)); return $refinery; } public function getUIFactory(): NoUIFactory { - $node_factory = $this->createMock(\ILIAS\UI\Implementation\Component\Input\Field\Node\Factory::class); - $language = $this->createMock(ilLanguage::class); - $filter_factory = $this->createMock(Component\Input\Container\Filter\Factory::class); - $view_control_factory = $this->createMock(Component\Input\Container\ViewControl\Factory::class); - $control_factory = $this->createMock(Component\Input\ViewControl\Factory::class); - $upload_limit_resolver = $this->createMock(Component\Input\UploadLimitResolver::class); $refinery = $this->getRefinery(); $factory = new class ( - $node_factory, - $language, - $filter_factory, - $view_control_factory, - $control_factory, - $upload_limit_resolver, + $this->createStub(\ILIAS\UI\Implementation\Component\Input\Field\Node\Factory::class), + $this->createStub(ilLanguage::class), + $this->createStub(Component\Input\Container\Filter\Factory::class), + $this->createStub(Component\Input\Container\ViewControl\Factory::class), + $this->createStub(Component\Input\ViewControl\Factory::class), + $this->createStub(Component\Input\UploadLimitResolver::class), $refinery ) extends NoUIFactory { public function __construct( @@ -140,7 +133,7 @@ public function testOrgUnitTypeGuiAMDForm(): void $gui = new mock_ilOrgUnitTypeGUI( $this->getRefinery(), $this->getUIFactory(), - $this->createMock(ilLanguage::class) + $this->createStub(ilLanguage::class) ); $form = $gui->mockGetAmdForm([$amdr1, $amdr2], $type); diff --git a/components/ILIAS/OrgUnit/tests/ilOrgUnitOperationContextRegisteredObjectiveTest.php b/components/ILIAS/OrgUnit/tests/ilOrgUnitOperationContextRegisteredObjectiveTest.php index 2ff801baf372..9144347e200c 100644 --- a/components/ILIAS/OrgUnit/tests/ilOrgUnitOperationContextRegisteredObjectiveTest.php +++ b/components/ILIAS/OrgUnit/tests/ilOrgUnitOperationContextRegisteredObjectiveTest.php @@ -48,7 +48,7 @@ protected function getMockEnviroment( } $env = $this->createMock(Environment::class); - $env + $env->expects($this->atLeastOnce()) ->method('getResource') ->with(Environment::RESOURCE_DATABASE) ->willReturn($db); @@ -101,11 +101,10 @@ protected function testGetHash(): void protected function testGetPreconditions(): void { - $env = $this->createMock(Environment::class); $obj = $this->getMockObjective(0, 0, $this->context); $this->assertContainsOnlyInstancesOf( ilDatabaseInitializedObjective::class, - $obj->getPreconditions($env) + $obj->getPreconditions($this->createStub(Environment::class)) ); } diff --git a/components/ILIAS/OrgUnit/tests/ilOrgUnitOperationRegisteredObjectiveTest.php b/components/ILIAS/OrgUnit/tests/ilOrgUnitOperationRegisteredObjectiveTest.php index 0fe942e30cfc..f437600b299b 100644 --- a/components/ILIAS/OrgUnit/tests/ilOrgUnitOperationRegisteredObjectiveTest.php +++ b/components/ILIAS/OrgUnit/tests/ilOrgUnitOperationRegisteredObjectiveTest.php @@ -51,7 +51,7 @@ protected function getMockEnviroment( } $env = $this->createMock(Environment::class); - $env + $env->expects($this->atLeastOnce()) ->method('getResource') ->with(Environment::RESOURCE_DATABASE) ->willReturn($db); @@ -72,11 +72,12 @@ protected function getMockObjective( ->onlyMethods(['getContextId', 'doesOperationExistInContext']) ->getMock(); - $obj + $obj->expects($this->atLeastOnce()) ->method('getContextId') ->with($this->isInstanceOf(ilDBInterface::class), 'context') ->willReturn($context_id); - $obj + // an unknown context (id 0) fails before the operation is looked up + $obj->expects($context_id === 0 ? $this->never() : $this->atLeastOnce()) ->method('doesOperationExistInContext') ->with($this->isInstanceOf(ilDBInterface::class), $context_id, $operation_name) ->willReturn($does_op_already_exist); @@ -96,11 +97,10 @@ protected function testGetHash(): void protected function testGetPreconditions(): void { - $env = $this->createMock(Environment::class); $obj = $this->getMockObjective(true, 0, $this->operation, ''); $this->assertContainsOnlyInstancesOf( ilDatabaseInitializedObjective::class, - $obj->getPreconditions($env) + $obj->getPreconditions($this->createStub(Environment::class)) ); } diff --git a/components/ILIAS/ResourceStorage/tests/AbstractBaseResourceBuilderTestCase.php b/components/ILIAS/ResourceStorage/tests/AbstractBaseResourceBuilderTestCase.php index 148b469bc786..6df1b1c20ed6 100644 --- a/components/ILIAS/ResourceStorage/tests/AbstractBaseResourceBuilderTestCase.php +++ b/components/ILIAS/ResourceStorage/tests/AbstractBaseResourceBuilderTestCase.php @@ -49,13 +49,16 @@ */ abstract class AbstractBaseResourceBuilderTestCase extends AbstractTestBase { + /** + * @var \PHPUnit\Framework\MockObject\MockObject&\ILIAS\ResourceStorage\Resource\Repository\FlavourRepository + */ public MockObject $flavour_repository; /** - * @var Revision|MockObject + * @var \PHPUnit\Framework\MockObject\MockObject&\ILIAS\ResourceStorage\Revision\Revision */ protected MockObject $revision; /** - * @var Information|MockObject + * @var \PHPUnit\Framework\MockObject\MockObject&\ILIAS\ResourceStorage\Information\Information */ protected MockObject $information; /** @@ -63,40 +66,41 @@ abstract class AbstractBaseResourceBuilderTestCase extends AbstractTestBase */ protected $upload_result; /** - * @var MockObject|InformationRepository + * @var \PHPUnit\Framework\MockObject\MockObject&\ILIAS\ResourceStorage\Information\Repository\InformationRepository */ protected MockObject $information_repository; /** - * @var MockObject|ResourceRepository + * @var \PHPUnit\Framework\MockObject\MockObject&\ILIAS\ResourceStorage\Resource\Repository\ResourceRepository */ protected MockObject $resource_repository; /** - * @var MockObject|CollectionRepository + * @var \PHPUnit\Framework\MockObject\MockObject&\ILIAS\ResourceStorage\Collection\Repository\CollectionRepository */ protected MockObject $collection_repository; /** - * @var MockObject|RevisionRepository + * @var \PHPUnit\Framework\MockObject\MockObject&\ILIAS\ResourceStorage\Revision\Repository\RevisionRepository */ protected MockObject $revision_repository; /** - * @var MockObject|StorageHandler + * @var \PHPUnit\Framework\MockObject\MockObject&\ILIAS\ResourceStorage\StorageHandler\StorageHandler */ protected MockObject $storage_handler; protected ResourceBuilder $resource_builder; /** - * @var StakeholderRepository|MockObject + * @var \PHPUnit\Framework\MockObject\MockObject&\ILIAS\ResourceStorage\Stakeholder\Repository\StakeholderRepository */ protected MockObject $stakeholder_repository; /** - * @var LockHandler|MockObject + * @var \PHPUnit\Framework\MockObject\MockObject&\ILIAS\ResourceStorage\Lock\LockHandler */ protected MockObject $locking; /** - * @var StorageHandlerFactory|MockObject + * @var \PHPUnit\Framework\MockObject\MockObject&\ILIAS\ResourceStorage\StorageHandler\StorageHandlerFactory */ protected MockObject $storage_handler_factory; /** * @var StreamAccess|\PHPUnit\Framework\MockObject\MockObject|StreamAccess&\PHPUnit\Framework\MockObject\MockObject + * @var \PHPUnit\Framework\MockObject\MockObject&\ILIAS\ResourceStorage\Consumer\StreamAccess\StreamAccess */ protected MockObject $stream_access; protected Repositories $repositories; diff --git a/components/ILIAS/ResourceStorage/tests/AbstractTestBase.php b/components/ILIAS/ResourceStorage/tests/AbstractTestBase.php index cbb9b6e3814b..21b2d06c547f 100644 --- a/components/ILIAS/ResourceStorage/tests/AbstractTestBase.php +++ b/components/ILIAS/ResourceStorage/tests/AbstractTestBase.php @@ -40,7 +40,7 @@ abstract class AbstractTestBase extends TestCase { protected DummyIDGenerator $id_generator; /** - * @var \ilDBInterface|mixed|MockObject + * @var \PHPUnit\Framework\MockObject\MockObject&\ilDBInterface */ protected MockObject $db_mock; @@ -51,7 +51,7 @@ protected function setUp(): void { parent::setUp(); $this->id_generator = new DummyIDGenerator(); - $this->db_mock = $this->getMockBuilder(\ilDBInterface::class)->getMock(); + $this->db_mock = $this->createMock(\ilDBInterface::class); } protected function getDummyUploadResult(string $file_name, string $mime_type, int $size): UploadResult diff --git a/components/ILIAS/ResourceStorage/tests/Collection/CollectionBuilderTest.php b/components/ILIAS/ResourceStorage/tests/Collection/CollectionBuilderTest.php index ea4588c45923..ec78b795cb89 100755 --- a/components/ILIAS/ResourceStorage/tests/Collection/CollectionBuilderTest.php +++ b/components/ILIAS/ResourceStorage/tests/Collection/CollectionBuilderTest.php @@ -57,7 +57,7 @@ protected function setUp(): void $this->collections = new Collections( $this->resource_builder = $this->createMock(ResourceBuilder::class), $collection_builder, - $this->createMock(RepositoryPreloader::class), + $this->createStub(RepositoryPreloader::class), new Subject() ); } diff --git a/components/ILIAS/ResourceStorage/tests/Collection/CollectionRepositoryTest.php b/components/ILIAS/ResourceStorage/tests/Collection/CollectionRepositoryTest.php index 0d78ce4cf95d..17229ada9a0d 100755 --- a/components/ILIAS/ResourceStorage/tests/Collection/CollectionRepositoryTest.php +++ b/components/ILIAS/ResourceStorage/tests/Collection/CollectionRepositoryTest.php @@ -37,6 +37,9 @@ class CollectionRepositoryTest extends TestCase { private const string TEST_RCID = 'test_rcid'; + /** + * @var \PHPUnit\Framework\MockObject\MockObject&\ilDBInterface + */ private MockObject $db_mock; private CollectionDBRepository $repo; private DummyIDGenerator $rcid_generator; diff --git a/components/ILIAS/ResourceStorage/tests/Collection/CollectionSortingTest.php b/components/ILIAS/ResourceStorage/tests/Collection/CollectionSortingTest.php index 031ca5e00e14..7bb32c5c42e3 100755 --- a/components/ILIAS/ResourceStorage/tests/Collection/CollectionSortingTest.php +++ b/components/ILIAS/ResourceStorage/tests/Collection/CollectionSortingTest.php @@ -40,11 +40,20 @@ class CollectionSortingTest extends AbstractBaseResourceBuilderTestCase protected CollectionIdentificationGenerator $rcid_generator; private ResourceIdentification $rid_one; + /** + * @var \PHPUnit\Framework\MockObject\MockObject&\ILIAS\ResourceStorage\Revision\Revision + */ private MockObject $revision_one; private ResourceIdentification $rid_two; + /** + * @var \PHPUnit\Framework\MockObject\MockObject&\ILIAS\ResourceStorage\Revision\Revision + */ private MockObject $revision_two; private Sorter $sorter; private ResourceIdentification $rid_three; + /** + * @var \PHPUnit\Framework\MockObject\MockObject&\ILIAS\ResourceStorage\Revision\Revision + */ private MockObject $revision_three; #[\Override] @@ -53,7 +62,6 @@ protected function setUp(): void parent::setUp(); $this->rcid_generator = new DummyIDGenerator(self::DUMMY_RCID); $this->resource_builder = $this->createMock(ResourceBuilder::class); - $collection_builder = $this->createMock(CollectionBuilder::class); $rcid = new ResourceCollectionIdentification(self::DUMMY_RCID); $collection = new ResourceCollection( $rcid, @@ -74,7 +82,7 @@ protected function setUp(): void $this->sorter = new Sorter( $this->resource_builder, - $collection_builder, + $this->createStub(CollectionBuilder::class), $collection ); diff --git a/components/ILIAS/ResourceStorage/tests/Collection/CollectionTest.php b/components/ILIAS/ResourceStorage/tests/Collection/CollectionTest.php index 3d963dff6e16..8457b28d71e3 100755 --- a/components/ILIAS/ResourceStorage/tests/Collection/CollectionTest.php +++ b/components/ILIAS/ResourceStorage/tests/Collection/CollectionTest.php @@ -42,8 +42,9 @@ class CollectionTest extends AbstractBaseResourceBuilderTestCase public $collection_builder; /** * @var \ILIAS\ResourceStorage\Preloader\RepositoryPreloader&\PHPUnit\Framework\MockObject\MockObject|mixed + * @var \PHPUnit\Framework\MockObject\Stub&\ILIAS\ResourceStorage\Preloader\RepositoryPreloader */ - public MockObject $preloader; + public \PHPUnit\Framework\MockObject\Stub $preloader; /** * @var Collections|mixed */ @@ -64,9 +65,7 @@ protected function setUp(): void $this->rcid_generator ); - $this->preloader = $this->getMockBuilder(RepositoryPreloader::class) - ->disableOriginalConstructor() - ->getMock(); + $this->preloader = $this->createStub(RepositoryPreloader::class); $this->resource_builder = new ResourceBuilder( $this->storage_handler_factory, @@ -86,7 +85,7 @@ protected function setUp(): void public function testCreateCollection(): void { $identifiation = $this->rcid_generator->getUniqueResourceCollectionIdentification(); - $this->collection_repository->method('blank')->with($identifiation)->willReturn( + $this->collection_repository->expects($this->atLeastOnce())->method('blank')->with($identifiation)->willReturn( new ResourceCollection($identifiation, -1, '') ); @@ -100,16 +99,12 @@ public function testCreateCollection(): void public function testGetCollectionOfUser(): void { $identifiation = $this->rcid_generator->getUniqueResourceCollectionIdentification(); - $this->collection_repository->method('blank')->with($identifiation)->willReturn( + $this->collection_repository->expects($this->atLeastOnce())->method('blank')->with($identifiation)->willReturn( new ResourceCollection($identifiation, 42, '') ); $id = $this->collections->id($identifiation->serialize()); - $this->collection_repository->method('getResourceIdStrings')->with($identifiation)->willReturn( - $this->arrayAsGenerator([]) - ); - $collection = $this->collections->get($id, 42); $this->assertInstanceOf(ResourceCollection::class, $collection); diff --git a/components/ILIAS/ResourceStorage/tests/Collections/View/UploadStorerTest.php b/components/ILIAS/ResourceStorage/tests/Collections/View/UploadStorerTest.php index 0b2139469aff..b4b0b21d3b9d 100644 --- a/components/ILIAS/ResourceStorage/tests/Collections/View/UploadStorerTest.php +++ b/components/ILIAS/ResourceStorage/tests/Collections/View/UploadStorerTest.php @@ -46,9 +46,9 @@ final class UploadStorerTest extends TestCase private Manager&MockObject $manage; private Collections&MockObject $collections; private ResourceCollection&MockObject $collection; - private ResourceStakeholder&MockObject $stakeholder; + private ResourceStakeholder&\PHPUnit\Framework\MockObject\Stub $stakeholder; private UploadResult $result; - private FileStream&MockObject $stream; + private FileStream&\PHPUnit\Framework\MockObject\Stub $stream; private UploadStorer $storer; protected function setUp(): void @@ -57,7 +57,7 @@ protected function setUp(): void $this->manage = $this->createMock(Manager::class); $this->collections = $this->createMock(Collections::class); $this->collection = $this->createMock(ResourceCollection::class); - $this->stakeholder = $this->createMock(ResourceStakeholder::class); + $this->stakeholder = $this->createStub(ResourceStakeholder::class); $this->result = new UploadResult( self::FILE_NAME, 123, @@ -66,7 +66,7 @@ protected function setUp(): void new ProcessingStatus(ProcessingStatus::OK, 'ok'), 'dummy/path' ); - $this->stream = $this->createMock(FileStream::class); + $this->stream = $this->createStub(FileStream::class); $this->storer = new UploadStorer($this->manage, $this->collections); } @@ -292,14 +292,14 @@ private function storeStream(OnDuplicate $on_duplicate): ?ResourceIdentification private function givenExistingResource(ResourceIdentification $existing_rid): void { - $this->collections->method('findIdentificationByNameIn') + $this->collections->expects($this->atLeastOnce())->method('findIdentificationByNameIn') ->with($this->collection, self::FILE_NAME) ->willReturn($existing_rid); } private function givenNoExistingResource(): void { - $this->collections->method('findIdentificationByNameIn') + $this->collections->expects($this->atLeastOnce())->method('findIdentificationByNameIn') ->with($this->collection, self::FILE_NAME) ->willReturn(null); } diff --git a/components/ILIAS/ResourceStorage/tests/Flavours/FlavourMachineTest.php b/components/ILIAS/ResourceStorage/tests/Flavours/FlavourMachineTest.php index f9343f305d7e..52a84f789db1 100755 --- a/components/ILIAS/ResourceStorage/tests/Flavours/FlavourMachineTest.php +++ b/components/ILIAS/ResourceStorage/tests/Flavours/FlavourMachineTest.php @@ -55,7 +55,7 @@ class FlavourMachineTest extends AbstractTestBase { /** - * @var \ILIAS\ResourceStorage\Flavour\Engine\Factory|MockObject + * @var \PHPUnit\Framework\MockObject\MockObject&\ILIAS\ResourceStorage\Flavour\Engine\Factory */ private MockObject $engine_factory_mock; diff --git a/components/ILIAS/ResourceStorage/tests/Flavours/FlavourTest.php b/components/ILIAS/ResourceStorage/tests/Flavours/FlavourTest.php index f8a7c0859dea..844fb4a2a45d 100755 --- a/components/ILIAS/ResourceStorage/tests/Flavours/FlavourTest.php +++ b/components/ILIAS/ResourceStorage/tests/Flavours/FlavourTest.php @@ -45,6 +45,9 @@ class FlavourTest extends AbstractTestBase { + /** + * @var \PHPUnit\Framework\MockObject\MockObject&\ILIAS\ResourceStorage\Resource\ResourceBuilder + */ public MockObject $resource_builder; private const string BASE_DIR = '/var'; private Factory $machine_factory; @@ -52,6 +55,9 @@ class FlavourTest extends AbstractTestBase * @var StorageHandlerFactory|MockObject */ protected $storage_handler_factory; + /** + * @var \PHPUnit\Framework\MockObject\MockObject&\ILIAS\ResourceStorage\Resource\Repository\FlavourRepository + */ private MockObject $flavour_repo; private StreamAccess $stream_access; @@ -190,7 +196,7 @@ public function testNewFlavour(): void $revision->expects($this->once()) ->method('getInformation') - ->willReturn($this->createMock(FileInformation::class)); + ->willReturn($this->createStub(FileInformation::class)); $stream = Streams::ofString('test'); diff --git a/components/ILIAS/ResourceStorage/tests/Revision/RevisionRepositoryTest.php b/components/ILIAS/ResourceStorage/tests/Revision/RevisionRepositoryTest.php index 927a15d74fc2..aee39cdf1b0a 100755 --- a/components/ILIAS/ResourceStorage/tests/Revision/RevisionRepositoryTest.php +++ b/components/ILIAS/ResourceStorage/tests/Revision/RevisionRepositoryTest.php @@ -38,7 +38,7 @@ class RevisionRepositoryTest extends AbstractTestBase */ public $resource; /** - * @var MockObject|InfoResolver + * @var \PHPUnit\Framework\MockObject\MockObject&\ILIAS\ResourceStorage\Resource\InfoResolver\InfoResolver */ private MockObject $info_resolver; diff --git a/components/ILIAS/ResourceStorage/tests/Stakeholder/StakeholderRepositoryTests.php b/components/ILIAS/ResourceStorage/tests/Stakeholder/StakeholderRepositoryTests.php index 29896bb806e0..849b532540c6 100755 --- a/components/ILIAS/ResourceStorage/tests/Stakeholder/StakeholderRepositoryTests.php +++ b/components/ILIAS/ResourceStorage/tests/Stakeholder/StakeholderRepositoryTests.php @@ -31,10 +31,6 @@ */ class StakeholderRepositoryTests extends AbstractTestBase { - public function __construct() - { - parent::__construct(static::class); - } protected StakeholderDBRepository $stakeholder_repository; protected ResourceIdentification $identification; diff --git a/components/ILIAS/ResourceStorage/tests/StorageHandler/DirectoryNestingTest.php b/components/ILIAS/ResourceStorage/tests/StorageHandler/DirectoryNestingTest.php index 6e17e0f7b601..32135d793485 100755 --- a/components/ILIAS/ResourceStorage/tests/StorageHandler/DirectoryNestingTest.php +++ b/components/ILIAS/ResourceStorage/tests/StorageHandler/DirectoryNestingTest.php @@ -39,15 +39,15 @@ class DirectoryNestingTest extends AbstractTestBase private const int NESTING_281474976710656 = 281_474_976_710_656; private const int COMBINATIONS = 16; // 0-9a-f /** - * @var Filesystem|MockObject + * @var \PHPUnit\Framework\MockObject\Stub&\ILIAS\Filesystem\Filesystem */ - protected MockObject $file_system_mock; + protected \PHPUnit\Framework\MockObject\Stub $file_system_mock; #[\Override] protected function setUp(): void { parent::setUp(); - $this->file_system_mock = $this->createMock(Filesystem::class); + $this->file_system_mock = $this->createStub(Filesystem::class); } private function withImplementation(StorageHandler $h, int $min, int $max): void diff --git a/components/ILIAS/Setup/tests/Agent/NullAgentTest.php b/components/ILIAS/Setup/tests/Agent/NullAgentTest.php index f9ba4b2c2414..b5268fe77736 100755 --- a/components/ILIAS/Setup/tests/Agent/NullAgentTest.php +++ b/components/ILIAS/Setup/tests/Agent/NullAgentTest.php @@ -27,14 +27,20 @@ class NullAgentTest extends TestCase { - protected \ILIAS\Refinery\Factory $refinery; - protected Metrics\Storage $storage; + /** + * @var \PHPUnit\Framework\MockObject\Stub&\ILIAS\Refinery\Factory + */ + protected \PHPUnit\Framework\MockObject\Stub $refinery; + /** + * @var \PHPUnit\Framework\MockObject\Stub&\ILIAS\Setup\Metrics\Storage + */ + protected \PHPUnit\Framework\MockObject\Stub $storage; protected NullAgent $agent; public function setUp(): void { - $this->refinery = $this->createMock(\ILIAS\Refinery\Factory::class); - $this->storage = $this->createMock(Metrics\Storage::class); + $this->refinery = $this->createStub(\ILIAS\Refinery\Factory::class); + $this->storage = $this->createStub(Metrics\Storage::class); $this->agent = new NullAgent($this->refinery); } diff --git a/components/ILIAS/Setup/tests/AgentCollectionTest.php b/components/ILIAS/Setup/tests/AgentCollectionTest.php index be2e0ec3339d..12be7414b581 100755 --- a/components/ILIAS/Setup/tests/AgentCollectionTest.php +++ b/components/ILIAS/Setup/tests/AgentCollectionTest.php @@ -35,7 +35,7 @@ class AgentCollectionTest extends TestCase public function testHasConfig(): void { - $refinery = new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class)); + $refinery = new Refinery($this->createStub(DataFactory::class), $this->createStub(\ilLanguage::class)); $c1 = $this->newAgent(); $c2 = $this->newAgent(); @@ -62,7 +62,7 @@ public function testHasConfig(): void public function testGetArrayToConfigTransformation(): void { - $refinery = new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class)); + $refinery = new Refinery($this->createStub(DataFactory::class), $this->createStub(\ilLanguage::class)); $c1 = $this->newAgent(); $c2 = $this->newAgent(); @@ -114,7 +114,7 @@ public function testGetArrayToConfigTransformation(): void public function testArrayToConfigTransformationAllowsUnsetFields(): void { - $refinery = new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class)); + $refinery = new Refinery($this->createStub(DataFactory::class), $this->createStub(\ilLanguage::class)); $c1 = $this->newAgent(); $c2 = $this->newAgent(); @@ -166,7 +166,7 @@ public function testArrayToConfigTransformationAllowsUnsetFields(): void public function testGetInstallObjective(): void { - $refinery = new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class)); + $refinery = new Refinery($this->createStub(DataFactory::class), $this->createStub(\ilLanguage::class)); $c1 = $this->newAgent(); $c2 = $this->newAgent(); @@ -207,8 +207,8 @@ public function testGetInstallObjective(): void public function testGetUpdateObjective(): void { - $refinery = new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class)); - $storage = $this->createMock(Setup\Metrics\Storage::class); + $refinery = new Refinery($this->createStub(DataFactory::class), $this->createStub(\ilLanguage::class)); + $storage = $this->createStub(Setup\Metrics\Storage::class); $c1 = $this->newAgent(); $c2 = $this->newAgent(); @@ -241,7 +241,7 @@ public function testGetUpdateObjective(): void public function testGetCollectMetricsObjective(): void { - $refinery = new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class)); + $refinery = new Refinery($this->createStub(DataFactory::class), $this->createStub(\ilLanguage::class)); $c1 = $this->newAgent(); $c2 = $this->newAgent(); @@ -273,7 +273,7 @@ public function testGetCollectMetricsObjective(): void public function testGetAgent(): void { - $refinery = $this->createMock(Refinery::class); + $refinery = $this->createStub(Refinery::class); $c1 = $this->newAgent(); $c2 = $this->newAgent(); @@ -294,7 +294,7 @@ public function testGetAgent(): void public function testWithRemovedAgent(): void { - $refinery = $this->createMock(Refinery::class); + $refinery = $this->createStub(Refinery::class); $c1 = $this->newAgent(); $c2 = $this->newAgent(); @@ -324,7 +324,7 @@ public function testWithRemovedAgent(): void public function testWithAdditionalAgent(): void { - $refinery = $this->createMock(Refinery::class); + $refinery = $this->createStub(Refinery::class); $c1 = $this->newAgent(); $c2 = $this->newAgent(); @@ -354,7 +354,7 @@ public function testWithAdditionalAgent(): void public function testGetNamedObjectivesSorting(): void { - $refinery = $this->createMock(Refinery::class); + $refinery = $this->createStub(Refinery::class); $config = new Setup\ConfigCollection([]); $aAgent = $this->newAgent(); @@ -427,7 +427,7 @@ public function testGetNamedObjectivesSorting(): void public function testGetNamedObjectives(): void { - $refinery = $this->createMock(Refinery::class); + $refinery = $this->createStub(Refinery::class); $config = new Setup\ConfigCollection([]); $aAgent = $this->newAgent(); @@ -467,7 +467,7 @@ public function testGetNamedObjectives(): void public function testGetNamedObjectivePassesCorrectConfig() { - $refinery = $this->createMock(Refinery::class); + $refinery = $this->createStub(Refinery::class); $agent = $this->newAgent(); $seen_config = null; @@ -483,7 +483,7 @@ public function testGetNamedObjectivePassesCorrectConfig() ["agent" => $agent] ); - $agent_config = $this->createMock(Setup\Config::class); + $agent_config = $this->createStub(Setup\Config::class); $config = new Setup\ConfigCollection( ["agent" => $agent_config] ); @@ -495,7 +495,7 @@ public function testGetNamedObjectivePassesCorrectConfig() public function testGetAgents(): void { - $refinery = $this->createMock(Refinery::class); + $refinery = $this->createStub(Refinery::class); $c1 = $this->newAgent(); $c2 = $this->newAgent(); diff --git a/components/ILIAS/Setup/tests/Artifact/BuildArtifactObjectiveTest.php b/components/ILIAS/Setup/tests/Artifact/BuildArtifactObjectiveTest.php index daa8cf02d737..56d8d7d7b3c3 100755 --- a/components/ILIAS/Setup/tests/Artifact/BuildArtifactObjectiveTest.php +++ b/components/ILIAS/Setup/tests/Artifact/BuildArtifactObjectiveTest.php @@ -29,7 +29,10 @@ class BuildArtifactObjectiveTest extends TestCase protected \PHPUnit\Framework\MockObject\MockObject $o; protected Artifact $artifact; - protected Setup\Environment $env; + /** + * @var \PHPUnit\Framework\MockObject\Stub&\ILIAS\Setup\Environment + */ + protected \PHPUnit\Framework\MockObject\Stub $env; public function setUp(): void { @@ -39,7 +42,7 @@ public function setUp(): void ->getMock(); $this->artifact = $this->createMock(Setup\Artifact::class); - $this->env = $this->createMock(Setup\Environment::class); + $this->env = $this->createStub(Setup\Environment::class); } public function testBuildInDefaultsToBuild(): void diff --git a/components/ILIAS/Setup/tests/CLI/AchieveCommandTest.php b/components/ILIAS/Setup/tests/CLI/AchieveCommandTest.php index b27ca9000bfc..1fbb6890240e 100755 --- a/components/ILIAS/Setup/tests/CLI/AchieveCommandTest.php +++ b/components/ILIAS/Setup/tests/CLI/AchieveCommandTest.php @@ -63,14 +63,14 @@ public function readAgentConfig(Agent $agent, InputInterface $input, ?string $us class AchieveCommandTest extends TestCase { /** - * @var Setup\CLI\ConfigReader|\PHPUnit\Framework\MockObject\MockObject + * @var \PHPUnit\Framework\MockObject\Stub&\ILIAS\Setup\CLI\ConfigReader */ - protected $config_reader; + protected \PHPUnit\Framework\MockObject\Stub $config_reader; /** - * @var Setup\AgentFinder|\PHPUnit\Framework\MockObject\MockObject + * @var \PHPUnit\Framework\MockObject\Stub&\ILIAS\Setup\AgentFinder */ - protected $agent_finder; + protected \PHPUnit\Framework\MockObject\Stub $agent_finder; /** * @var Refinery @@ -84,15 +84,15 @@ class AchieveCommandTest extends TestCase public function setUp(): void { - $this->config_reader = $this->createMock(Setup\CLI\ConfigReader::class); - $this->agent_finder = $this->createMock(Setup\AgentFinder::class); - $this->refinery = new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class)); + $this->config_reader = $this->createStub(Setup\CLI\ConfigReader::class); + $this->agent_finder = $this->createStub(Setup\AgentFinder::class); + $this->refinery = new Refinery($this->createStub(DataFactory::class), $this->createStub(\ilLanguage::class)); $this->command = new Setup\CLI\AchieveCommand($this->agent_finder, $this->config_reader, [], $this->refinery); } public function testBasicFunctionality(): void { - $refinery = new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class)); + $refinery = new Refinery($this->createStub(DataFactory::class), $this->createStub(\ilLanguage::class)); $agent = $this->createMock(Setup\AgentCollection::class); $config_reader = $this->createMock(Setup\CLI\ConfigReader::class); @@ -101,13 +101,13 @@ public function testBasicFunctionality(): void $tester = new CommandTester($command); - $config = $this->createMock(Setup\ConfigCollection::class); + $config = $this->createStub(Setup\ConfigCollection::class); $config_file = "config_file"; $config_file_content = ["config_file"]; $objective_name = "my.objective"; $objective = $this->createMock(Setup\Objective::class); - $env = $this->createMock(Setup\Environment::class); + $env = $this->createStub(Setup\Environment::class); $config_reader ->expects($this->once()) @@ -175,7 +175,7 @@ static function () use ($objective): Setup\Objective { public function testAchieveObjective(): void { - $refinery = new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class)); + $refinery = new Refinery($this->createStub(DataFactory::class), $this->createStub(\ilLanguage::class)); $agent = $this->createMock(Setup\AgentCollection::class); $config_reader = $this->createMock(Setup\CLI\ConfigReader::class); @@ -184,13 +184,13 @@ public function testAchieveObjective(): void $tester = new CommandTester($command); - $config = $this->createMock(Setup\ConfigCollection::class); + $config = $this->createStub(Setup\ConfigCollection::class); $config_file = "config_file"; $config_file_content = ["config_file"]; $objective_name = "my.objective"; $objective = $this->createMock(Setup\Objective::class); - $env = $this->createMock(Setup\Environment::class); + $env = $this->createStub(Setup\Environment::class); $config_reader ->expects($this->once()) diff --git a/components/ILIAS/Setup/tests/CLI/HasAgentTest.php b/components/ILIAS/Setup/tests/CLI/HasAgentTest.php index c9b5b446c31b..b1b812ca11cd 100755 --- a/components/ILIAS/Setup/tests/CLI/HasAgentTest.php +++ b/components/ILIAS/Setup/tests/CLI/HasAgentTest.php @@ -51,7 +51,7 @@ public function _getRelevantAgent($i) public function testGetRelevantAgentWithoutOption(): void { $ii = $this->createMock(InputInterface::class); - $ac = $this->createMock(AgentCollection::class); + $ac = $this->createStub(AgentCollection::class); $ii ->method("getOption") @@ -71,7 +71,7 @@ public function testGetRelevantAgentWithoutOption(): void public function testGetRelevantAgentWithNoPluginOption(): void { $ii = $this->createMock(InputInterface::class); - $ac = $this->createMock(AgentCollection::class); + $ac = $this->createStub(AgentCollection::class); $ii ->method("hasOption") @@ -98,7 +98,7 @@ public function testGetRelevantAgentWithNoPluginOption(): void public function testGetRelevantAgentWithPluginNameOptions(): void { $ii = $this->createMock(InputInterface::class); - $ac = $this->createMock(AgentCollection::class); + $ac = $this->createStub(AgentCollection::class); $ii diff --git a/components/ILIAS/Setup/tests/CLI/HasConfigReaderTest.php b/components/ILIAS/Setup/tests/CLI/HasConfigReaderTest.php index ce2b7bb84c02..3184f69ff360 100755 --- a/components/ILIAS/Setup/tests/CLI/HasConfigReaderTest.php +++ b/components/ILIAS/Setup/tests/CLI/HasConfigReaderTest.php @@ -27,12 +27,15 @@ class HasConfigReaderTest extends TestCase { - protected ConfigReader $config_reader; + /** + * @var \PHPUnit\Framework\MockObject\Stub&\ILIAS\Setup\CLI\ConfigReader + */ + protected \PHPUnit\Framework\MockObject\Stub $config_reader; protected $has_config_reader; public function setUp(): void { - $this->config_reader = $this->createMock(ConfigReader::class); + $this->config_reader = $this->createStub(ConfigReader::class); $this->has_config_reader = new class ($this->config_reader) { use HasConfigReader; public function __construct($cr) @@ -50,7 +53,7 @@ public function _readAgentConfig(Agent $agent, InputInterface $input, ?string $u public function testReadAgentConfigWithoutConfig() { $agent = $this->createMock(Agent::class); - $ii = $this->createMock(InputInterface::class); + $ii = $this->createStub(InputInterface::class); $agent ->method("hasConfig") diff --git a/components/ILIAS/Setup/tests/CLI/InstallCommandTest.php b/components/ILIAS/Setup/tests/CLI/InstallCommandTest.php index 13dc0219ad36..3780f97369ac 100755 --- a/components/ILIAS/Setup/tests/CLI/InstallCommandTest.php +++ b/components/ILIAS/Setup/tests/CLI/InstallCommandTest.php @@ -40,7 +40,7 @@ public function testBasicFunctionalityAlreadyAchieved(): void public function basicFunctionality(bool $is_applicable): void { - $refinery = new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class)); + $refinery = new Refinery($this->createStub(DataFactory::class), $this->createStub(\ilLanguage::class)); $agent = $this->createMock(Setup\AgentCollection::class); $config_reader = $this->createMock(Setup\CLI\ConfigReader::class); @@ -54,7 +54,6 @@ public function basicFunctionality(bool $is_applicable): void $config_file_content = ["config_file"]; $objective = $this->createMock(Setup\Objective::class); - $env = $this->createMock(Setup\Environment::class); $config_overwrites = [ "a.b.c" => "foo", @@ -132,7 +131,7 @@ public function getClientId(): string $objective ->expects($expects) ->method("achieve") - ->willReturn($env); + ->willReturn($this->createStub(Setup\Environment::class)); $objective ->expects($this->once()) @@ -148,14 +147,14 @@ public function getClientId(): string public function testPluginInstallation(): void { $agent = $this->createMock(Setup\AgentCollection::class); - $config_reader = $this->createMock(Setup\CLI\ConfigReader::class); + $config_reader = $this->createStub(Setup\CLI\ConfigReader::class); $agent_finder = $this->createMock(Setup\AgentFinder::class); $command = new Setup\CLI\InstallCommand($agent_finder, $config_reader, []); $tester = new CommandTester($command); $objective = $this->createMock(Setup\Objective::class); - $env = $this->createMock(Setup\Environment::class); + $env = $this->createStub(Setup\Environment::class); $agent ->expects($this->once()) diff --git a/components/ILIAS/Setup/tests/CLI/StatusCommandTest.php b/components/ILIAS/Setup/tests/CLI/StatusCommandTest.php index 935d9c55bd5d..1c9eb729c09b 100755 --- a/components/ILIAS/Setup/tests/CLI/StatusCommandTest.php +++ b/components/ILIAS/Setup/tests/CLI/StatusCommandTest.php @@ -31,10 +31,10 @@ class StatusCommandTest extends TestCase { public function testMetrics(): void { - $agent_finder = $this->createMock(Setup\AgentFinder::class); + $agent_finder = $this->createStub(Setup\AgentFinder::class); $obj = new Setup\CLI\StatusCommand($agent_finder); $storage = new Metrics\ArrayStorage(); - $objective = $this->createMock(Setup\Objective::class); + $objective = $this->createStub(Setup\Objective::class); $agent = $this->createMock(Setup\AgentCollection::class); $expected = new M(M::STABILITY_MIXED, M::TYPE_COLLECTION, []); diff --git a/components/ILIAS/Setup/tests/CLI/UpdateCommandTest.php b/components/ILIAS/Setup/tests/CLI/UpdateCommandTest.php index 4961a7e4eeec..91b6f0ef010a 100755 --- a/components/ILIAS/Setup/tests/CLI/UpdateCommandTest.php +++ b/components/ILIAS/Setup/tests/CLI/UpdateCommandTest.php @@ -39,7 +39,7 @@ public function testBasicFunctionalityAlreadyAchieved(): void } public function basicFunctionality(bool $is_applicable): void { - $refinery = new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class)); + $refinery = new Refinery($this->createStub(DataFactory::class), $this->createStub(\ilLanguage::class)); $agent = $this->createMock(Setup\AgentCollection::class); $config_reader = $this->createMock(Setup\CLI\ConfigReader::class); @@ -53,7 +53,6 @@ public function basicFunctionality(bool $is_applicable): void $config_file_content = ["config_file"]; $objective = $this->createMock(Setup\Objective::class); - $env = $this->createMock(Setup\Environment::class); $config_reader ->expects($this->once()) @@ -115,7 +114,7 @@ public function basicFunctionality(bool $is_applicable): void $objective ->expects($expects) ->method("achieve") - ->willReturn($env); + ->willReturn($this->createStub(Setup\Environment::class)); $objective ->expects($this->once()) diff --git a/components/ILIAS/Setup/tests/Condition/ExternalConditionObjectiveTest.php b/components/ILIAS/Setup/tests/Condition/ExternalConditionObjectiveTest.php index 8727e20afcdd..34fcaefc9717 100755 --- a/components/ILIAS/Setup/tests/Condition/ExternalConditionObjectiveTest.php +++ b/components/ILIAS/Setup/tests/Condition/ExternalConditionObjectiveTest.php @@ -73,7 +73,7 @@ public function testIsNotable(): void public function testGetPreconditions(): void { - $env = $this->createMock(Setup\Environment::class); + $env = $this->createStub(Setup\Environment::class); $pre = $this->f->getPreconditions($env); $this->assertEquals([], $pre); @@ -82,20 +82,20 @@ public function testGetPreconditions(): void public function testAchieveFalse(): void { $this->expectException(Setup\UnachievableException::class); - $env = $this->createMock(Setup\Environment::class); + $env = $this->createStub(Setup\Environment::class); $this->f->achieve($env); } public function testAchieveTrue(): void { - $env = $this->createMock(Setup\Environment::class); + $env = $this->createStub(Setup\Environment::class); $res = $this->t->achieve($env); $this->assertEquals($env, $res); } public function testNotExecutable(): void { - $env = $this->createMock(Setup\Environment::class); + $env = $this->createStub(Setup\Environment::class); $throws_not_executable = new Condition\ExternalConditionObjective( "Not executable", @@ -112,7 +112,7 @@ function (Setup\Environment $e) { public function testUnachievable(): void { - $env = $this->createMock(Setup\Environment::class); + $env = $this->createStub(Setup\Environment::class); $throws_unachievable = new Condition\ExternalConditionObjective( "Unachievable", diff --git a/components/ILIAS/Setup/tests/Objective/AdminConfirmedObjectiveTest.php b/components/ILIAS/Setup/tests/Objective/AdminConfirmedObjectiveTest.php index 0c0878b21a8c..09482d7ea701 100755 --- a/components/ILIAS/Setup/tests/Objective/AdminConfirmedObjectiveTest.php +++ b/components/ILIAS/Setup/tests/Objective/AdminConfirmedObjectiveTest.php @@ -58,7 +58,7 @@ public function testIsNotable(): void public function testGetPreconditions(): void { - $env = $this->createMock(Setup\Environment::class); + $env = $this->createStub(Setup\Environment::class); $pre = $this->o->getPreconditions($env); $this->assertEquals([], $pre); diff --git a/components/ILIAS/Setup/tests/Objective/CallableObjectiveTest.php b/components/ILIAS/Setup/tests/Objective/CallableObjectiveTest.php index e2578ff31fdd..3caa7da60a05 100755 --- a/components/ILIAS/Setup/tests/Objective/CallableObjectiveTest.php +++ b/components/ILIAS/Setup/tests/Objective/CallableObjectiveTest.php @@ -72,7 +72,7 @@ public function testIsNotable(): void public function testGetPreconditions(): void { - $env = $this->createMock(Setup\Environment::class); + $env = $this->createStub(Setup\Environment::class); $pre = $this->o->getPreconditions($env); $this->assertEquals([$this->p], $pre); @@ -83,7 +83,7 @@ public function testAchieve(): void { $this->env = null; - $env = $this->createMock(Setup\Environment::class); + $env = $this->createStub(Setup\Environment::class); $res = $this->o->achieve($env); $this->assertSame($env, $res); diff --git a/components/ILIAS/Setup/tests/Objective/ClientIdReadObjectiveTest.php b/components/ILIAS/Setup/tests/Objective/ClientIdReadObjectiveTest.php index c7c3e144cc3d..c99d8a691c35 100755 --- a/components/ILIAS/Setup/tests/Objective/ClientIdReadObjectiveTest.php +++ b/components/ILIAS/Setup/tests/Objective/ClientIdReadObjectiveTest.php @@ -55,7 +55,7 @@ public function testIsNotable(): void public function testGetPreconditions(): void { - $env = $this->createMock(Setup\Environment::class); + $env = $this->createStub(Setup\Environment::class); $pre = $this->o->getPreconditions($env); $this->assertEquals([], $pre); diff --git a/components/ILIAS/Setup/tests/Objective/NullObjectiveTest.php b/components/ILIAS/Setup/tests/Objective/NullObjectiveTest.php index 7d28484d36d3..745bca0b07ff 100755 --- a/components/ILIAS/Setup/tests/Objective/NullObjectiveTest.php +++ b/components/ILIAS/Setup/tests/Objective/NullObjectiveTest.php @@ -50,7 +50,7 @@ public function testIsNotable(): void public function testGetPreconditions(): void { - $env = $this->createMock(Setup\Environment::class); + $env = $this->createStub(Setup\Environment::class); $pre = $this->o->getPreconditions($env); $this->assertEquals([], $pre); @@ -58,7 +58,7 @@ public function testGetPreconditions(): void public function testAchieve(): void { - $env = $this->createMock(Setup\Environment::class); + $env = $this->createStub(Setup\Environment::class); $res = $this->o->achieve($env); $this->assertSame($env, $res); diff --git a/components/ILIAS/Setup/tests/Objective/ObjectiveWithPreconditionsTest.php b/components/ILIAS/Setup/tests/Objective/ObjectiveWithPreconditionsTest.php index e84b022ef6e1..ca31958b86df 100755 --- a/components/ILIAS/Setup/tests/Objective/ObjectiveWithPreconditionsTest.php +++ b/components/ILIAS/Setup/tests/Objective/ObjectiveWithPreconditionsTest.php @@ -81,7 +81,7 @@ public function testGetPreconditions(): void { $another = $this->newObjective(); - $env = $this->createMock(Setup\Environment::class); + $env = $this->createStub(Setup\Environment::class); $this->objective ->expects($this->once()) @@ -96,7 +96,7 @@ public function testGetPreconditions(): void public function testAchieve(): void { - $env = $this->createMock(Setup\Environment::class); + $env = $this->createStub(Setup\Environment::class); $this->objective ->expects($this->once()) diff --git a/components/ILIAS/Setup/tests/Objective/TentativelyTest.php b/components/ILIAS/Setup/tests/Objective/TentativelyTest.php index 6d01897c9710..7099f42dcce5 100755 --- a/components/ILIAS/Setup/tests/Objective/TentativelyTest.php +++ b/components/ILIAS/Setup/tests/Objective/TentativelyTest.php @@ -105,7 +105,7 @@ public function testGetPreconditions(): void { $other = $this->newObjective(); - $env = $this->createMock(Setup\Environment::class); + $env = $this->createStub(Setup\Environment::class); $this->objective ->expects($this->once()) @@ -121,7 +121,7 @@ public function testGetPreconditions(): void public function testAchieve(): void { - $env = $this->createMock(Setup\Environment::class); + $env = $this->createStub(Setup\Environment::class); $this->objective ->expects($this->once()) @@ -135,7 +135,7 @@ public function testAchieve(): void public function testAchieveThrows(): void { - $env = $this->createMock(Setup\Environment::class); + $env = $this->createStub(Setup\Environment::class); $this->objective ->expects($this->once()) @@ -149,7 +149,7 @@ public function testAchieveThrows(): void public function testIsApplicable(): void { - $env = $this->createMock(Setup\Environment::class); + $env = $this->createStub(Setup\Environment::class); $is_applicable = random_int(0, 1) == 1; $this->objective diff --git a/components/ILIAS/Setup/tests/ObjectiveCollectionTest.php b/components/ILIAS/Setup/tests/ObjectiveCollectionTest.php index e84f07380324..4b6db2ce58c7 100755 --- a/components/ILIAS/Setup/tests/ObjectiveCollectionTest.php +++ b/components/ILIAS/Setup/tests/ObjectiveCollectionTest.php @@ -81,7 +81,7 @@ public function testGetPreconditions(): void $c = new Setup\ObjectiveCollection("", false, $g1, $g2, $g3); - $env = $this->createMock(Setup\Environment::class); + $env = $this->createStub(Setup\Environment::class); $pre = $c->getPreconditions($env); $this->assertEquals([$g1,$g2, $g3], $pre); @@ -96,7 +96,7 @@ public function testAchieve(): void $c = new Setup\ObjectiveCollection("", false, $g1, $g2, $g3); - $env = $this->createMock(Setup\Environment::class); + $env = $this->createStub(Setup\Environment::class); foreach ([$g1,$g2,$g3] as $g) { $g diff --git a/components/ILIAS/Setup/tests/ObjectiveIteratorTest.php b/components/ILIAS/Setup/tests/ObjectiveIteratorTest.php index ce556db7938a..ea9558577068 100755 --- a/components/ILIAS/Setup/tests/ObjectiveIteratorTest.php +++ b/components/ILIAS/Setup/tests/ObjectiveIteratorTest.php @@ -30,7 +30,7 @@ public function testBasicAlgorithm(): void { $hash = "my hash"; $objective = $this->newObjective($hash); - $environment = $this->createMock(Setup\Environment::class); + $environment = $this->createStub(Setup\Environment::class); $objective ->expects($this->once()) @@ -53,7 +53,7 @@ public function testRewind(): void { $hash = "my hash"; $objective = $this->newObjective($hash); - $environment = $this->createMock(Setup\Environment::class); + $environment = $this->createStub(Setup\Environment::class); $iterator = new Setup\ObjectiveIterator($environment, $objective); @@ -73,29 +73,29 @@ public function testRewind(): void public function testAllObjectives(): void { - $environment = $this->createMock(Setup\Environment::class); + $environment = $this->createStub(Setup\Environment::class); $objective1 = $this->newObjective(); $objective11 = $this->newObjective(); $objective12 = $this->newObjective(); $objective121 = $this->newObjective(); - $objective1 + $objective1->expects($this->atLeastOnce()) ->method("getPreconditions") ->with($environment) ->willReturn([$objective11, $objective12]); - $objective11 + $objective11->expects($this->atLeastOnce()) ->method("getPreconditions") ->with($environment) ->willReturn([]); - $objective12 + $objective12->expects($this->atLeastOnce()) ->method("getPreconditions") ->with($environment) ->willReturn([$objective121]); - $objective121 + $objective121->expects($this->atLeastOnce()) ->method("getPreconditions") ->with($environment) ->willReturn([]); @@ -114,17 +114,17 @@ public function testAllObjectives(): void public function testAllObjectivesOnlyReturnsObjectiveOnce(): void { - $environment = $this->createMock(Setup\Environment::class); + $environment = $this->createStub(Setup\Environment::class); $objective1 = $this->newObjective(); $objective11 = $this->newObjective(); - $objective1 + $objective1->expects($this->atLeastOnce()) ->method("getPreconditions") ->with($environment) ->willReturn([$objective11, $objective11]); - $objective11 + $objective11->expects($this->atLeastOnce()) ->method("getPreconditions") ->with($environment) ->willReturn([]); @@ -140,17 +140,17 @@ public function testAllObjectivesOnlyReturnsObjectiveOnce(): void public function testAllObjectivesDetectsCycle(): void { - $environment = $this->createMock(Setup\Environment::class); + $environment = $this->createStub(Setup\Environment::class); $objective1 = $this->newObjective(); $objective2 = $this->newObjective(); - $objective1 + $objective1->expects($this->atLeastOnce()) ->method("getPreconditions") ->with($environment) ->willReturn([$objective2]); - $objective2 + $objective2->expects($this->atLeastOnce()) ->method("getPreconditions") ->with($environment) ->willReturn([$objective1]); diff --git a/components/ILIAS/Setup/tests/ilCommonSetupAgentTest.php b/components/ILIAS/Setup/tests/ilCommonSetupAgentTest.php index 79de8f07f39b..e987ee860b46 100755 --- a/components/ILIAS/Setup/tests/ilCommonSetupAgentTest.php +++ b/components/ILIAS/Setup/tests/ilCommonSetupAgentTest.php @@ -17,6 +17,7 @@ *********************************************************************/ declare(strict_types=1); + namespace ILIAS\Tests\Setup; use PHPUnit\Framework\TestCase; @@ -40,12 +41,12 @@ class ilCommonSetupAgentTest extends TestCase protected function setUp(): void { $refinery = new Refinery( - $this->createMock(DataFactory::class), - $this->createMock(ilLanguage::class) + $this->createStub(DataFactory::class), + $this->createStub(ilLanguage::class) ); parent::setUp(); - $this->testObj = new ilCommonSetupAgent($refinery, $this->createMock(DataFactory::class)); + $this->testObj = new ilCommonSetupAgent($refinery, $this->createStub(DataFactory::class)); } public function testGetNamedObjectives(): void diff --git a/components/ILIAS/UICore/tests/Paths/ilCtrlArrayClassPathTest.php b/components/ILIAS/UICore/tests/Paths/ilCtrlArrayClassPathTest.php index 3e474a0e0b77..27e96aeb6a56 100755 --- a/components/ILIAS/UICore/tests/Paths/ilCtrlArrayClassPathTest.php +++ b/components/ILIAS/UICore/tests/Paths/ilCtrlArrayClassPathTest.php @@ -30,7 +30,7 @@ public function testArrayPathWithEmptyTargets(): void { $path = new ilCtrlArrayClassPath( $this->structure, - $this->createMock(ilCtrlContextInterface::class), + $this->createStub(ilCtrlContextInterface::class), [] ); @@ -45,7 +45,7 @@ public function testArrayPathWithUnknownTargetClass(): void $invalid_class = ilCtrlInvalidGuiClass::class; $path = new ilCtrlArrayClassPath( $this->structure, - $this->createMock(ilCtrlContextInterface::class), + $this->createStub(ilCtrlContextInterface::class), [$invalid_class] ); @@ -61,7 +61,7 @@ public function testArrayPathWithUnrelatedTargets(): void $child_class = ilCtrlCommandClass2TestGUI::class; $path = new ilCtrlArrayClassPath( $this->structure, - $this->createMock(ilCtrlContextInterface::class), + $this->createStub(ilCtrlContextInterface::class), [$parent_class, $child_class] ); diff --git a/components/ILIAS/UICore/tests/Paths/ilCtrlPathFactoryTest.php b/components/ILIAS/UICore/tests/Paths/ilCtrlPathFactoryTest.php index 88b4c828855b..219d617ae8c4 100755 --- a/components/ILIAS/UICore/tests/Paths/ilCtrlPathFactoryTest.php +++ b/components/ILIAS/UICore/tests/Paths/ilCtrlPathFactoryTest.php @@ -44,7 +44,7 @@ protected function setUp(): void public function testPathFactoryFindSingleClassTargetPath(): void { - $context = $this->createMock(ilCtrlContextInterface::class); + $context = $this->createStub(ilCtrlContextInterface::class); $path = $this->factory->find($context, ilCtrlBaseClass1TestGUI::class); $this->assertEquals('0', $path->getCidPath()); @@ -56,7 +56,7 @@ public function testPathFactoryFindSingleClassTargetPath(): void public function testPathFactoryFindArrayClassTargetPath(): void { - $context = $this->createMock(ilCtrlContextInterface::class); + $context = $this->createStub(ilCtrlContextInterface::class); $path = $this->factory->find($context, [ ilCtrlBaseClass1TestGUI::class, ilCtrlCommandClass1TestGUI::class, diff --git a/components/ILIAS/UICore/tests/Paths/ilCtrlSingleClassPathTest.php b/components/ILIAS/UICore/tests/Paths/ilCtrlSingleClassPathTest.php index 8ef400fe8d7f..9e5931c62e2a 100755 --- a/components/ILIAS/UICore/tests/Paths/ilCtrlSingleClassPathTest.php +++ b/components/ILIAS/UICore/tests/Paths/ilCtrlSingleClassPathTest.php @@ -32,7 +32,7 @@ public function testSinglePathWithUnknownClass(): void $invalid_class = ilCtrlInvalidGuiClass::class; $path = new ilCtrlSingleClassPath( $this->structure, - $this->createMock(ilCtrlContextInterface::class), + $this->createStub(ilCtrlContextInterface::class), $invalid_class ); @@ -123,7 +123,7 @@ public function testSinglePathWithEmptyTargetClassString(): void { $path = new ilCtrlSingleClassPath( $this->structure, - $this->createMock(ilCtrlContextInterface::class), + $this->createStub(ilCtrlContextInterface::class), '' ); diff --git a/components/ILIAS/UICore/tests/ilCtrlContextTest.php b/components/ILIAS/UICore/tests/ilCtrlContextTest.php index 3a7addbb9670..9fd1590db2c2 100755 --- a/components/ILIAS/UICore/tests/ilCtrlContextTest.php +++ b/components/ILIAS/UICore/tests/ilCtrlContextTest.php @@ -39,9 +39,9 @@ class ilCtrlContextTest extends TestCase private ilCtrlPathFactory $factory; /** - * @var Refinery + * @var \PHPUnit\Framework\MockObject\Stub&\ILIAS\Refinery\Factory */ - private Refinery $refinery; + private \PHPUnit\Framework\MockObject\Stub $refinery; /** * @var array @@ -54,7 +54,7 @@ class ilCtrlContextTest extends TestCase protected function setUp(): void { $this->values = []; - $this->refinery = $this->createMock(Refinery::class); + $this->refinery = $this->createStub(Refinery::class); $this->factory = $this->createMock(ilCtrlPathFactory::class); $this->request = $this->createMock(ArrayBasedRequestWrapper::class); $this->request->method('has')->willReturn(true); diff --git a/components/ILIAS/UICore/tests/ilCtrlEventTest.php b/components/ILIAS/UICore/tests/ilCtrlEventTest.php index 148a2d9f5588..00a52c8065ea 100755 --- a/components/ILIAS/UICore/tests/ilCtrlEventTest.php +++ b/components/ILIAS/UICore/tests/ilCtrlEventTest.php @@ -40,7 +40,7 @@ protected function setUp(): void public function testObserverAttachment(): void { // Default Attachment - $mocked_observer = $this->createMock(ilCtrlObserver::class); + $mocked_observer = $this->createStub(ilCtrlObserver::class); $mocked_subject = $this->createMock(ilCtrlSubject::class); $mocked_ilctrl = $this->getMockedCtrl($mocked_subject); $mocked_subject->expects($this->once()) @@ -55,7 +55,7 @@ public function testObserverAttachment(): void $mocked_ilctrl->detachObserver($mocked_observer); // Command Class Attachment - $mocked_observer = $this->createMock(ilCtrlObserver::class); + $mocked_observer = $this->createStub(ilCtrlObserver::class); $mocked_subject = $this->createMock(ilCtrlSubject::class); $mocked_ilctrl = $this->getMockedCtrl($mocked_subject); $mocked_subject->expects($this->once()) @@ -70,7 +70,7 @@ public function testObserverAttachment(): void $mocked_ilctrl->detachObserver($mocked_observer, ilCtrlEvent::COMMAND_CLASS_FORWARD); // Command Determination Attachment - $mocked_observer = $this->createMock(ilCtrlObserver::class); + $mocked_observer = $this->createStub(ilCtrlObserver::class); $mocked_subject = $this->createMock(ilCtrlSubject::class); $mocked_ilctrl = $this->getMockedCtrl($mocked_subject); $mocked_subject->expects($this->once()) @@ -119,18 +119,18 @@ function ($event, $cmd) use (&$consecutive) { private function getMockedCtrl(?ilCtrlSubject $subject = null): ilCtrlInterface { return new ilCtrl( - $this->createMock(ilCtrlStructureInterface::class), - $this->createMock(ilCtrlTokenRepositoryInterface::class), - $this->createMock(ilCtrlPathFactoryInterface::class), - $this->createMock(ilCtrlContextInterface::class), - $this->createMock(ResponseSenderStrategy::class), - $this->createMock(ServerRequestInterface::class), - $this->createMock(RequestWrapper::class), - $this->createMock(RequestWrapper::class), - $this->createMock(Refinery::class), - $this->createMock(ilComponentFactory::class), + $this->createStub(ilCtrlStructureInterface::class), + $this->createStub(ilCtrlTokenRepositoryInterface::class), + $this->createStub(ilCtrlPathFactoryInterface::class), + $this->createStub(ilCtrlContextInterface::class), + $this->createStub(ResponseSenderStrategy::class), + $this->createStub(ServerRequestInterface::class), + $this->createStub(RequestWrapper::class), + $this->createStub(RequestWrapper::class), + $this->createStub(Refinery::class), + $this->createStub(ilComponentFactory::class), $subject ?? $this->subject, - $this->createMock(ilCtrlQueryParserInterface::class), + $this->createStub(ilCtrlQueryParserInterface::class), ); } } diff --git a/components/ILIAS/UICore/tests/ilCtrlTest.php b/components/ILIAS/UICore/tests/ilCtrlTest.php index 5a4f1d1668ee..2ccb0fb563e9 100755 --- a/components/ILIAS/UICore/tests/ilCtrlTest.php +++ b/components/ILIAS/UICore/tests/ilCtrlTest.php @@ -50,17 +50,17 @@ public function testCallBaseClassWithInvalidProvidedBaseClass(): void $ctrl = new ilCtrl( $structure, - $this->createMock(ilCtrlTokenRepositoryInterface::class), - $this->createMock(ilCtrlPathFactoryInterface::class), - $this->createMock(ilCtrlContextInterface::class), - $this->createMock(ResponseSenderStrategy::class), - $this->createMock(ServerRequestInterface::class), - $this->createMock(RequestWrapper::class), - $this->createMock(RequestWrapper::class), - $this->createMock(Refinery::class), - $this->createMock(ilComponentFactory::class), + $this->createStub(ilCtrlTokenRepositoryInterface::class), + $this->createStub(ilCtrlPathFactoryInterface::class), + $this->createStub(ilCtrlContextInterface::class), + $this->createStub(ResponseSenderStrategy::class), + $this->createStub(ServerRequestInterface::class), + $this->createStub(RequestWrapper::class), + $this->createStub(RequestWrapper::class), + $this->createStub(Refinery::class), + $this->createStub(ilComponentFactory::class), new ilCtrlSubject(), - $this->createMock(ilCtrlQueryParserInterface::class), + $this->createStub(ilCtrlQueryParserInterface::class), ); $invalid_baseclass = ilCtrlInvalidGuiClass::class; @@ -133,18 +133,18 @@ public function testGetCmdWithoutProvidedCmd(): void public function testGetCmdWithoutProvidedCmdAndFallback(): void { $ctrl = new ilCtrl( - $this->createMock(ilCtrlStructureInterface::class), - $this->createMock(ilCtrlTokenRepositoryInterface::class), - $this->createMock(ilCtrlPathFactoryInterface::class), - $this->createMock(ilCtrlContextInterface::class), - $this->createMock(ResponseSenderStrategy::class), - $this->createMock(ServerRequestInterface::class), - $this->createMock(RequestWrapper::class), - $this->createMock(RequestWrapper::class), - $this->createMock(Refinery::class), - $this->createMock(ilComponentFactory::class), + $this->createStub(ilCtrlStructureInterface::class), + $this->createStub(ilCtrlTokenRepositoryInterface::class), + $this->createStub(ilCtrlPathFactoryInterface::class), + $this->createStub(ilCtrlContextInterface::class), + $this->createStub(ResponseSenderStrategy::class), + $this->createStub(ServerRequestInterface::class), + $this->createStub(RequestWrapper::class), + $this->createStub(RequestWrapper::class), + $this->createStub(Refinery::class), + $this->createStub(ilComponentFactory::class), new ilCtrlSubject(), - $this->createMock(ilCtrlQueryParserInterface::class), + $this->createStub(ilCtrlQueryParserInterface::class), ); $fallback_cmd = 'fallback_cmd_test'; @@ -223,18 +223,18 @@ public function testGetParentReturnByClass() : void private function getMockedCtrl(): ilCtrlInterface { return new ilCtrl( - $this->createMock(ilCtrlStructureInterface::class), - $this->createMock(ilCtrlTokenRepositoryInterface::class), - $this->createMock(ilCtrlPathFactoryInterface::class), - $this->createMock(ilCtrlContextInterface::class), - $this->createMock(ResponseSenderStrategy::class), - $this->createMock(ServerRequestInterface::class), - $this->createMock(RequestWrapper::class), - $this->createMock(RequestWrapper::class), - $this->createMock(Refinery::class), - $this->createMock(ilComponentFactory::class), + $this->createStub(ilCtrlStructureInterface::class), + $this->createStub(ilCtrlTokenRepositoryInterface::class), + $this->createStub(ilCtrlPathFactoryInterface::class), + $this->createStub(ilCtrlContextInterface::class), + $this->createStub(ResponseSenderStrategy::class), + $this->createStub(ServerRequestInterface::class), + $this->createStub(RequestWrapper::class), + $this->createStub(RequestWrapper::class), + $this->createStub(Refinery::class), + $this->createStub(ilComponentFactory::class), new ilCtrlSubject(), - $this->createMock(ilCtrlQueryParserInterface::class), + $this->createStub(ilCtrlQueryParserInterface::class), ); } }