Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DeployStaticContentTest.php
Go to the documentation of this file.
1 <?php
7 
19 
22 
23 use Psr\Log\LoggerInterface;
24 
25 use PHPUnit_Framework_MockObject_MockObject as Mock;
26 
32 class DeployStaticContentTest extends \PHPUnit\Framework\TestCase
33 {
37  private $service;
38 
42  private $deployStrategyFactory;
43 
47  private $queueFactory;
48 
52  private $logger;
53 
57  private $objectManager;
58 
62  private $versionStorage;
63 
64  protected function setUp()
65  {
66  $this->deployStrategyFactory = $this->createPartialMock(DeployStrategyFactory::class, ['create']);
67  $this->queueFactory = $this->createPartialMock(QueueFactory::class, ['create']);
68  $this->logger = $this->getMockForAbstractClass(
69  LoggerInterface::class,
70  [],
71  '',
72  false
73  );
74  $this->objectManager = $this->createPartialMock(ObjectManagerInterface::class, ['create', 'get', 'configure']);
75  $this->versionStorage = $this->getMockForAbstractClass(
76  StorageInterface::class,
77  ['save'],
78  '',
79  false
80  );
81 
82  $this->service = new DeployStaticContent(
83  $this->objectManager,
84  $this->logger,
85  $this->versionStorage,
86  $this->deployStrategyFactory,
87  $this->queueFactory
88  );
89  }
90 
96  public function testDeploy($options, $expectedContentVersion)
97  {
98  $package = $this->createMock(Package::class);
99  if ($options['refresh-content-version-only']) {
100  $package->expects($this->never())->method('isVirtual');
101  $package->expects($this->never())->method('getArea');
102  $package->expects($this->never())->method('getTheme');
103  $package->expects($this->never())->method('getLocale');
104  } else {
105  $package->expects($this->exactly(1))->method('isVirtual')->willReturn(false);
106  $package->expects($this->exactly(3))->method('getArea')->willReturn('area');
107  $package->expects($this->exactly(3))->method('getTheme')->willReturn('theme');
108  $package->expects($this->exactly(3))->method('getLocale')->willReturn('locale');
109  }
110  $packages = ['package' => $package];
111 
112  if ($expectedContentVersion) {
113  $this->versionStorage->expects($this->once())->method('save')->with($expectedContentVersion);
114  } else {
115  $this->versionStorage->expects($this->once())->method('save');
116  }
117 
118  $queue = $this->getMockBuilder(Queue::class)
119  ->disableOriginalConstructor()
120  ->getMockForAbstractClass();
121  if ($options['refresh-content-version-only']) {
122  $this->queueFactory->expects($this->never())->method('create');
123  } else {
124  $this->queueFactory->expects($this->once())->method('create')->willReturn($queue);
125  }
126 
127  $strategy = $this->getMockBuilder(CompactDeploy::class)
128  ->setMethods(['deploy'])
129  ->disableOriginalConstructor()
130  ->getMockForAbstractClass();
131  if ($options['refresh-content-version-only']) {
132  $strategy->expects($this->never())->method('deploy');
133  } else {
134  $strategy->expects($this->once())->method('deploy')
135  ->with($options)
136  ->willReturn($packages);
137  $this->deployStrategyFactory->expects($this->once())
138  ->method('create')
139  ->with('compact', ['queue' => $queue])
140  ->willReturn($strategy);
141  }
142  $deployPackageService = $this->getMockBuilder(DeployPackage::class)
143  ->disableOriginalConstructor()
144  ->getMockForAbstractClass();
145  $deployRjsConfig = $this->getMockBuilder(DeployRequireJsConfig::class)
146  ->setMethods(['deploy'])
147  ->disableOriginalConstructor()
148  ->getMockForAbstractClass();
149  $deployI18n = $this->getMockBuilder(DeployTranslationsDictionary::class)
150  ->setMethods(['deploy'])
151  ->disableOriginalConstructor()
152  ->getMockForAbstractClass();
153  $deployBundle = $this->getMockBuilder(Bundle::class)
154  ->setMethods(['deploy'])
155  ->disableOriginalConstructor()
156  ->getMockForAbstractClass();
157  $minifyTemplates = $this->getMockBuilder(MinifyTemplates::class)
158  ->setMethods(['minifyTemplates'])
159  ->disableOriginalConstructor()
160  ->getMockForAbstractClass();
161 
162  if ($options['refresh-content-version-only']) {
163  $this->objectManager->expects($this->never())->method('create');
164  $this->objectManager->expects($this->never())->method('get');
165  } else {
166  $this->objectManager->expects($this->exactly(4))
167  ->method('create')
168  ->withConsecutive(
169  [DeployPackage::class, ['logger' => $this->logger]],
170  [DeployRequireJsConfig::class, ['logger' => $this->logger]],
171  [DeployTranslationsDictionary::class, ['logger' => $this->logger]],
172  [Bundle::class, ['logger' => $this->logger]]
173  )
174  ->willReturnOnConsecutiveCalls(
175  $deployPackageService,
176  $deployRjsConfig,
177  $deployI18n,
178  $deployBundle
179  );
180 
181  $this->objectManager->expects($this->exactly(1))
182  ->method('get')
183  ->withConsecutive([MinifyTemplates::class])
184  ->willReturnOnConsecutiveCalls($minifyTemplates);
185  }
186 
187  $this->assertEquals(null, $this->service->deploy($options));
188  }
189 
193  public function deployDataProvider()
194  {
195  return [
196  [
197  [
198  'strategy' => 'compact',
199  'no-javascript' => false,
200  'no-html-minify' => false,
201  'refresh-content-version-only' => false,
202  ],
203  null // content version value should not be asserted in this case
204  ],
205  [
206  [
207  'strategy' => 'compact',
208  'no-javascript' => false,
209  'no-html-minify' => false,
210  'refresh-content-version-only' => false,
211  'content-version' => '123456',
212  ],
213  '123456'
214  ],
215  [
216  [
217  'refresh-content-version-only' => true,
218  'content-version' => '654321',
219  ],
220  '654321'
221  ]
222  ];
223  }
224 }
$queue
Definition: queue.php:21