Skip to content

Commit cfef773

Browse files
committed
#36538: Added Unit Test for Input Option
1 parent 4d2f319 commit cfef773

File tree

2 files changed

+177
-0
lines changed

2 files changed

+177
-0
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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\Model\Varnish;
9+
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
use Magento\Framework\Filesystem\Directory\Read;
12+
use Magento\Framework\Filesystem\Directory\ReadFactory;
13+
use Magento\Framework\Filesystem\DirectoryList;
14+
use Magento\Framework\Module\Dir\Reader;
15+
use Magento\PageCache\Model\Varnish\VclTemplateLocator;
16+
use PHPUnit\Framework\TestCase;
17+
18+
class VclTemplateLocatorTest extends TestCase
19+
{
20+
/**
21+
* @var Reader
22+
*/
23+
private $readerMock;
24+
25+
/**
26+
* @var ScopeConfigInterface
27+
*/
28+
private $scopeConfigMock;
29+
30+
/**
31+
* @var ReadFactory
32+
*/
33+
private $readFactoryMock;
34+
35+
/**
36+
* @var DirectoryList
37+
*/
38+
private $directoryListMock;
39+
40+
private $vclTemplateLocator;
41+
42+
public function setUp(): void
43+
{
44+
$this->readerMock = $this->createMock(Reader::class);
45+
$this->scopeConfigMock = $this->createMock(ScopeConfigInterface::class);
46+
$this->readFactoryMock = $this->createMock(ReadFactory::class);
47+
$this->directoryListMock = $this->createMock(DirectoryList::class);
48+
49+
$this->vclTemplateLocator = new VclTemplateLocator(
50+
$this->readerMock,
51+
$this->readFactoryMock,
52+
$this->scopeConfigMock,
53+
$this->directoryListMock
54+
);
55+
}
56+
57+
public function testGetTemplate()
58+
{
59+
$inputfile = 'test.vcl';
60+
$version = 6;
61+
$read = $this->createMock(Read::class);
62+
$read
63+
->method('readFile')
64+
->with('test.vcl')
65+
->willReturn('test.vcl" file can\'t be read.');
66+
$this->readFactoryMock->method('create')->willReturn($read);
67+
68+
$template = $this->vclTemplateLocator->getTemplate($version, $inputfile);
69+
$this->assertStringContainsString(
70+
'test.vcl" file can\'t be read.',
71+
$template
72+
);
73+
}
74+
75+
76+
}

0 commit comments

Comments
 (0)