From b535998f4dc5b657836a55f4d1fb9891b5fccd3c Mon Sep 17 00:00:00 2001 From: Simon Schaufelberger Date: Tue, 17 Aug 2021 01:01:36 +0200 Subject: [PATCH] [FEATURE] Update generated tests to phpunit 9 --- .../Extbase/Tests/Functional/BasicTest.phpt | 2 +- .../Extbase/Tests/Unit/ControllerTest.phpt | 55 ++++---- .../Extbase/Tests/Unit/DomainModelTest.phpt | 87 ++++-------- .../Tests/Functional/BasicTest.php | 2 +- .../Unit/Controller/MainControllerTest.php | 53 ++++---- .../Tests/Unit/Domain/Model/Child1Test.php | 39 +++--- .../Tests/Unit/Domain/Model/Child2Test.php | 64 ++++----- .../Tests/Unit/Domain/Model/Child3Test.php | 44 +++--- .../Tests/Unit/Domain/Model/Child4Test.php | 34 +++-- .../Tests/Unit/Domain/Model/MainTest.php | 128 +++++++----------- 10 files changed, 213 insertions(+), 295 deletions(-) diff --git a/Resources/Private/CodeTemplates/Extbase/Tests/Functional/BasicTest.phpt b/Resources/Private/CodeTemplates/Extbase/Tests/Functional/BasicTest.phpt index 453beaa4c..1c6baa35c 100644 --- a/Resources/Private/CodeTemplates/Extbase/Tests/Functional/BasicTest.phpt +++ b/Resources/Private/CodeTemplates/Extbase/Tests/Functional/BasicTest.phpt @@ -24,7 +24,7 @@ class BasicTest extends FunctionalTestCase * * @test */ - public function dummy() + public function dummy(): void { $this->assertTrue(true); } diff --git a/Resources/Private/CodeTemplates/Extbase/Tests/Unit/ControllerTest.phpt b/Resources/Private/CodeTemplates/Extbase/Tests/Unit/ControllerTest.phpt index cf5d1d348..ffcaa4504 100644 --- a/Resources/Private/CodeTemplates/Extbase/Tests/Unit/ControllerTest.phpt +++ b/Resources/Private/CodeTemplates/Extbase/Tests/Unit/ControllerTest.phpt @@ -3,6 +3,9 @@ declare(strict_types=1); namespace {extension.namespaceName}\Tests\Unit\Controller; +use PHPUnit\Framework\MockObject\MockObject; +use TYPO3\CMS\Extbase\Mvc\View\ViewInterface; +use TYPO3\TestingFramework\Core\AccessibleObjectInterface; use TYPO3\TestingFramework\Core\Unit\UnitTestCase; /** @@ -13,20 +16,20 @@ use TYPO3\TestingFramework\Core\Unit\UnitTestCase; class {controllerName}Test extends UnitTestCase { /** - * @var \{domainObject.controllerClassName} + * @var \{domainObject.controllerClassName}|MockObject|AccessibleObjectInterface */ protected $subject; - protected function setUp() + protected function setUp(): void { parent::setUp(); - $this->subject = $this->getMockBuilder(\{domainObject.controllerClassName}::class) - ->setMethods(['redirect', 'forward', 'addFlashMessage']) + $this->subject = $this->getMockBuilder($this->buildAccessibleProxy(\{domainObject.controllerClassName}::class)) + ->onlyMethods(['redirect', 'forward', 'addFlashMessage']) ->disableOriginalConstructor() ->getMock(); } - protected function tearDown() + protected function tearDown(): void { parent::tearDown(); } @@ -36,22 +39,22 @@ class {controllerName}Test extends UnitTestCase /** * @test */ - public function listActionFetchesAll{domainObject.name -> k:pluralize()}FromRepositoryAndAssignsThemToView() + public function listActionFetchesAll{domainObject.name -> k:pluralize()}FromRepositoryAndAssignsThemToView(): void { $all{domainObject.name -> k:pluralize()} = $this->getMockBuilder(\TYPO3\CMS\Extbase\Persistence\ObjectStorage::class) ->disableOriginalConstructor() ->getMock(); ${domainObject.name -> k:format.lowercaseFirst()}Repository = $this->getMockBuilder(\{domainObject.qualifiedDomainRepositoryClassName}::class) - ->setMethods(['findAll']) + ->onlyMethods(['findAll']) ->disableOriginalConstructor() ->getMock(); ${domainObject.name -> k:format.lowercaseFirst()}Repository->expects(self::once())->method('findAll')->will(self::returnValue($all{domainObject.name -> k:pluralize()})); - $this->inject($this->subject, '{domainObject.name -> k:format.lowercaseFirst()}Repository', ${domainObject.name -> k:format.lowercaseFirst()}Repository); + $this->subject->_set('{domainObject.name -> k:format.lowercaseFirst()}Repository', ${domainObject.name -> k:format.lowercaseFirst()}Repository); - $view = $this->getMockBuilder(\TYPO3\CMS\Extbase\Mvc\View\ViewInterface::class)->getMock(); + $view = $this->getMockBuilder(ViewInterface::class)->getMock(); $view->expects(self::once())->method('assign')->with('{domainObject.name -> k:pluralize() -> k:format.lowercaseFirst()}', $all{domainObject.name -> k:pluralize()}); - $this->inject($this->subject, 'view', $view); + $this->subject->_set('view', $view); $this->subject->listAction(); } @@ -59,12 +62,12 @@ class {controllerName}Test extends UnitTestCase /** * @test */ - public function showActionAssignsTheGiven{domainObject.name}ToView() + public function showActionAssignsTheGiven{domainObject.name}ToView(): void { ${domainObject.name -> k:format.lowercaseFirst()} = new {domainObject.fullQualifiedClassName}(); - $view = $this->getMockBuilder(\TYPO3\CMS\Extbase\Mvc\View\ViewInterface::class)->getMock(); - $this->inject($this->subject, 'view', $view); + $view = $this->getMockBuilder(ViewInterface::class)->getMock(); + $this->subject->_set('view', $view); $view->expects(self::once())->method('assign')->with('{domainObject.name -> k:format.lowercaseFirst()}', ${domainObject.name -> k:format.lowercaseFirst()}); $this->subject->showAction(${domainObject.name -> k:format.lowercaseFirst()}); @@ -73,17 +76,17 @@ class {controllerName}Test extends UnitTestCase /** * @test */ - public function createActionAddsTheGiven{domainObject.name}To{domainObject.name}Repository() + public function createActionAddsTheGiven{domainObject.name}To{domainObject.name}Repository(): void { ${domainObject.name -> k:format.lowercaseFirst()} = new {domainObject.fullQualifiedClassName}(); ${domainObject.name -> k:format.lowercaseFirst()}Repository = $this->getMockBuilder(\{domainObject.qualifiedDomainRepositoryClassName}::class) - ->setMethods(['add']) + ->onlyMethods(['add']) ->disableOriginalConstructor() ->getMock(); ${domainObject.name -> k:format.lowercaseFirst()}Repository->expects(self::once())->method('add')->with(${domainObject.name -> k:format.lowercaseFirst()}); - $this->inject($this->subject, '{domainObject.name -> k:format.lowercaseFirst()}Repository', ${domainObject.name -> k:format.lowercaseFirst()}Repository); + $this->subject->_set('{domainObject.name -> k:format.lowercaseFirst()}Repository', ${domainObject.name -> k:format.lowercaseFirst()}Repository); $this->subject->createAction(${domainObject.name -> k:format.lowercaseFirst()}); } @@ -91,12 +94,12 @@ class {controllerName}Test extends UnitTestCase /** * @test */ - public function editActionAssignsTheGiven{domainObject.name}ToView() + public function editActionAssignsTheGiven{domainObject.name}ToView(): void { ${domainObject.name -> k:format.lowercaseFirst()} = new {domainObject.fullQualifiedClassName}(); - $view = $this->getMockBuilder(\TYPO3\CMS\Extbase\Mvc\View\ViewInterface::class)->getMock(); - $this->inject($this->subject, 'view', $view); + $view = $this->getMockBuilder(ViewInterface::class)->getMock(); + $this->subject->_set('view', $view); $view->expects(self::once())->method('assign')->with('{domainObject.name -> k:format.lowercaseFirst()}', ${domainObject.name -> k:format.lowercaseFirst()}); $this->subject->editAction(${domainObject.name -> k:format.lowercaseFirst()}); @@ -106,17 +109,17 @@ class {controllerName}Test extends UnitTestCase /** * @test */ - public function updateActionUpdatesTheGiven{domainObject.name}In{domainObject.name}Repository() + public function updateActionUpdatesTheGiven{domainObject.name}In{domainObject.name}Repository(): void { ${domainObject.name -> k:format.lowercaseFirst()} = new {domainObject.fullQualifiedClassName}(); ${domainObject.name -> k:format.lowercaseFirst()}Repository = $this->getMockBuilder(\{domainObject.qualifiedDomainRepositoryClassName}::class) - ->setMethods(['update']) + ->onlyMethods(['update']) ->disableOriginalConstructor() ->getMock(); ${domainObject.name -> k:format.lowercaseFirst()}Repository->expects(self::once())->method('update')->with(${domainObject.name -> k:format.lowercaseFirst()}); - $this->inject($this->subject, '{domainObject.name -> k:format.lowercaseFirst()}Repository', ${domainObject.name -> k:format.lowercaseFirst()}Repository); + $this->subject->_set('{domainObject.name -> k:format.lowercaseFirst()}Repository', ${domainObject.name -> k:format.lowercaseFirst()}Repository); $this->subject->updateAction(${domainObject.name -> k:format.lowercaseFirst()}); } @@ -124,24 +127,24 @@ class {controllerName}Test extends UnitTestCase /** * @test */ - public function deleteActionRemovesTheGiven{domainObject.name}From{domainObject.name}Repository() + public function deleteActionRemovesTheGiven{domainObject.name}From{domainObject.name}Repository(): void { ${domainObject.name -> k:format.lowercaseFirst()} = new {domainObject.fullQualifiedClassName}(); ${domainObject.name -> k:format.lowercaseFirst()}Repository = $this->getMockBuilder(\{domainObject.qualifiedDomainRepositoryClassName}::class) - ->setMethods(['remove']) + ->onlyMethods(['remove']) ->disableOriginalConstructor() ->getMock(); ${domainObject.name -> k:format.lowercaseFirst()}Repository->expects(self::once())->method('remove')->with(${domainObject.name -> k:format.lowercaseFirst()}); - $this->inject($this->subject, '{domainObject.name -> k:format.lowercaseFirst()}Repository', ${domainObject.name -> k:format.lowercaseFirst()}Repository); + $this->subject->_set('{domainObject.name -> k:format.lowercaseFirst()}Repository', ${domainObject.name -> k:format.lowercaseFirst()}Repository); $this->subject->deleteAction(${domainObject.name -> k:format.lowercaseFirst()}); } /** * @test */ - public function dummyTestToNotLeaveThisFileEmpty() + public function dummyTestToNotLeaveThisFileEmpty(): void { self::markTestIncomplete(); } diff --git a/Resources/Private/CodeTemplates/Extbase/Tests/Unit/DomainModelTest.phpt b/Resources/Private/CodeTemplates/Extbase/Tests/Unit/DomainModelTest.phpt index d19ece32f..265f58f72 100644 --- a/Resources/Private/CodeTemplates/Extbase/Tests/Unit/DomainModelTest.phpt +++ b/Resources/Private/CodeTemplates/Extbase/Tests/Unit/DomainModelTest.phpt @@ -3,6 +3,8 @@ declare(strict_types=1); namespace {extension.namespaceName}\Tests\Unit\Domain\Model; +use PHPUnit\Framework\MockObject\MockObject; +use TYPO3\TestingFramework\Core\AccessibleObjectInterface; use TYPO3\TestingFramework\Core\Unit\UnitTestCase; /** @@ -13,17 +15,21 @@ use TYPO3\TestingFramework\Core\Unit\UnitTestCase; class {domainObject.name}Test extends UnitTestCase { /** - * @var {domainObject.fullQualifiedClassName} + * @var {domainObject.fullQualifiedClassName}|MockObject|AccessibleObjectInterface */ protected $subject; - protected function setUp() + protected function setUp(): void { parent::setUp(); - $this->subject = new {domainObject.fullQualifiedClassName}(); + + $this->subject = $this->getAccessibleMock( + {domainObject.fullQualifiedClassName}::class, + ['dummy'] + ); } - protected function tearDown() + protected function tearDown(): void { parent::tearDown(); } @@ -34,7 +40,7 @@ class {domainObject.name}Test extends UnitTestCase /** * @test */ - public function get{property.name -> k:format.uppercaseFirst()}ReturnsInitialValueForFileReference{f:if(condition:"{k:matchString(match:'ObjectStorage', in:property.unqualifiedType)}", then:"{property.foreignModelName}", else:"{property.unqualifiedType -> k:format.uppercaseFirst()}")}() + public function get{property.name -> k:format.uppercaseFirst()}ReturnsInitialValueForFileReference{f:if(condition: "{k:matchString(match: 'ObjectStorage', in: property.unqualifiedType)}", then: "{property.foreignModelName}", else: "{property.unqualifiedType -> k:format.uppercaseFirst()}")}(): void { self::assertSame( 0, @@ -48,10 +54,7 @@ class {domainObject.name}Test extends UnitTestCase '', $this->subject->get{property.name -> k:format.uppercaseFirst()}() ); - self::assertSame( - false, - $this->subject->get{property.name -> k:format.uppercaseFirst()}() - ); + self::assertFalse($this->subject->get{property.name -> k:format.uppercaseFirst()}()); $newObjectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); self::assertEquals( $newObjectStorage, @@ -74,87 +77,53 @@ class {domainObject.name}Test extends UnitTestCase /** * @test */ - public function set{property.name -> k:format.uppercaseFirst()}ForFileReference{f:if(condition:"{k:matchString(match:'ObjectStorage', in:property.unqualifiedType)}", then:"ObjectStorageContaining{property.foreignModelName}", else:"{property.unqualifiedType -> k:format.uppercaseFirst()}")}Sets{property.name -> k:format.uppercaseFirst()}() + public function set{property.name -> k:format.uppercaseFirst()}ForFileReference{f:if(condition:"{k:matchString(match: 'ObjectStorage', in: property.unqualifiedType)}", then: "ObjectStorageContaining{property.foreignModelName}", else: "{property.unqualifiedType -> k:format.uppercaseFirst()}")}Sets{property.name -> k:format.uppercaseFirst()}(): void { $this->subject->set{property.name -> k:format.uppercaseFirst()}('Conceived at T3CON10'); - self::assertAttributeEquals( - 'Conceived at T3CON10', - '{property.name}', - $this->subject - ); + self::assertEquals('Conceived at T3CON10', $this->subject->_get('{property.name}')); $this->subject->set{property.name -> k:format.uppercaseFirst()}(12); - self::assertAttributeEquals( - 12, - '{property.name}', - $this->subject - ); + self::assertEquals(12, $this->subject->_get('{property.name}')); $this->subject->set{property.name -> k:format.uppercaseFirst()}(3.14159265); - self::assertAttributeEquals( - 3.14159265, - '{property.name}', - $this->subject, - '', - 0.000000001 - ); + self::assertEquals(3.14159265, $this->subject->_get('{property.name}')); $this->subject->set{property.name -> k:format.uppercaseFirst()}(true); - self::assertAttributeEquals( - true, - '{property.name}', - $this->subject - ); + self::assertEquals(true, $this->subject->_get('{property.name}')); ${property.name -> k:singularize()} = new {k:pregReplace(match:'/^.*<(.*)>$/', replace:'\1', subject:property.unqualifiedType)}(); $objectStorageHoldingExactlyOne{property.name -> k:format.uppercaseFirst()} = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); $objectStorageHoldingExactlyOne{property.name -> k:format.uppercaseFirst()}->attach(${property.name -> k:singularize()}); $this->subject->set{property.name -> k:format.uppercaseFirst()}($objectStorageHoldingExactlyOne{property.name -> k:format.uppercaseFirst()}); - self::assertAttributeEquals( - $objectStorageHoldingExactlyOne{property.name -> k:format.uppercaseFirst()}, - '{property.name}', - $this->subject - ); + self::assertEquals($objectStorageHoldingExactlyOne{property.name -> k:format.uppercaseFirst()}, $this->subject->_get('{property.name}')); ${property.name}Fixture = new {f:if(condition:"{k:matchString(match:'ObjectStorage', in:property.unqualifiedType)}", then:"ObjectStorageContaining{property.foreignModelName)}", else:"{property.foreignModel.fullQualifiedClassName}")}(); $this->subject->set{property.name -> k:format.uppercaseFirst()}(${property.name}Fixture); - self::assertAttributeEquals( - ${property.name}Fixture, - '{property.name}', - $this->subject - ); + self::assertEquals(${property.name}Fixture, $this->subject->_get('{property.name}')); $dateTimeFixture = new \DateTime(); $this->subject->set{property.name -> k:format.uppercaseFirst()}($dateTimeFixture); - self::assertAttributeEquals( - $dateTimeFixture, - '{property.name}', - $this->subject - ); + self::assertEquals($dateTimeFixture, $this->subject->_get('{property.name}')); $fileReferenceFixture = new \TYPO3\CMS\Extbase\Domain\Model\FileReference(); $this->subject->set{property.name -> k:format.uppercaseFirst()}($fileReferenceFixture); - self::assertAttributeEquals( - $fileReferenceFixture, - '{property.name}', - $this->subject - ); + self::assertEquals($fileReferenceFixture, $this->subject->_get('{property.name}')); } /** * @test */ - public function add{property.name -> k:singularize() -> k:format.uppercaseFirst()}ToObjectStorageHolding{property.name -> k:format.uppercaseFirst()}() + public function add{property.name -> k:singularize() -> k:format.uppercaseFirst()}ToObjectStorageHolding{property.name -> k:format.uppercaseFirst()}(): void { ${property.name -> k:singularize()} = new {property.foreignClassName}(); ${property.name}ObjectStorageMock = $this->getMockBuilder(\TYPO3\CMS\Extbase\Persistence\ObjectStorage::class) - ->setMethods(['attach']) + ->onlyMethods(['attach']) ->disableOriginalConstructor() ->getMock(); ${property.name}ObjectStorageMock->expects(self::once())->method('attach')->with(self::equalTo(${property.name -> k:singularize()})); - $this->inject($this->subject, '{property.name}', ${property.name}ObjectStorageMock); + $this->subject->_set('{property.name}', ${property.name}ObjectStorageMock); $this->subject->add{property.name -> k:singularize() -> k:format.uppercaseFirst()}(${property.name -> k:singularize()}); } @@ -162,23 +131,23 @@ class {domainObject.name}Test extends UnitTestCase /** * @test */ - public function remove{property.name -> k:singularize() -> k:format.uppercaseFirst()}FromObjectStorageHolding{property.name -> k:format.uppercaseFirst()}() + public function remove{property.name -> k:singularize() -> k:format.uppercaseFirst()}FromObjectStorageHolding{property.name -> k:format.uppercaseFirst()}(): void { ${property.name -> k:singularize()} = new {property.foreignClassName}(); ${property.name}ObjectStorageMock = $this->getMockBuilder(\TYPO3\CMS\Extbase\Persistence\ObjectStorage::class) - ->setMethods(['detach']) + ->onlyMethods(['detach']) ->disableOriginalConstructor() ->getMock(); ${property.name}ObjectStorageMock->expects(self::once())->method('detach')->with(self::equalTo(${property.name -> k:singularize()})); - $this->inject($this->subject, '{property.name}', ${property.name}ObjectStorageMock); + $this->subject->_set('{property.name}', ${property.name}ObjectStorageMock); $this->subject->remove{property.name -> k:singularize() -> k:format.uppercaseFirst()}(${property.name -> k:singularize()}); } /** * @test */ - public function dummyTestToNotLeaveThisFileEmpty() + public function dummyTestToNotLeaveThisFileEmpty(): void { self::markTestIncomplete(); } diff --git a/Tests/Fixtures/TestExtensions/test_extension/Tests/Functional/BasicTest.php b/Tests/Fixtures/TestExtensions/test_extension/Tests/Functional/BasicTest.php index 125d646f9..d26a85447 100644 --- a/Tests/Fixtures/TestExtensions/test_extension/Tests/Functional/BasicTest.php +++ b/Tests/Fixtures/TestExtensions/test_extension/Tests/Functional/BasicTest.php @@ -24,7 +24,7 @@ class BasicTest extends FunctionalTestCase * * @test */ - public function dummy() + public function dummy(): void { $this->assertTrue(true); } diff --git a/Tests/Fixtures/TestExtensions/test_extension/Tests/Unit/Controller/MainControllerTest.php b/Tests/Fixtures/TestExtensions/test_extension/Tests/Unit/Controller/MainControllerTest.php index f0bb6ec02..3f547b8a8 100644 --- a/Tests/Fixtures/TestExtensions/test_extension/Tests/Unit/Controller/MainControllerTest.php +++ b/Tests/Fixtures/TestExtensions/test_extension/Tests/Unit/Controller/MainControllerTest.php @@ -3,6 +3,9 @@ namespace FIXTURE\TestExtension\Tests\Unit\Controller; +use PHPUnit\Framework\MockObject\MockObject; +use TYPO3\CMS\Extbase\Mvc\View\ViewInterface; +use TYPO3\TestingFramework\Core\AccessibleObjectInterface; use TYPO3\TestingFramework\Core\Unit\UnitTestCase; /** @@ -13,20 +16,20 @@ class MainControllerTest extends UnitTestCase { /** - * @var \FIXTURE\TestExtension\Controller\MainController + * @var \FIXTURE\TestExtension\Controller\MainController|MockObject|AccessibleObjectInterface */ protected $subject; - protected function setUp() + protected function setUp(): void { parent::setUp(); - $this->subject = $this->getMockBuilder(\FIXTURE\TestExtension\Controller\MainController::class) - ->setMethods(['redirect', 'forward', 'addFlashMessage']) + $this->subject = $this->getMockBuilder($this->buildAccessibleProxy(\FIXTURE\TestExtension\Controller\MainController::class)) + ->onlyMethods(['redirect', 'forward', 'addFlashMessage']) ->disableOriginalConstructor() ->getMock(); } - protected function tearDown() + protected function tearDown(): void { parent::tearDown(); } @@ -34,22 +37,22 @@ protected function tearDown() /** * @test */ - public function listActionFetchesAllMainsFromRepositoryAndAssignsThemToView() + public function listActionFetchesAllMainsFromRepositoryAndAssignsThemToView(): void { $allMains = $this->getMockBuilder(\TYPO3\CMS\Extbase\Persistence\ObjectStorage::class) ->disableOriginalConstructor() ->getMock(); $mainRepository = $this->getMockBuilder(\FIXTURE\TestExtension\Domain\Repository\MainRepository::class) - ->setMethods(['findAll']) + ->onlyMethods(['findAll']) ->disableOriginalConstructor() ->getMock(); $mainRepository->expects(self::once())->method('findAll')->will(self::returnValue($allMains)); - $this->inject($this->subject, 'mainRepository', $mainRepository); + $this->subject->_set('mainRepository', $mainRepository); - $view = $this->getMockBuilder(\TYPO3\CMS\Extbase\Mvc\View\ViewInterface::class)->getMock(); + $view = $this->getMockBuilder(ViewInterface::class)->getMock(); $view->expects(self::once())->method('assign')->with('mains', $allMains); - $this->inject($this->subject, 'view', $view); + $this->subject->_set('view', $view); $this->subject->listAction(); } @@ -57,12 +60,12 @@ public function listActionFetchesAllMainsFromRepositoryAndAssignsThemToView() /** * @test */ - public function showActionAssignsTheGivenMainToView() + public function showActionAssignsTheGivenMainToView(): void { $main = new \FIXTURE\TestExtension\Domain\Model\Main(); - $view = $this->getMockBuilder(\TYPO3\CMS\Extbase\Mvc\View\ViewInterface::class)->getMock(); - $this->inject($this->subject, 'view', $view); + $view = $this->getMockBuilder(ViewInterface::class)->getMock(); + $this->subject->_set('view', $view); $view->expects(self::once())->method('assign')->with('main', $main); $this->subject->showAction($main); @@ -71,17 +74,17 @@ public function showActionAssignsTheGivenMainToView() /** * @test */ - public function createActionAddsTheGivenMainToMainRepository() + public function createActionAddsTheGivenMainToMainRepository(): void { $main = new \FIXTURE\TestExtension\Domain\Model\Main(); $mainRepository = $this->getMockBuilder(\FIXTURE\TestExtension\Domain\Repository\MainRepository::class) - ->setMethods(['add']) + ->onlyMethods(['add']) ->disableOriginalConstructor() ->getMock(); $mainRepository->expects(self::once())->method('add')->with($main); - $this->inject($this->subject, 'mainRepository', $mainRepository); + $this->subject->_set('mainRepository', $mainRepository); $this->subject->createAction($main); } @@ -89,12 +92,12 @@ public function createActionAddsTheGivenMainToMainRepository() /** * @test */ - public function editActionAssignsTheGivenMainToView() + public function editActionAssignsTheGivenMainToView(): void { $main = new \FIXTURE\TestExtension\Domain\Model\Main(); - $view = $this->getMockBuilder(\TYPO3\CMS\Extbase\Mvc\View\ViewInterface::class)->getMock(); - $this->inject($this->subject, 'view', $view); + $view = $this->getMockBuilder(ViewInterface::class)->getMock(); + $this->subject->_set('view', $view); $view->expects(self::once())->method('assign')->with('main', $main); $this->subject->editAction($main); @@ -103,17 +106,17 @@ public function editActionAssignsTheGivenMainToView() /** * @test */ - public function updateActionUpdatesTheGivenMainInMainRepository() + public function updateActionUpdatesTheGivenMainInMainRepository(): void { $main = new \FIXTURE\TestExtension\Domain\Model\Main(); $mainRepository = $this->getMockBuilder(\FIXTURE\TestExtension\Domain\Repository\MainRepository::class) - ->setMethods(['update']) + ->onlyMethods(['update']) ->disableOriginalConstructor() ->getMock(); $mainRepository->expects(self::once())->method('update')->with($main); - $this->inject($this->subject, 'mainRepository', $mainRepository); + $this->subject->_set('mainRepository', $mainRepository); $this->subject->updateAction($main); } @@ -121,17 +124,17 @@ public function updateActionUpdatesTheGivenMainInMainRepository() /** * @test */ - public function deleteActionRemovesTheGivenMainFromMainRepository() + public function deleteActionRemovesTheGivenMainFromMainRepository(): void { $main = new \FIXTURE\TestExtension\Domain\Model\Main(); $mainRepository = $this->getMockBuilder(\FIXTURE\TestExtension\Domain\Repository\MainRepository::class) - ->setMethods(['remove']) + ->onlyMethods(['remove']) ->disableOriginalConstructor() ->getMock(); $mainRepository->expects(self::once())->method('remove')->with($main); - $this->inject($this->subject, 'mainRepository', $mainRepository); + $this->subject->_set('mainRepository', $mainRepository); $this->subject->deleteAction($main); } diff --git a/Tests/Fixtures/TestExtensions/test_extension/Tests/Unit/Domain/Model/Child1Test.php b/Tests/Fixtures/TestExtensions/test_extension/Tests/Unit/Domain/Model/Child1Test.php index b3d96fe1d..16780b8ab 100644 --- a/Tests/Fixtures/TestExtensions/test_extension/Tests/Unit/Domain/Model/Child1Test.php +++ b/Tests/Fixtures/TestExtensions/test_extension/Tests/Unit/Domain/Model/Child1Test.php @@ -3,6 +3,8 @@ namespace FIXTURE\TestExtension\Tests\Unit\Domain\Model; +use PHPUnit\Framework\MockObject\MockObject; +use TYPO3\TestingFramework\Core\AccessibleObjectInterface; use TYPO3\TestingFramework\Core\Unit\UnitTestCase; /** @@ -13,17 +15,21 @@ class Child1Test extends UnitTestCase { /** - * @var \FIXTURE\TestExtension\Domain\Model\Child1 + * @var \FIXTURE\TestExtension\Domain\Model\Child1|MockObject|AccessibleObjectInterface */ protected $subject; - protected function setUp() + protected function setUp(): void { parent::setUp(); - $this->subject = new \FIXTURE\TestExtension\Domain\Model\Child1(); + + $this->subject = $this->getAccessibleMock( + \FIXTURE\TestExtension\Domain\Model\Child1::class, + ['dummy'] + ); } - protected function tearDown() + protected function tearDown(): void { parent::tearDown(); } @@ -31,7 +37,7 @@ protected function tearDown() /** * @test */ - public function getNameReturnsInitialValueForString() + public function getNameReturnsInitialValueForString(): void { self::assertSame( '', @@ -42,39 +48,28 @@ public function getNameReturnsInitialValueForString() /** * @test */ - public function setNameForStringSetsName() + public function setNameForStringSetsName(): void { $this->subject->setName('Conceived at T3CON10'); - self::assertAttributeEquals( - 'Conceived at T3CON10', - 'name', - $this->subject - ); + self::assertEquals('Conceived at T3CON10', $this->subject->_get('name')); } /** * @test */ - public function getFlagReturnsInitialValueForBool() + public function getFlagReturnsInitialValueForBool(): void { - self::assertSame( - false, - $this->subject->getFlag() - ); + self::assertFalse($this->subject->getFlag()); } /** * @test */ - public function setFlagForBoolSetsFlag() + public function setFlagForBoolSetsFlag(): void { $this->subject->setFlag(true); - self::assertAttributeEquals( - true, - 'flag', - $this->subject - ); + self::assertEquals(true, $this->subject->_get('flag')); } } diff --git a/Tests/Fixtures/TestExtensions/test_extension/Tests/Unit/Domain/Model/Child2Test.php b/Tests/Fixtures/TestExtensions/test_extension/Tests/Unit/Domain/Model/Child2Test.php index 532bdceb3..7953f7320 100644 --- a/Tests/Fixtures/TestExtensions/test_extension/Tests/Unit/Domain/Model/Child2Test.php +++ b/Tests/Fixtures/TestExtensions/test_extension/Tests/Unit/Domain/Model/Child2Test.php @@ -3,6 +3,8 @@ namespace FIXTURE\TestExtension\Tests\Unit\Domain\Model; +use PHPUnit\Framework\MockObject\MockObject; +use TYPO3\TestingFramework\Core\AccessibleObjectInterface; use TYPO3\TestingFramework\Core\Unit\UnitTestCase; /** @@ -13,17 +15,21 @@ class Child2Test extends UnitTestCase { /** - * @var \FIXTURE\TestExtension\Domain\Model\Child2 + * @var \FIXTURE\TestExtension\Domain\Model\Child2|MockObject|AccessibleObjectInterface */ protected $subject; - protected function setUp() + protected function setUp(): void { parent::setUp(); - $this->subject = new \FIXTURE\TestExtension\Domain\Model\Child2(); + + $this->subject = $this->getAccessibleMock( + \FIXTURE\TestExtension\Domain\Model\Child2::class, + ['dummy'] + ); } - protected function tearDown() + protected function tearDown(): void { parent::tearDown(); } @@ -31,7 +37,7 @@ protected function tearDown() /** * @test */ - public function getNameReturnsInitialValueForString() + public function getNameReturnsInitialValueForString(): void { self::assertSame( '', @@ -42,21 +48,17 @@ public function getNameReturnsInitialValueForString() /** * @test */ - public function setNameForStringSetsName() + public function setNameForStringSetsName(): void { $this->subject->setName('Conceived at T3CON10'); - self::assertAttributeEquals( - 'Conceived at T3CON10', - 'name', - $this->subject - ); + self::assertEquals('Conceived at T3CON10', $this->subject->_get('name')); } /** * @test */ - public function getDateProperty1ReturnsInitialValueForDateTime() + public function getDateProperty1ReturnsInitialValueForDateTime(): void { self::assertEquals( null, @@ -67,22 +69,18 @@ public function getDateProperty1ReturnsInitialValueForDateTime() /** * @test */ - public function setDateProperty1ForDateTimeSetsDateProperty1() + public function setDateProperty1ForDateTimeSetsDateProperty1(): void { $dateTimeFixture = new \DateTime(); $this->subject->setDateProperty1($dateTimeFixture); - self::assertAttributeEquals( - $dateTimeFixture, - 'dateProperty1', - $this->subject - ); + self::assertEquals($dateTimeFixture, $this->subject->_get('dateProperty1')); } /** * @test */ - public function getDateProperty2ReturnsInitialValueForDateTime() + public function getDateProperty2ReturnsInitialValueForDateTime(): void { self::assertEquals( null, @@ -93,22 +91,18 @@ public function getDateProperty2ReturnsInitialValueForDateTime() /** * @test */ - public function setDateProperty2ForDateTimeSetsDateProperty2() + public function setDateProperty2ForDateTimeSetsDateProperty2(): void { $dateTimeFixture = new \DateTime(); $this->subject->setDateProperty2($dateTimeFixture); - self::assertAttributeEquals( - $dateTimeFixture, - 'dateProperty2', - $this->subject - ); + self::assertEquals($dateTimeFixture, $this->subject->_get('dateProperty2')); } /** * @test */ - public function getDateProperty3ReturnsInitialValueForDateTime() + public function getDateProperty3ReturnsInitialValueForDateTime(): void { self::assertEquals( null, @@ -119,22 +113,18 @@ public function getDateProperty3ReturnsInitialValueForDateTime() /** * @test */ - public function setDateProperty3ForDateTimeSetsDateProperty3() + public function setDateProperty3ForDateTimeSetsDateProperty3(): void { $dateTimeFixture = new \DateTime(); $this->subject->setDateProperty3($dateTimeFixture); - self::assertAttributeEquals( - $dateTimeFixture, - 'dateProperty3', - $this->subject - ); + self::assertEquals($dateTimeFixture, $this->subject->_get('dateProperty3')); } /** * @test */ - public function getDateProperty4ReturnsInitialValueForDateTime() + public function getDateProperty4ReturnsInitialValueForDateTime(): void { self::assertEquals( null, @@ -145,15 +135,11 @@ public function getDateProperty4ReturnsInitialValueForDateTime() /** * @test */ - public function setDateProperty4ForDateTimeSetsDateProperty4() + public function setDateProperty4ForDateTimeSetsDateProperty4(): void { $dateTimeFixture = new \DateTime(); $this->subject->setDateProperty4($dateTimeFixture); - self::assertAttributeEquals( - $dateTimeFixture, - 'dateProperty4', - $this->subject - ); + self::assertEquals($dateTimeFixture, $this->subject->_get('dateProperty4')); } } diff --git a/Tests/Fixtures/TestExtensions/test_extension/Tests/Unit/Domain/Model/Child3Test.php b/Tests/Fixtures/TestExtensions/test_extension/Tests/Unit/Domain/Model/Child3Test.php index a237d9fd1..ce38730f7 100644 --- a/Tests/Fixtures/TestExtensions/test_extension/Tests/Unit/Domain/Model/Child3Test.php +++ b/Tests/Fixtures/TestExtensions/test_extension/Tests/Unit/Domain/Model/Child3Test.php @@ -3,6 +3,8 @@ namespace FIXTURE\TestExtension\Tests\Unit\Domain\Model; +use PHPUnit\Framework\MockObject\MockObject; +use TYPO3\TestingFramework\Core\AccessibleObjectInterface; use TYPO3\TestingFramework\Core\Unit\UnitTestCase; /** @@ -13,17 +15,21 @@ class Child3Test extends UnitTestCase { /** - * @var \FIXTURE\TestExtension\Domain\Model\Child3 + * @var \FIXTURE\TestExtension\Domain\Model\Child3|MockObject|AccessibleObjectInterface */ protected $subject; - protected function setUp() + protected function setUp(): void { parent::setUp(); - $this->subject = new \FIXTURE\TestExtension\Domain\Model\Child3(); + + $this->subject = $this->getAccessibleMock( + \FIXTURE\TestExtension\Domain\Model\Child3::class, + ['dummy'] + ); } - protected function tearDown() + protected function tearDown(): void { parent::tearDown(); } @@ -31,7 +37,7 @@ protected function tearDown() /** * @test */ - public function getNameReturnsInitialValueForString() + public function getNameReturnsInitialValueForString(): void { self::assertSame( '', @@ -42,21 +48,17 @@ public function getNameReturnsInitialValueForString() /** * @test */ - public function setNameForStringSetsName() + public function setNameForStringSetsName(): void { $this->subject->setName('Conceived at T3CON10'); - self::assertAttributeEquals( - 'Conceived at T3CON10', - 'name', - $this->subject - ); + self::assertEquals('Conceived at T3CON10', $this->subject->_get('name')); } /** * @test */ - public function getPasswordReturnsInitialValueForString() + public function getPasswordReturnsInitialValueForString(): void { self::assertSame( '', @@ -67,21 +69,17 @@ public function getPasswordReturnsInitialValueForString() /** * @test */ - public function setPasswordForStringSetsPassword() + public function setPasswordForStringSetsPassword(): void { $this->subject->setPassword('Conceived at T3CON10'); - self::assertAttributeEquals( - 'Conceived at T3CON10', - 'password', - $this->subject - ); + self::assertEquals('Conceived at T3CON10', $this->subject->_get('password')); } /** * @test */ - public function getImagePropertyReturnsInitialValueForFileReference() + public function getImagePropertyReturnsInitialValueForFileReference(): void { self::assertEquals( null, @@ -92,15 +90,11 @@ public function getImagePropertyReturnsInitialValueForFileReference() /** * @test */ - public function setImagePropertyForFileReferenceSetsImageProperty() + public function setImagePropertyForFileReferenceSetsImageProperty(): void { $fileReferenceFixture = new \TYPO3\CMS\Extbase\Domain\Model\FileReference(); $this->subject->setImageProperty($fileReferenceFixture); - self::assertAttributeEquals( - $fileReferenceFixture, - 'imageProperty', - $this->subject - ); + self::assertEquals($fileReferenceFixture, $this->subject->_get('imageProperty')); } } diff --git a/Tests/Fixtures/TestExtensions/test_extension/Tests/Unit/Domain/Model/Child4Test.php b/Tests/Fixtures/TestExtensions/test_extension/Tests/Unit/Domain/Model/Child4Test.php index 6c5e144af..4e080d1b2 100644 --- a/Tests/Fixtures/TestExtensions/test_extension/Tests/Unit/Domain/Model/Child4Test.php +++ b/Tests/Fixtures/TestExtensions/test_extension/Tests/Unit/Domain/Model/Child4Test.php @@ -3,6 +3,8 @@ namespace FIXTURE\TestExtension\Tests\Unit\Domain\Model; +use PHPUnit\Framework\MockObject\MockObject; +use TYPO3\TestingFramework\Core\AccessibleObjectInterface; use TYPO3\TestingFramework\Core\Unit\UnitTestCase; /** @@ -13,17 +15,21 @@ class Child4Test extends UnitTestCase { /** - * @var \FIXTURE\TestExtension\Domain\Model\Child4 + * @var \FIXTURE\TestExtension\Domain\Model\Child4|MockObject|AccessibleObjectInterface */ protected $subject; - protected function setUp() + protected function setUp(): void { parent::setUp(); - $this->subject = new \FIXTURE\TestExtension\Domain\Model\Child4(); + + $this->subject = $this->getAccessibleMock( + \FIXTURE\TestExtension\Domain\Model\Child4::class, + ['dummy'] + ); } - protected function tearDown() + protected function tearDown(): void { parent::tearDown(); } @@ -31,7 +37,7 @@ protected function tearDown() /** * @test */ - public function getNameReturnsInitialValueForString() + public function getNameReturnsInitialValueForString(): void { self::assertSame( '', @@ -42,21 +48,17 @@ public function getNameReturnsInitialValueForString() /** * @test */ - public function setNameForStringSetsName() + public function setNameForStringSetsName(): void { $this->subject->setName('Conceived at T3CON10'); - self::assertAttributeEquals( - 'Conceived at T3CON10', - 'name', - $this->subject - ); + self::assertEquals('Conceived at T3CON10', $this->subject->_get('name')); } /** * @test */ - public function getFilePropertyReturnsInitialValueForFileReference() + public function getFilePropertyReturnsInitialValueForFileReference(): void { self::assertEquals( null, @@ -67,15 +69,11 @@ public function getFilePropertyReturnsInitialValueForFileReference() /** * @test */ - public function setFilePropertyForFileReferenceSetsFileProperty() + public function setFilePropertyForFileReferenceSetsFileProperty(): void { $fileReferenceFixture = new \TYPO3\CMS\Extbase\Domain\Model\FileReference(); $this->subject->setFileProperty($fileReferenceFixture); - self::assertAttributeEquals( - $fileReferenceFixture, - 'fileProperty', - $this->subject - ); + self::assertEquals($fileReferenceFixture, $this->subject->_get('fileProperty')); } } diff --git a/Tests/Fixtures/TestExtensions/test_extension/Tests/Unit/Domain/Model/MainTest.php b/Tests/Fixtures/TestExtensions/test_extension/Tests/Unit/Domain/Model/MainTest.php index c38d8aa77..331b4b6e1 100644 --- a/Tests/Fixtures/TestExtensions/test_extension/Tests/Unit/Domain/Model/MainTest.php +++ b/Tests/Fixtures/TestExtensions/test_extension/Tests/Unit/Domain/Model/MainTest.php @@ -3,6 +3,8 @@ namespace FIXTURE\TestExtension\Tests\Unit\Domain\Model; +use PHPUnit\Framework\MockObject\MockObject; +use TYPO3\TestingFramework\Core\AccessibleObjectInterface; use TYPO3\TestingFramework\Core\Unit\UnitTestCase; /** @@ -13,17 +15,21 @@ class MainTest extends UnitTestCase { /** - * @var \FIXTURE\TestExtension\Domain\Model\Main + * @var \FIXTURE\TestExtension\Domain\Model\Main|MockObject|AccessibleObjectInterface */ protected $subject; - protected function setUp() + protected function setUp(): void { parent::setUp(); - $this->subject = new \FIXTURE\TestExtension\Domain\Model\Main(); + + $this->subject = $this->getAccessibleMock( + \FIXTURE\TestExtension\Domain\Model\Main::class, + ['dummy'] + ); } - protected function tearDown() + protected function tearDown(): void { parent::tearDown(); } @@ -31,7 +37,7 @@ protected function tearDown() /** * @test */ - public function getNameReturnsInitialValueForString() + public function getNameReturnsInitialValueForString(): void { self::assertSame( '', @@ -42,21 +48,17 @@ public function getNameReturnsInitialValueForString() /** * @test */ - public function setNameForStringSetsName() + public function setNameForStringSetsName(): void { $this->subject->setName('Conceived at T3CON10'); - self::assertAttributeEquals( - 'Conceived at T3CON10', - 'name', - $this->subject - ); + self::assertEquals('Conceived at T3CON10', $this->subject->_get('name')); } /** * @test */ - public function getIdentifierReturnsInitialValueForString() + public function getIdentifierReturnsInitialValueForString(): void { self::assertSame( '', @@ -67,21 +69,17 @@ public function getIdentifierReturnsInitialValueForString() /** * @test */ - public function setIdentifierForStringSetsIdentifier() + public function setIdentifierForStringSetsIdentifier(): void { $this->subject->setIdentifier('Conceived at T3CON10'); - self::assertAttributeEquals( - 'Conceived at T3CON10', - 'identifier', - $this->subject - ); + self::assertEquals('Conceived at T3CON10', $this->subject->_get('identifier')); } /** * @test */ - public function getDescriptionReturnsInitialValueForString() + public function getDescriptionReturnsInitialValueForString(): void { self::assertSame( '', @@ -92,21 +90,17 @@ public function getDescriptionReturnsInitialValueForString() /** * @test */ - public function setDescriptionForStringSetsDescription() + public function setDescriptionForStringSetsDescription(): void { $this->subject->setDescription('Conceived at T3CON10'); - self::assertAttributeEquals( - 'Conceived at T3CON10', - 'description', - $this->subject - ); + self::assertEquals('Conceived at T3CON10', $this->subject->_get('description')); } /** * @test */ - public function getMyDateReturnsInitialValueForDateTime() + public function getMyDateReturnsInitialValueForDateTime(): void { self::assertEquals( null, @@ -117,22 +111,18 @@ public function getMyDateReturnsInitialValueForDateTime() /** * @test */ - public function setMyDateForDateTimeSetsMyDate() + public function setMyDateForDateTimeSetsMyDate(): void { $dateTimeFixture = new \DateTime(); $this->subject->setMyDate($dateTimeFixture); - self::assertAttributeEquals( - $dateTimeFixture, - 'myDate', - $this->subject - ); + self::assertEquals($dateTimeFixture, $this->subject->_get('myDate')); } /** * @test */ - public function getMailReturnsInitialValueForString() + public function getMailReturnsInitialValueForString(): void { self::assertSame( '', @@ -143,21 +133,17 @@ public function getMailReturnsInitialValueForString() /** * @test */ - public function setMailForStringSetsMail() + public function setMailForStringSetsMail(): void { $this->subject->setMail('Conceived at T3CON10'); - self::assertAttributeEquals( - 'Conceived at T3CON10', - 'mail', - $this->subject - ); + self::assertEquals('Conceived at T3CON10', $this->subject->_get('mail')); } /** * @test */ - public function getChild1ReturnsInitialValueForChild1() + public function getChild1ReturnsInitialValueForChild1(): void { self::assertEquals( null, @@ -168,22 +154,18 @@ public function getChild1ReturnsInitialValueForChild1() /** * @test */ - public function setChild1ForChild1SetsChild1() + public function setChild1ForChild1SetsChild1(): void { $child1Fixture = new \FIXTURE\TestExtension\Domain\Model\Child1(); $this->subject->setChild1($child1Fixture); - self::assertAttributeEquals( - $child1Fixture, - 'child1', - $this->subject - ); + self::assertEquals($child1Fixture, $this->subject->_get('child1')); } /** * @test */ - public function getChildren2ReturnsInitialValueForChild2() + public function getChildren2ReturnsInitialValueForChild2(): void { $newObjectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); self::assertEquals( @@ -195,33 +177,29 @@ public function getChildren2ReturnsInitialValueForChild2() /** * @test */ - public function setChildren2ForObjectStorageContainingChild2SetsChildren2() + public function setChildren2ForObjectStorageContainingChild2SetsChildren2(): void { $children2 = new \FIXTURE\TestExtension\Domain\Model\Child2(); $objectStorageHoldingExactlyOneChildren2 = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); $objectStorageHoldingExactlyOneChildren2->attach($children2); $this->subject->setChildren2($objectStorageHoldingExactlyOneChildren2); - self::assertAttributeEquals( - $objectStorageHoldingExactlyOneChildren2, - 'children2', - $this->subject - ); + self::assertEquals($objectStorageHoldingExactlyOneChildren2, $this->subject->_get('children2')); } /** * @test */ - public function addChildren2ToObjectStorageHoldingChildren2() + public function addChildren2ToObjectStorageHoldingChildren2(): void { $children2 = new \FIXTURE\TestExtension\Domain\Model\Child2(); $children2ObjectStorageMock = $this->getMockBuilder(\TYPO3\CMS\Extbase\Persistence\ObjectStorage::class) - ->setMethods(['attach']) + ->onlyMethods(['attach']) ->disableOriginalConstructor() ->getMock(); $children2ObjectStorageMock->expects(self::once())->method('attach')->with(self::equalTo($children2)); - $this->inject($this->subject, 'children2', $children2ObjectStorageMock); + $this->subject->_set('children2', $children2ObjectStorageMock); $this->subject->addChildren2($children2); } @@ -229,16 +207,16 @@ public function addChildren2ToObjectStorageHoldingChildren2() /** * @test */ - public function removeChildren2FromObjectStorageHoldingChildren2() + public function removeChildren2FromObjectStorageHoldingChildren2(): void { $children2 = new \FIXTURE\TestExtension\Domain\Model\Child2(); $children2ObjectStorageMock = $this->getMockBuilder(\TYPO3\CMS\Extbase\Persistence\ObjectStorage::class) - ->setMethods(['detach']) + ->onlyMethods(['detach']) ->disableOriginalConstructor() ->getMock(); $children2ObjectStorageMock->expects(self::once())->method('detach')->with(self::equalTo($children2)); - $this->inject($this->subject, 'children2', $children2ObjectStorageMock); + $this->subject->_set('children2', $children2ObjectStorageMock); $this->subject->removeChildren2($children2); } @@ -246,7 +224,7 @@ public function removeChildren2FromObjectStorageHoldingChildren2() /** * @test */ - public function getChild3ReturnsInitialValueForChild3() + public function getChild3ReturnsInitialValueForChild3(): void { self::assertEquals( null, @@ -257,22 +235,18 @@ public function getChild3ReturnsInitialValueForChild3() /** * @test */ - public function setChild3ForChild3SetsChild3() + public function setChild3ForChild3SetsChild3(): void { $child3Fixture = new \FIXTURE\TestExtension\Domain\Model\Child3(); $this->subject->setChild3($child3Fixture); - self::assertAttributeEquals( - $child3Fixture, - 'child3', - $this->subject - ); + self::assertEquals($child3Fixture, $this->subject->_get('child3')); } /** * @test */ - public function getChildren4ReturnsInitialValueForChild4() + public function getChildren4ReturnsInitialValueForChild4(): void { $newObjectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); self::assertEquals( @@ -284,33 +258,29 @@ public function getChildren4ReturnsInitialValueForChild4() /** * @test */ - public function setChildren4ForObjectStorageContainingChild4SetsChildren4() + public function setChildren4ForObjectStorageContainingChild4SetsChildren4(): void { $children4 = new \FIXTURE\TestExtension\Domain\Model\Child4(); $objectStorageHoldingExactlyOneChildren4 = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); $objectStorageHoldingExactlyOneChildren4->attach($children4); $this->subject->setChildren4($objectStorageHoldingExactlyOneChildren4); - self::assertAttributeEquals( - $objectStorageHoldingExactlyOneChildren4, - 'children4', - $this->subject - ); + self::assertEquals($objectStorageHoldingExactlyOneChildren4, $this->subject->_get('children4')); } /** * @test */ - public function addChildren4ToObjectStorageHoldingChildren4() + public function addChildren4ToObjectStorageHoldingChildren4(): void { $children4 = new \FIXTURE\TestExtension\Domain\Model\Child4(); $children4ObjectStorageMock = $this->getMockBuilder(\TYPO3\CMS\Extbase\Persistence\ObjectStorage::class) - ->setMethods(['attach']) + ->onlyMethods(['attach']) ->disableOriginalConstructor() ->getMock(); $children4ObjectStorageMock->expects(self::once())->method('attach')->with(self::equalTo($children4)); - $this->inject($this->subject, 'children4', $children4ObjectStorageMock); + $this->subject->_set('children4', $children4ObjectStorageMock); $this->subject->addChildren4($children4); } @@ -318,16 +288,16 @@ public function addChildren4ToObjectStorageHoldingChildren4() /** * @test */ - public function removeChildren4FromObjectStorageHoldingChildren4() + public function removeChildren4FromObjectStorageHoldingChildren4(): void { $children4 = new \FIXTURE\TestExtension\Domain\Model\Child4(); $children4ObjectStorageMock = $this->getMockBuilder(\TYPO3\CMS\Extbase\Persistence\ObjectStorage::class) - ->setMethods(['detach']) + ->onlyMethods(['detach']) ->disableOriginalConstructor() ->getMock(); $children4ObjectStorageMock->expects(self::once())->method('detach')->with(self::equalTo($children4)); - $this->inject($this->subject, 'children4', $children4ObjectStorageMock); + $this->subject->_set('children4', $children4ObjectStorageMock); $this->subject->removeChildren4($children4); }