From 31b1044fb57d7655f63c0733030bb4c5c1f16bdd Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Sun, 8 May 2016 14:57:07 +0200 Subject: [PATCH] [CLEANUP] Rework tests to match the TDD examples --- .../Repository/TeaBeverageRepositoryTest.php | 15 ++------- .../Repository/TestimonialRepositoryTest.php | 20 +++--------- Tests/Functional/Utility/FileUtilityTest.php | 15 ++------- Tests/Unit/Domain/Model/AdditionTest.php | 14 +++----- Tests/Unit/Domain/Model/TeaBeverageTest.php | 9 +++--- Tests/Unit/Domain/Model/TeaTypeTest.php | 25 +++++---------- Tests/Unit/Domain/Model/TestimonialTest.php | 32 +++++++------------ .../Repository/TeaBeverageRepositoryTest.php | 7 ++-- .../Repository/TestimonialRepositoryTest.php | 7 ++-- 9 files changed, 44 insertions(+), 100 deletions(-) diff --git a/Tests/Functional/Domain/Repository/TeaBeverageRepositoryTest.php b/Tests/Functional/Domain/Repository/TeaBeverageRepositoryTest.php index a03d121..b69d6e8 100644 --- a/Tests/Functional/Domain/Repository/TeaBeverageRepositoryTest.php +++ b/Tests/Functional/Domain/Repository/TeaBeverageRepositoryTest.php @@ -58,10 +58,7 @@ class TeaBeverageRepositoryTest extends \Tx_Phpunit_Database_TestCase { $container = $this->subject->findAll(); - self::assertSame( - 0, - $container->count() - ); + self::assertCount(0, $container); } /** @@ -75,14 +72,8 @@ class TeaBeverageRepositoryTest extends \Tx_Phpunit_Database_TestCase /** @var TeaBeverage $first */ $first = $container->getFirst(); - self::assertSame( - 1, - $container->count() - ); - self::assertSame( - 1, - $first->getUid() - ); + self::assertCount(1, $container); + self::assertSame(1, $first->getUid()); } /** diff --git a/Tests/Functional/Domain/Repository/TestimonialRepositoryTest.php b/Tests/Functional/Domain/Repository/TestimonialRepositoryTest.php index 4513b75..06a3cb5 100644 --- a/Tests/Functional/Domain/Repository/TestimonialRepositoryTest.php +++ b/Tests/Functional/Domain/Repository/TestimonialRepositoryTest.php @@ -59,10 +59,7 @@ class TestimonialRepositoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { $container = $this->subject->findAll(); - self::assertSame( - 0, - $container->count() - ); + self::assertCount(0, $container); } /** @@ -76,14 +73,8 @@ class TestimonialRepositoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase /** @var Testimonial $first */ $first = $container->getFirst(); - self::assertSame( - 1, - $container->count() - ); - self::assertSame( - $uid, - $first->getUid() - ); + self::assertCount(1, $container); + self::assertSame($uid, $first->getUid()); } /** @@ -100,9 +91,6 @@ class TestimonialRepositoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase $model = $this->subject->findByUid($uid); self::assertNotNull($model); - self::assertSame( - $text, - $model->getText() - ); + self::assertSame($text, $model->getText()); } } diff --git a/Tests/Functional/Utility/FileUtilityTest.php b/Tests/Functional/Utility/FileUtilityTest.php index 4539fe6..f6f4558 100644 --- a/Tests/Functional/Utility/FileUtilityTest.php +++ b/Tests/Functional/Utility/FileUtilityTest.php @@ -66,10 +66,7 @@ class FileUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { $this->subject->concatenate($this->targetFilePath, []); - self::assertSame( - '', - file_get_contents($this->targetFilePath) - ); + self::assertSame('', file_get_contents($this->targetFilePath)); } /** @@ -84,10 +81,7 @@ class FileUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase $this->subject->concatenate($this->targetFilePath, [$sourceFileName]); - self::assertSame( - '', - file_get_contents($this->targetFilePath) - ); + self::assertSame('', file_get_contents($this->targetFilePath)); } /** @@ -102,10 +96,7 @@ class FileUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase $this->subject->concatenate($this->targetFilePath, [$sourceFileName]); - self::assertSame( - $contents, - file_get_contents($this->targetFilePath) - ); + self::assertSame($contents, file_get_contents($this->targetFilePath)); } /** diff --git a/Tests/Unit/Domain/Model/AdditionTest.php b/Tests/Unit/Domain/Model/AdditionTest.php index 342a084..9ba54af 100644 --- a/Tests/Unit/Domain/Model/AdditionTest.php +++ b/Tests/Unit/Domain/Model/AdditionTest.php @@ -36,10 +36,7 @@ class AdditionTest extends \TYPO3\CMS\Core\Tests\UnitTestCase */ public function getTitleInitiallyReturnsEmptyString() { - self::assertSame( - '', - $this->subject->getTitle() - ); + self::assertSame('', $this->subject->getTitle()); } /** @@ -47,11 +44,10 @@ class AdditionTest extends \TYPO3\CMS\Core\Tests\UnitTestCase */ public function setTitleSetsTitle() { - $this->subject->setTitle('foo bar'); + $title = 'foo bar'; - self::assertSame( - 'foo bar', - $this->subject->getTitle() - ); + $this->subject->setTitle($title); + + self::assertSame($title, $this->subject->getTitle()); } } diff --git a/Tests/Unit/Domain/Model/TeaBeverageTest.php b/Tests/Unit/Domain/Model/TeaBeverageTest.php index 68c702c..be6fc0c 100644 --- a/Tests/Unit/Domain/Model/TeaBeverageTest.php +++ b/Tests/Unit/Domain/Model/TeaBeverageTest.php @@ -49,12 +49,11 @@ class TeaBeverageTest extends \TYPO3\CMS\Core\Tests\UnitTestCase */ public function setSizeSetsSize() { - $this->subject->setSize(1234.56); + $size = 1234.56; - self::assertSame( - 1234.56, - $this->subject->getSize() - ); + $this->subject->setSize($size); + + self::assertSame($size, $this->subject->getSize()); } /** diff --git a/Tests/Unit/Domain/Model/TeaTypeTest.php b/Tests/Unit/Domain/Model/TeaTypeTest.php index 3f626d5..e93df61 100644 --- a/Tests/Unit/Domain/Model/TeaTypeTest.php +++ b/Tests/Unit/Domain/Model/TeaTypeTest.php @@ -36,10 +36,7 @@ class TeaTypeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase */ public function getTitleInitiallyReturnsEmptyString() { - self::assertSame( - '', - $this->subject->getTitle() - ); + self::assertSame('', $this->subject->getTitle()); } /** @@ -47,12 +44,11 @@ class TeaTypeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase */ public function setTitleSetsTitle() { - $this->subject->setTitle('foo bar'); + $title = 'foo bar'; - self::assertSame( - 'foo bar', - $this->subject->getTitle() - ); + $this->subject->setTitle($title); + + self::assertSame($title, $this->subject->getTitle()); } /** @@ -60,10 +56,7 @@ class TeaTypeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase */ public function getCaffeinatedInitiallyReturnsFalse() { - self::assertSame( - false, - $this->subject->getCaffeinated() - ); + self::assertFalse($this->subject->getCaffeinated()); } /** @@ -72,9 +65,7 @@ class TeaTypeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase public function setCaffeinatedSetsCaffeinated() { $this->subject->setCaffeinated(true); - self::assertSame( - true, - $this->subject->getCaffeinated() - ); + + self::assertTrue($this->subject->getCaffeinated()); } } diff --git a/Tests/Unit/Domain/Model/TestimonialTest.php b/Tests/Unit/Domain/Model/TestimonialTest.php index c437f37..602aa00 100644 --- a/Tests/Unit/Domain/Model/TestimonialTest.php +++ b/Tests/Unit/Domain/Model/TestimonialTest.php @@ -36,9 +36,7 @@ class TestimonialTest extends \TYPO3\CMS\Core\Tests\UnitTestCase */ public function getDateOfPostingInitiallyReturnsNull() { - self::assertNull( - $this->subject->getDateOfPosting() - ); + self::assertNull($this->subject->getDateOfPosting()); } /** @@ -60,10 +58,7 @@ class TestimonialTest extends \TYPO3\CMS\Core\Tests\UnitTestCase */ public function getNumberOfConsumedCupsInitiallyReturnsZero() { - self::assertSame( - 0, - $this->subject->getNumberOfConsumedCups() - ); + self::assertSame(0, $this->subject->getNumberOfConsumedCups()); } /** @@ -71,12 +66,11 @@ class TestimonialTest extends \TYPO3\CMS\Core\Tests\UnitTestCase */ public function setNumberOfConsumedCupsSetsNumberOfConsumedCups() { - $this->subject->setNumberOfConsumedCups(123456); + $number = 123456; - self::assertSame( - 123456, - $this->subject->getNumberOfConsumedCups() - ); + $this->subject->setNumberOfConsumedCups($number); + + self::assertSame($number, $this->subject->getNumberOfConsumedCups()); } /** @@ -84,10 +78,7 @@ class TestimonialTest extends \TYPO3\CMS\Core\Tests\UnitTestCase */ public function getTextInitiallyReturnsEmptyString() { - self::assertSame( - '', - $this->subject->getText() - ); + self::assertSame('', $this->subject->getText()); } /** @@ -95,11 +86,10 @@ class TestimonialTest extends \TYPO3\CMS\Core\Tests\UnitTestCase */ public function setTextSetsText() { - $this->subject->setText('foo bar'); + $text = 'foo bar'; - self::assertSame( - 'foo bar', - $this->subject->getText() - ); + $this->subject->setText($text); + + self::assertSame($text, $this->subject->getText()); } } diff --git a/Tests/Unit/Domain/Repository/TeaBeverageRepositoryTest.php b/Tests/Unit/Domain/Repository/TeaBeverageRepositoryTest.php index e8c1854..9231a47 100644 --- a/Tests/Unit/Domain/Repository/TeaBeverageRepositoryTest.php +++ b/Tests/Unit/Domain/Repository/TeaBeverageRepositoryTest.php @@ -16,6 +16,7 @@ namespace OliverKlee\Tea\Tests\Unit\Domain\Repository; use OliverKlee\Tea\Domain\Repository\TeaBeverageRepository; use TYPO3\CMS\Extbase\Object\ObjectManagerInterface; +use TYPO3\CMS\Extbase\Persistence\Repository; /** * Test case. @@ -43,10 +44,8 @@ class TeaBeverageRepositoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase /** * @test */ - public function canBeInstantiated() + public function isRepository() { - self::assertNotNull( - $this->subject - ); + self::assertInstanceOf(Repository::class, $this->subject); } } diff --git a/Tests/Unit/Domain/Repository/TestimonialRepositoryTest.php b/Tests/Unit/Domain/Repository/TestimonialRepositoryTest.php index 6a02c59..f59140d 100644 --- a/Tests/Unit/Domain/Repository/TestimonialRepositoryTest.php +++ b/Tests/Unit/Domain/Repository/TestimonialRepositoryTest.php @@ -16,6 +16,7 @@ namespace OliverKlee\Tea\Tests\Unit\Domain\Repository; use OliverKlee\Tea\Domain\Repository\TestimonialRepository; use TYPO3\CMS\Extbase\Object\ObjectManagerInterface; +use TYPO3\CMS\Extbase\Persistence\Repository; /** * Test case. @@ -43,10 +44,8 @@ class TestimonialRepositoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase /** * @test */ - public function canBeInstantiated() + public function isRepository() { - self::assertNotNull( - $this->subject - ); + self::assertInstanceOf(Repository::class, $this->subject); } }