From cb50981a2b49d466df935a5ae86391f6f71d7c0d Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 7 Jan 2021 09:01:58 +0100 Subject: [PATCH] Setup unit testing * Add dependency. * Remove empty tearDown() methods. * Fix signature of setUp() to be compatible with recent phpunit. * Temporary fix syntax issues in test files Relates: #8092 --- Tests/Unit/Controller/DateControllerTest.php | 15 +++++---------- Tests/Unit/Controller/EventControllerTest.php | 15 +++++---------- .../Unit/Controller/EventsControllerTest.php | 15 +++++---------- Tests/Unit/Domain/Model/DateTest.php | 7 +------ Tests/Unit/Domain/Model/EventTest.php | 7 +------ Tests/Unit/Domain/Model/EventsTest.php | 19 +++++++------------ Tests/Unit/Domain/Model/OrganizerTest.php | 7 +------ Tests/Unit/Domain/Model/RegionTest.php | 7 +------ composer.json | 4 +++- 9 files changed, 29 insertions(+), 67 deletions(-) diff --git a/Tests/Unit/Controller/DateControllerTest.php b/Tests/Unit/Controller/DateControllerTest.php index d9769de..b9a7ba9 100644 --- a/Tests/Unit/Controller/DateControllerTest.php +++ b/Tests/Unit/Controller/DateControllerTest.php @@ -14,7 +14,7 @@ class DateControllerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase */ protected $subject = null; - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->subject = $this->getMockBuilder(\Wrm\Events\Controller\DateController::class) @@ -23,11 +23,6 @@ class DateControllerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase ->getMock(); } - protected function tearDown() - { - parent::tearDown(); - } - /** * @test */ @@ -38,10 +33,10 @@ class DateControllerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase ->disableOriginalConstructor() ->getMock(); - $dateRepository = $this->getMockBuilder(\::class) - ->setMethods(['findAll']) - ->disableOriginalConstructor() - ->getMock(); + // $dateRepository = $this->getMockBuilder(\::class) + // ->setMethods(['findAll']) + // ->disableOriginalConstructor() + // ->getMock(); $dateRepository->expects(self::once())->method('findAll')->will(self::returnValue($allDates)); $this->inject($this->subject, 'dateRepository', $dateRepository); diff --git a/Tests/Unit/Controller/EventControllerTest.php b/Tests/Unit/Controller/EventControllerTest.php index 6a5309c..5ab1161 100644 --- a/Tests/Unit/Controller/EventControllerTest.php +++ b/Tests/Unit/Controller/EventControllerTest.php @@ -14,7 +14,7 @@ class EventControllerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase */ protected $subject = null; - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->subject = $this->getMockBuilder(\Wrm\Events\Controller\EventController::class) @@ -23,11 +23,6 @@ class EventControllerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase ->getMock(); } - protected function tearDown() - { - parent::tearDown(); - } - /** * @test */ @@ -38,10 +33,10 @@ class EventControllerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase ->disableOriginalConstructor() ->getMock(); - $eventRepository = $this->getMockBuilder(\::class) - ->setMethods(['findAll']) - ->disableOriginalConstructor() - ->getMock(); + // $eventRepository = $this->getMockBuilder(\::class) + // ->setMethods(['findAll']) + // ->disableOriginalConstructor() + // ->getMock(); $eventRepository->expects(self::once())->method('findAll')->will(self::returnValue($allEvents)); $this->inject($this->subject, 'eventRepository', $eventRepository); diff --git a/Tests/Unit/Controller/EventsControllerTest.php b/Tests/Unit/Controller/EventsControllerTest.php index c0c3413..9efe3a9 100644 --- a/Tests/Unit/Controller/EventsControllerTest.php +++ b/Tests/Unit/Controller/EventsControllerTest.php @@ -14,7 +14,7 @@ class EventsControllerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCas */ protected $subject = null; - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->subject = $this->getMockBuilder(\Wrm\Events\Controller\EventsController::class) @@ -23,11 +23,6 @@ class EventsControllerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCas ->getMock(); } - protected function tearDown() - { - parent::tearDown(); - } - /** * @test */ @@ -38,10 +33,10 @@ class EventsControllerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCas ->disableOriginalConstructor() ->getMock(); - $eventsRepository = $this->getMockBuilder(\::class) - ->setMethods(['findAll']) - ->disableOriginalConstructor() - ->getMock(); + // $eventsRepository = $this->getMockBuilder(\::class) + // ->setMethods(['findAll']) + // ->disableOriginalConstructor() + // ->getMock(); $eventsRepository->expects(self::once())->method('findAll')->will(self::returnValue($allEventss)); $this->inject($this->subject, 'eventsRepository', $eventsRepository); diff --git a/Tests/Unit/Domain/Model/DateTest.php b/Tests/Unit/Domain/Model/DateTest.php index da345a6..057c4a0 100644 --- a/Tests/Unit/Domain/Model/DateTest.php +++ b/Tests/Unit/Domain/Model/DateTest.php @@ -14,17 +14,12 @@ class DateTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase */ protected $subject = null; - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->subject = new \Wrm\Events\Domain\Model\Date(); } - protected function tearDown() - { - parent::tearDown(); - } - /** * @test */ diff --git a/Tests/Unit/Domain/Model/EventTest.php b/Tests/Unit/Domain/Model/EventTest.php index d37fe9a..82de42c 100644 --- a/Tests/Unit/Domain/Model/EventTest.php +++ b/Tests/Unit/Domain/Model/EventTest.php @@ -14,17 +14,12 @@ class EventTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase */ protected $subject = null; - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->subject = new \Wrm\Events\Domain\Model\Event(); } - protected function tearDown() - { - parent::tearDown(); - } - /** * @test */ diff --git a/Tests/Unit/Domain/Model/EventsTest.php b/Tests/Unit/Domain/Model/EventsTest.php index 0e8b3a1..25d9e4c 100644 --- a/Tests/Unit/Domain/Model/EventsTest.php +++ b/Tests/Unit/Domain/Model/EventsTest.php @@ -14,17 +14,12 @@ class EventsTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase */ protected $subject = null; - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->subject = new \Wrm\Events\Domain\Model\Events(); } - protected function tearDown() - { - parent::tearDown(); - } - /** * @test */ @@ -507,7 +502,7 @@ class EventsTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase */ public function setDateForObjectStorageContainingSetsDate() { - $date = new (); + // $date = new (); $objectStorageHoldingExactlyOneDate = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); $objectStorageHoldingExactlyOneDate->attach($date); $this->subject->setDate($objectStorageHoldingExactlyOneDate); @@ -524,7 +519,7 @@ class EventsTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase */ public function addDateToObjectStorageHoldingDate() { - $date = new (); + // $date = new (); $dateObjectStorageMock = $this->getMockBuilder(\TYPO3\CMS\Extbase\Persistence\ObjectStorage::class) ->setMethods(['attach']) ->disableOriginalConstructor() @@ -541,7 +536,7 @@ class EventsTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase */ public function removeDateFromObjectStorageHoldingDate() { - $date = new (); + // $date = new (); $dateObjectStorageMock = $this->getMockBuilder(\TYPO3\CMS\Extbase\Persistence\ObjectStorage::class) ->setMethods(['detach']) ->disableOriginalConstructor() @@ -570,7 +565,7 @@ class EventsTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase */ public function setRegionForObjectStorageContainingSetsRegion() { - $region = new (); + // $region = new (); $objectStorageHoldingExactlyOneRegion = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); $objectStorageHoldingExactlyOneRegion->attach($region); $this->subject->setRegion($objectStorageHoldingExactlyOneRegion); @@ -587,7 +582,7 @@ class EventsTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase */ public function addRegionToObjectStorageHoldingRegion() { - $region = new (); + // $region = new (); $regionObjectStorageMock = $this->getMockBuilder(\TYPO3\CMS\Extbase\Persistence\ObjectStorage::class) ->setMethods(['attach']) ->disableOriginalConstructor() @@ -604,7 +599,7 @@ class EventsTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase */ public function removeRegionFromObjectStorageHoldingRegion() { - $region = new (); + // $region = new (); $regionObjectStorageMock = $this->getMockBuilder(\TYPO3\CMS\Extbase\Persistence\ObjectStorage::class) ->setMethods(['detach']) ->disableOriginalConstructor() diff --git a/Tests/Unit/Domain/Model/OrganizerTest.php b/Tests/Unit/Domain/Model/OrganizerTest.php index b52b08f..1d38ff0 100644 --- a/Tests/Unit/Domain/Model/OrganizerTest.php +++ b/Tests/Unit/Domain/Model/OrganizerTest.php @@ -14,17 +14,12 @@ class OrganizerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase */ protected $subject = null; - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->subject = new \Wrm\Events\Domain\Model\Organizer(); } - protected function tearDown() - { - parent::tearDown(); - } - /** * @test */ diff --git a/Tests/Unit/Domain/Model/RegionTest.php b/Tests/Unit/Domain/Model/RegionTest.php index e74fb8f..0811d91 100644 --- a/Tests/Unit/Domain/Model/RegionTest.php +++ b/Tests/Unit/Domain/Model/RegionTest.php @@ -14,17 +14,12 @@ class RegionTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase */ protected $subject = null; - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->subject = new \Wrm\Events\Domain\Model\Region(); } - protected function tearDown() - { - parent::tearDown(); - } - /** * @test */ diff --git a/composer.json b/composer.json index 0909f31..7431679 100644 --- a/composer.json +++ b/composer.json @@ -29,6 +29,8 @@ } }, "require-dev": { - "squizlabs/php_codesniffer": "^3.5" + "squizlabs/php_codesniffer": "^3.5", + "phpunit/phpunit": "^9.0", + "typo3/testing-framework": "^6.6" } }