2015-10-25 11:34:00 +01:00
|
|
|
<?php
|
2017-09-08 18:04:28 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2015-10-25 11:34:00 +01:00
|
|
|
namespace OliverKlee\Tea\Tests\Functional\Domain\Repository;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the TYPO3 CMS project.
|
|
|
|
*
|
|
|
|
* It is free software; you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU General Public License, either version 2
|
|
|
|
* of the License, or any later version.
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please read the
|
|
|
|
* LICENSE.txt file that was distributed with this source code.
|
|
|
|
*
|
|
|
|
* The TYPO3 project - inspiring people to share!
|
|
|
|
*/
|
|
|
|
|
|
|
|
use OliverKlee\Tea\Domain\Model\TeaBeverage;
|
|
|
|
use OliverKlee\Tea\Domain\Repository\TeaBeverageRepository;
|
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
|
|
|
use TYPO3\CMS\Extbase\Object\ObjectManager;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test case.
|
|
|
|
*
|
|
|
|
* @author Oliver Klee <typo3-coding@oliverklee.de>
|
|
|
|
*/
|
2017-09-07 16:24:52 +02:00
|
|
|
class TeaBeverageRepositoryTest extends \Nimut\TestingFramework\TestCase\FunctionalTestCase
|
2016-05-07 21:43:25 +02:00
|
|
|
{
|
2016-07-16 21:39:04 +02:00
|
|
|
/**
|
2017-09-07 16:24:52 +02:00
|
|
|
* @var string[]
|
2016-07-16 21:39:04 +02:00
|
|
|
*/
|
2017-09-07 16:24:52 +02:00
|
|
|
protected $testExtensionsToLoad = ['typo3conf/ext/tea'];
|
2016-07-16 21:39:04 +02:00
|
|
|
|
2016-05-07 21:43:25 +02:00
|
|
|
/**
|
|
|
|
* @var TeaBeverageRepository|\PHPUnit_Framework_MockObject_MockObject
|
|
|
|
*/
|
|
|
|
protected $subject = null;
|
2015-10-25 11:34:00 +01:00
|
|
|
|
2016-05-07 21:43:25 +02:00
|
|
|
protected function setUp()
|
|
|
|
{
|
2017-09-07 16:24:52 +02:00
|
|
|
parent::setUp();
|
2015-10-25 11:34:00 +01:00
|
|
|
|
2016-05-07 21:43:25 +02:00
|
|
|
/** @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);
|
|
|
|
}
|
2015-10-25 11:34:00 +01:00
|
|
|
|
2016-05-07 21:43:25 +02:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function findAllForNoRecordsReturnsEmptyContainer()
|
|
|
|
{
|
|
|
|
$container = $this->subject->findAll();
|
2015-10-25 11:34:00 +01:00
|
|
|
|
2016-05-08 14:57:07 +02:00
|
|
|
self::assertCount(0, $container);
|
2016-05-07 21:43:25 +02:00
|
|
|
}
|
2015-10-25 11:34:00 +01:00
|
|
|
|
2016-05-07 21:43:25 +02:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function findAllWithOneRecordFindsThisRecord()
|
|
|
|
{
|
|
|
|
$this->importDataSet(__DIR__ . '/Fixtures/TeaBeverages.xml');
|
2015-10-25 11:34:00 +01:00
|
|
|
|
2016-05-07 21:43:25 +02:00
|
|
|
$container = $this->subject->findAll();
|
|
|
|
/** @var TeaBeverage $first */
|
|
|
|
$first = $container->getFirst();
|
2015-10-25 11:34:00 +01:00
|
|
|
|
2016-05-08 14:57:07 +02:00
|
|
|
self::assertCount(1, $container);
|
|
|
|
self::assertSame(1, $first->getUid());
|
2016-05-07 21:43:25 +02:00
|
|
|
}
|
2015-10-25 11:34:00 +01:00
|
|
|
|
2016-05-07 21:43:25 +02:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function findByUidForExistingRecordReturnsModelWithData()
|
|
|
|
{
|
|
|
|
$this->importDataSet(__DIR__ . '/Fixtures/TeaBeverages.xml');
|
2015-10-25 11:34:00 +01:00
|
|
|
|
2016-05-07 21:43:25 +02:00
|
|
|
/** @var TeaBeverage $model */
|
|
|
|
$model = $this->subject->findByUid(1);
|
2015-10-25 11:34:00 +01:00
|
|
|
|
2016-05-07 21:43:25 +02:00
|
|
|
self::assertNotNull($model);
|
|
|
|
self::assertEquals(
|
|
|
|
3.141,
|
|
|
|
$model->getSize(),
|
|
|
|
'',
|
|
|
|
0.001
|
|
|
|
);
|
|
|
|
}
|
2015-10-25 11:34:00 +01:00
|
|
|
}
|