MinifyTemplatesTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Deploy\Test\Unit\Service;
  7. use Magento\Deploy\Service\MinifyTemplates;
  8. use Magento\Framework\App\Utility\Files;
  9. use Magento\Framework\View\Template\Html\MinifierInterface;
  10. use PHPUnit_Framework_MockObject_MockObject as Mock;
  11. /**
  12. * Minify Templates service class unit tests
  13. */
  14. class MinifyTemplatesTest extends \PHPUnit\Framework\TestCase
  15. {
  16. /**
  17. * @var MinifyTemplates
  18. */
  19. private $service;
  20. /**
  21. * @var Files|Mock
  22. */
  23. private $filesUtils;
  24. /**
  25. * @var MinifierInterface|Mock
  26. */
  27. private $htmlMinifier;
  28. /**
  29. * @inheritdoc
  30. */
  31. protected function setUp()
  32. {
  33. $this->filesUtils = $this->createPartialMock(Files::class, ['getPhtmlFiles']);
  34. $this->htmlMinifier = $this->getMockForAbstractClass(
  35. MinifierInterface::class,
  36. ['minify'],
  37. '',
  38. false
  39. );
  40. $this->service = new MinifyTemplates(
  41. $this->filesUtils,
  42. $this->htmlMinifier
  43. );
  44. }
  45. /**
  46. * @see MinifyTemplates::minifyTemplates()
  47. */
  48. public function testMinifyTemplates()
  49. {
  50. $templateMock = "template.phtml";
  51. $templatesMock = [$templateMock];
  52. $this->filesUtils->expects($this->once())
  53. ->method('getPhtmlFiles')
  54. ->with(false, false)
  55. ->willReturn($templatesMock);
  56. $this->htmlMinifier->expects($this->once())->method('minify')->with($templateMock);
  57. $this->assertEquals(1, $this->service->minifyTemplates());
  58. }
  59. }