MinifyTemplatesTest.php 1.63 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\Deploy\Test\Unit\Service;

use Magento\Deploy\Service\MinifyTemplates;

use Magento\Framework\App\Utility\Files;
use Magento\Framework\View\Template\Html\MinifierInterface;

use PHPUnit_Framework_MockObject_MockObject as Mock;

/**
 * Minify Templates service class unit tests
 */
class MinifyTemplatesTest extends \PHPUnit\Framework\TestCase
{
    /**
     * @var MinifyTemplates
     */
    private $service;

    /**
     * @var Files|Mock
     */
    private $filesUtils;

    /**
     * @var MinifierInterface|Mock
     */
    private $htmlMinifier;

    /**
     * @inheritdoc
     */
    protected function setUp()
    {
        $this->filesUtils = $this->createPartialMock(Files::class, ['getPhtmlFiles']);

        $this->htmlMinifier = $this->getMockForAbstractClass(
            MinifierInterface::class,
            ['minify'],
            '',
            false
        );

        $this->service = new MinifyTemplates(
            $this->filesUtils,
            $this->htmlMinifier
        );
    }

    /**
     * @see MinifyTemplates::minifyTemplates()
     */
    public function testMinifyTemplates()
    {
        $templateMock = "template.phtml";
        $templatesMock = [$templateMock];

        $this->filesUtils->expects($this->once())
            ->method('getPhtmlFiles')
            ->with(false, false)
            ->willReturn($templatesMock);

        $this->htmlMinifier->expects($this->once())->method('minify')->with($templateMock);

        $this->assertEquals(1, $this->service->minifyTemplates());
    }
}