Your IP : 216.73.216.52


Current Path : /proc/thread-self/root/var/www/surf/TYPO3/src/surf/Tests/Unit/Controller/
Upload File :
Current File : //proc/thread-self/root/var/www/surf/TYPO3/src/surf/Tests/Unit/Controller/VendorControllerTest.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 VendorControllerTest extends UnitTestCase
{
    /**
     * @var \Torresani\Surf\Controller\VendorController|MockObject|AccessibleObjectInterface
     */
    protected $subject;

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

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

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

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

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

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

    /**
     * @test
     */
    public function showActionAssignsTheGivenVendorToView(): void
    {
        $vendor = new \Torresani\Surf\Domain\Model\Vendor();

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

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