Your IP : 216.73.217.13


Current Path : /var/www/surf/TYPO3/vendor/torresani/surf/Tests/Unit/Controller/
Upload File :
Current File : /var/www/surf/TYPO3/vendor/torresani/surf/Tests/Unit/Controller/DeliveryControllerTest.php

<?php

declare(strict_types=1);

namespace Torresani\Surf\Tests\Unit\Controller;

use PHPUnit\Framework\MockObject\MockObject;
use TYPO3\TestingFramework\Core\AccessibleObjectInterface;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
use TYPO3Fluid\Fluid\View\ViewInterface;

/**
 * Test case
 *
 * @author Roberto Torresani <roberto@torresani.eu>
 */
class DeliveryControllerTest extends UnitTestCase
{
    /**
     * @var \Torresani\Surf\Controller\DeliveryController|MockObject|AccessibleObjectInterface
     */
    protected $subject;

    protected function setUp(): void
    {
        parent::setUp();
        $this->subject = $this->getMockBuilder($this->buildAccessibleProxy(\Torresani\Surf\Controller\DeliveryController::class))
            ->onlyMethods(['redirect', 'forward', 'addFlashMessage'])
            ->disableOriginalConstructor()
            ->getMock();
    }

    protected function tearDown(): void
    {
        parent::tearDown();
    }

    /**
     * @test
     */
    public function listActionFetchesAllDeliveriesFromRepositoryAndAssignsThemToView(): void
    {
        $allDeliveries = $this->getMockBuilder(\TYPO3\CMS\Extbase\Persistence\ObjectStorage::class)
            ->disableOriginalConstructor()
            ->getMock();

        $deliveryRepository = $this->getMockBuilder(\Torresani\Surf\Domain\Repository\DeliveryRepository::class)
            ->onlyMethods(['findAll'])
            ->disableOriginalConstructor()
            ->getMock();
        $deliveryRepository->expects(self::once())->method('findAll')->will(self::returnValue($allDeliveries));
        $this->subject->_set('deliveryRepository', $deliveryRepository);

        $view = $this->getMockBuilder(ViewInterface::class)->getMock();
        $view->expects(self::once())->method('assign')->with('deliveries', $allDeliveries);
        $this->subject->_set('view', $view);

        $this->subject->listAction();
    }

    /**
     * @test
     */
    public function showActionAssignsTheGivenDeliveryToView(): void
    {
        $delivery = new \Torresani\Surf\Domain\Model\Delivery();

        $view = $this->getMockBuilder(ViewInterface::class)->getMock();
        $this->subject->_set('view', $view);
        $view->expects(self::once())->method('assign')->with('delivery', $delivery);

        $this->subject->showAction($delivery);
    }
}