*/ class TeaBeverageRepositoryTest extends \Tx_Phpunit_Database_TestCase { /** * @var TeaBeverageRepository|\PHPUnit_Framework_MockObject_MockObject */ protected $subject = null; protected function setUp() { if (!$this->createDatabase()) { self::markTestSkipped('Test database could not be created.'); } $this->importExtensions(array('tea')); /** @var ObjectManager $objectManager */ $objectManager = GeneralUtility::makeInstance(ObjectManager::class); // We are using the object manager instead of new so that the dependencies get injected. // In a unit test, we would inject the mocked dependencies instead. $this->subject = $objectManager->get(TeaBeverageRepository::class); } protected function tearDown() { $this->dropDatabase(); $this->switchToTypo3Database(); } /** * @test */ public function findAllForNoRecordsReturnsEmptyContainer() { $container = $this->subject->findAll(); self::assertSame( 0, $container->count() ); } /** * @test */ public function findAllWithOneRecordFindsThisRecord() { $this->importDataSet(__DIR__ . '/Fixtures/TeaBeverages.xml'); $container = $this->subject->findAll(); /** @var TeaBeverage $first */ $first = $container->getFirst(); self::assertSame( 1, $container->count() ); self::assertSame( 1, $first->getUid() ); } /** * @test */ public function findByUidForExistingRecordReturnsModelWithData() { $this->importDataSet(__DIR__ . '/Fixtures/TeaBeverages.xml'); /** @var TeaBeverage $model */ $model = $this->subject->findByUid(1); self::assertNotNull($model); self::assertEquals( 3.141, $model->getSize(), '', 0.001 ); } }