mirror of https://github.com/FriendsOfTYPO3/tea.git synced 2024-11-22 23:16:13 +01:00

[CLEANUP] Switch to Prophecy

This commit is contained in:
Oliver Klee 2017-05-05 19:12:44 +02:00
parent 15dc45eca7
commit 1c1f846858
3 changed files with 28 additions and 11 deletions

View file

@ -16,6 +16,8 @@ namespace OliverKlee\Tea\Tests\Unit\Controller;
use OliverKlee\Tea\Controller\TestimonialController; use OliverKlee\Tea\Controller\TestimonialController;
use OliverKlee\Tea\Domain\Repository\TestimonialRepository; use OliverKlee\Tea\Domain\Repository\TestimonialRepository;
use Prophecy\Prophecy\ObjectProphecy;
use Prophecy\Prophecy\ProphecySubjectInterface;
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface; use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage; use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
@ -37,12 +39,22 @@ class TestimonialControllerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
protected $subject = null; protected $subject = null;
/** /**
* @var ViewInterface|\PHPUnit_Framework_MockObject_MockObject * @var ViewInterface|ObjectProphecy
*/
protected $viewProphecy = null;
/**
* @var ViewInterface|ProphecySubjectInterface
*/ */
protected $view = null; protected $view = null;
/** /**
* @var TestimonialRepository|\PHPUnit_Framework_MockObject_MockObject * @var TestimonialRepository|ObjectProphecy
*/
protected $testimonialRepositoryProphecy = null;
/**
* @var TestimonialRepository|ProphecySubjectInterface
*/ */
protected $testimonialRepository = null; protected $testimonialRepository = null;
@ -50,10 +62,12 @@ class TestimonialControllerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
{ {
$this->subject = new TestimonialController(); $this->subject = new TestimonialController();
$this->view = $this->getMock(ViewInterface::class); $this->viewProphecy = $this->prophesize(ViewInterface::class);
$this->view = $this->viewProphecy->reveal();
$this->inject($this->subject, 'view', $this->view); $this->inject($this->subject, 'view', $this->view);
$this->testimonialRepository = $this->getMock(TestimonialRepository::class, [], [], '', false); $this->testimonialRepositoryProphecy = $this->prophesize(TestimonialRepository::class);
$this->testimonialRepository = $this->testimonialRepositoryProphecy->reveal();
$this->inject($this->subject, 'testimonialRepository', $this->testimonialRepository); $this->inject($this->subject, 'testimonialRepository', $this->testimonialRepository);
} }
@ -71,10 +85,9 @@ class TestimonialControllerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
public function indexActionPassesAllTestimonialsAsTestimonialsToView() public function indexActionPassesAllTestimonialsAsTestimonialsToView()
{ {
$allTestimonials = new ObjectStorage(); $allTestimonials = new ObjectStorage();
$this->testimonialRepository->expects(self::any())->method('findAll') $this->testimonialRepositoryProphecy->findAll()->willReturn($allTestimonials);
->will(self::returnValue($allTestimonials));
$this->view->expects(self::once())->method('assign')->with('testimonials', $allTestimonials); $this->viewProphecy->assign('testimonials', $allTestimonials)->shouldBeCalled();
$this->subject->indexAction(); $this->subject->indexAction();
} }

View file

@ -15,6 +15,7 @@ namespace OliverKlee\Tea\Tests\Unit\Domain\Repository;
*/ */
use OliverKlee\Tea\Domain\Repository\TeaBeverageRepository; use OliverKlee\Tea\Domain\Repository\TeaBeverageRepository;
use Prophecy\Prophecy\ProphecySubjectInterface;
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface; use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
use TYPO3\CMS\Extbase\Persistence\Repository; use TYPO3\CMS\Extbase\Persistence\Repository;
@ -36,13 +37,14 @@ class TeaBeverageRepositoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
protected $subject; protected $subject;
/** /**
* @var ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject * @var ObjectManagerInterface|ProphecySubjectInterface
*/ */
protected $objectManager = null; protected $objectManager = null;
protected function setUp() protected function setUp()
{ {
$this->objectManager = $this->getMock(ObjectManagerInterface::class); $objectManagerProphecy = $this->prophesize(ObjectManagerInterface::class);
$this->objectManager = $objectManagerProphecy->reveal();
$this->subject = new TeaBeverageRepository($this->objectManager); $this->subject = new TeaBeverageRepository($this->objectManager);
} }

View file

@ -15,6 +15,7 @@ namespace OliverKlee\Tea\Tests\Unit\Domain\Repository;
*/ */
use OliverKlee\Tea\Domain\Repository\TestimonialRepository; use OliverKlee\Tea\Domain\Repository\TestimonialRepository;
use Prophecy\Prophecy\ProphecySubjectInterface;
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface; use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
use TYPO3\CMS\Extbase\Persistence\Repository; use TYPO3\CMS\Extbase\Persistence\Repository;
@ -36,13 +37,14 @@ class TestimonialRepositoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
protected $subject; protected $subject;
/** /**
* @var ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject * @var ObjectManagerInterface|ProphecySubjectInterface
*/ */
protected $objectManager = null; protected $objectManager = null;
protected function setUp() protected function setUp()
{ {
$this->objectManager = $this->getMock(ObjectManagerInterface::class); $objectManagerProphecy = $this->prophesize(ObjectManagerInterface::class);
$this->objectManager = $objectManagerProphecy->reveal();
$this->subject = new TestimonialRepository($this->objectManager); $this->subject = new TestimonialRepository($this->objectManager);
} }