Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
JobStaticRegenerateTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class JobStaticRegenerateTest extends \PHPUnit\Framework\TestCase
11 {
15  private $jobStaticRegenerate;
16 
17  public function setUp()
18  {
19  $this->jobStaticRegenerate = $this->getJobStaticRegenerateMock(
20  [
21  'getCacheObject',
22  'getCleanFilesObject',
23  'getStatusObject',
24  'getOutputObject',
25  'getModeObject',
26  'getFilesystem',
27  ]
28  );
29  }
30 
34  public function testExecuteProductionMode()
35  {
36  $modeObjectMock = $this->getModeObjectMock(['getMode']);
37  $modeObjectMock->expects($this->once())
38  ->method('getMode')
39  ->will($this->returnValue(State::MODE_PRODUCTION));
40 
41  $filesystemMock = $this->getFilesystemObjectMock(['regenerateStatic']);
42  $filesystemMock
43  ->expects($this->once())
44  ->method('regenerateStatic');
45 
46  $this->jobStaticRegenerate
47  ->expects($this->once())
48  ->method('getFilesystem')
49  ->will($this->returnValue($filesystemMock));
50 
51  $this->jobStaticRegenerate
52  ->expects($this->once())
53  ->method('getModeObject')
54  ->will($this->returnValue($modeObjectMock));
55 
56  $this->jobStaticRegenerate
57  ->expects($this->once())
58  ->method('getOutputObject')
59  ->will($this->returnValue($this->getOutputObjectMock()));
60 
61  $this->jobStaticRegenerate->execute();
62  }
63 
67  public function testExecuteDevelopernMode()
68  {
69  $modeObjectMock = $this->getModeObjectMock(['getMode']);
70  $modeObjectMock->expects($this->once())
71  ->method('getMode')
72  ->will($this->returnValue(State::MODE_DEVELOPER));
73 
74  $this->jobStaticRegenerate
75  ->expects($this->once())
76  ->method('getModeObject')
77  ->will($this->returnValue($modeObjectMock));
78 
79  $statusObject = $this->getStatusObjectMock(['add']);
80  $statusObject
81  ->expects($this->exactly(3))
82  ->method('add');
83  $this->jobStaticRegenerate
84  ->expects($this->exactly(3))
85  ->method('getStatusObject')
86  ->will($this->returnValue($statusObject));
87 
88  $cacheObject = $this->getCacheObjectMock(['clean']);
89  $cacheObject
90  ->expects($this->once())
91  ->method('clean');
92  $this->jobStaticRegenerate
93  ->expects($this->once())
94  ->method('getCacheObject')
95  ->will($this->returnValue($cacheObject));
96 
97  $cleanFilesObject = $this->getCleanFilesObjectMock(['clearMaterializedViewFiles', 'clearCodeGeneratedFiles']);
98  $cleanFilesObject
99  ->expects($this->once())
100  ->method('clearMaterializedViewFiles');
101  $cleanFilesObject
102  ->expects($this->once())
103  ->method('clearCodeGeneratedFiles');
104  $this->jobStaticRegenerate
105  ->expects($this->exactly(2))
106  ->method('getCleanFilesObject')
107  ->will($this->returnValue($cleanFilesObject));
108 
109  $this->jobStaticRegenerate->execute();
110  }
111 
116  public function testExecuteWithException()
117  {
118  $modeObjectMock = $this->getModeObjectMock(['getMode']);
119  $modeObjectMock->expects($this->once())
120  ->method('getMode')
121  ->will($this->throwException(new \Exception('error')));
122  $this->jobStaticRegenerate
123  ->expects($this->once())
124  ->method('getModeObject')
125  ->will($this->returnValue($modeObjectMock));
126 
127  $statusObject = $this->getStatusObjectMock(['toggleUpdateError']);
128  $statusObject
129  ->expects($this->once())
130  ->method('toggleUpdateError');
131  $this->jobStaticRegenerate
132  ->expects($this->once())
133  ->method('getStatusObject')
134  ->will($this->returnValue($statusObject));
135 
136  $this->jobStaticRegenerate->execute();
137  }
138 
144  protected function getJobStaticRegenerateMock($methods = null)
145  {
146  return $this->createPartialMock(\Magento\Setup\Model\Cron\JobStaticRegenerate::class, $methods);
147  }
148 
154  protected function getFilesystemObjectMock($methods = null)
155  {
156  return $this->createPartialMock(\Magento\Deploy\Model\Filesystem::class, $methods);
157  }
158 
164  protected function getStatusObjectMock($methods = null)
165  {
166  return $this->createPartialMock(\Magento\Setup\Model\Cron\Status::class, $methods);
167  }
168 
174  protected function getCleanFilesObjectMock($methods = null)
175  {
176  return $this->createPartialMock(\Magento\Framework\App\State\CleanupFiles::class, $methods);
177  }
178 
184  protected function getCacheObjectMock($methods = null)
185  {
186  return $this->createPartialMock(\Magento\Framework\App\State\CleanupFiles::class, $methods);
187  }
188 
194  protected function getOutputObjectMock()
195  {
196  return $this->getMockForAbstractClass(\Symfony\Component\Console\Output\OutputInterface::class);
197  }
198 
204  protected function getModeObjectMock($methods = null)
205  {
206  return $this->createPartialMock(\Magento\Deploy\Model\Mode::class, $methods);
207  }
208 }
$methods
Definition: billing.phtml:71