|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\Customer\Test\Unit\Console\Command; |
| 9 | + |
| 10 | +use Magento\Framework\App\Config\ScopeConfigInterface; |
| 11 | +use Magento\Framework\Filesystem\File\WriteFactory; |
| 12 | +use Magento\Framework\Serialize\Serializer\Json; |
| 13 | +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
| 14 | +use Magento\PageCache\Console\Command\GenerateVclCommand; |
| 15 | +use Magento\PageCache\Model\Varnish\VclGenerator; |
| 16 | +use Magento\PageCache\Model\VclGeneratorInterfaceFactory; |
| 17 | +use PHPUnit\Framework\TestCase; |
| 18 | +use Symfony\Component\Console\Tester\CommandTester; |
| 19 | + |
| 20 | +class GenerateVclCommandInputOptionTest extends TestCase |
| 21 | +{ |
| 22 | + /** |
| 23 | + * @var GenerateVclCommand |
| 24 | + */ |
| 25 | + private $command; |
| 26 | + |
| 27 | + /** |
| 28 | + * @var ObjectManager |
| 29 | + */ |
| 30 | + private $objectManager; |
| 31 | + |
| 32 | + /** |
| 33 | + * @var VclGeneratorInterfaceFactory |
| 34 | + */ |
| 35 | + private $vclGeneratorInterfaceFactory; |
| 36 | + |
| 37 | + /** |
| 38 | + * @var WriteFactory |
| 39 | + */ |
| 40 | + private $writeFactoryMock; |
| 41 | + |
| 42 | + /** |
| 43 | + * @var ScopeConfigInterface |
| 44 | + */ |
| 45 | + private $scopeConfigMock; |
| 46 | + |
| 47 | + /** |
| 48 | + * @var VclGenerator |
| 49 | + */ |
| 50 | + private $vclGenerator; |
| 51 | + |
| 52 | + /** |
| 53 | + * @var Json |
| 54 | + */ |
| 55 | + private $serializer; |
| 56 | + |
| 57 | + protected function setUp(): void |
| 58 | + { |
| 59 | + $this->vclGeneratorInterfaceFactory = $this->createMock(VclGeneratorInterfaceFactory::class); |
| 60 | + $this->vclGenerator = $this->createMock(VclGenerator::class); |
| 61 | + $this->vclGenerator->method('generateVcl')->willReturn('test.vcl" file can\'t be read.'); |
| 62 | + $this->vclGeneratorInterfaceFactory->method('create')->willReturn($this->vclGenerator); |
| 63 | + $this->writeFactoryMock = $this->createMock(WriteFactory::class); |
| 64 | + $this->scopeConfigMock = $this->createMock(ScopeConfigInterface::class); |
| 65 | + $this->serializer = $this->getMockBuilder(Json::class) |
| 66 | + ->onlyMethods(['unserialize']) |
| 67 | + ->getMockForAbstractClass(); |
| 68 | + |
| 69 | + $this->command = new GenerateVclCommand( |
| 70 | + $this->vclGeneratorInterfaceFactory, |
| 71 | + $this->writeFactoryMock, |
| 72 | + $this->scopeConfigMock, |
| 73 | + $this->serializer |
| 74 | + ); |
| 75 | + |
| 76 | + } |
| 77 | + |
| 78 | + public function testConfigure() |
| 79 | + { |
| 80 | + $this->assertEquals('varnish:vcl:generate', $this->command->getName()); |
| 81 | + $this->assertEquals( |
| 82 | + 'Generates Varnish VCL and echos it to the command line', |
| 83 | + $this->command->getDescription() |
| 84 | + ); |
| 85 | + } |
| 86 | + |
| 87 | + public function testInputOption() |
| 88 | + { |
| 89 | + $options = [ |
| 90 | + '--' . GenerateVclCommand::INPUT_FILE_OPTION => 'test.vcl', |
| 91 | + '--' . GenerateVclCommand::EXPORT_VERSION_OPTION => 6, |
| 92 | + ]; |
| 93 | + |
| 94 | + $commandTester = new CommandTester($this->command); |
| 95 | + $commandTester->execute($options, ['interactive' => false]); |
| 96 | + $this->assertStringContainsString( |
| 97 | + 'test.vcl" file can\'t be read.', |
| 98 | + $commandTester->getDisplay() |
| 99 | + ); |
| 100 | + } |
| 101 | +} |
0 commit comments