Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
FilesystemTest.php
Go to the documentation of this file.
1 <?php
7 
8 use Magento\Deploy\Model\Filesystem as DeployFilesystem;
17 use PHPUnit_Framework_MockObject_MockObject as MockObject;
18 use Symfony\Component\Console\Output\OutputInterface;
21 
25 class FilesystemTest extends \PHPUnit\Framework\TestCase
26 {
30  private $storeView;
31 
35  private $shell;
36 
40  private $output;
41 
45  private $filesystem;
46 
50  private $directoryWrite;
51 
55  private $userCollection;
56 
60  private $objectManager;
61 
65  private $deployFilesystem;
66 
70  private $cmdPrefix;
71 
72  protected function setUp()
73  {
74  $objectManager = new ObjectManager($this);
75 
76  $this->storeView = $this->getMockBuilder(StoreView::class)
77  ->disableOriginalConstructor()
78  ->getMock();
79  $this->shell = $this->getMockBuilder(ShellInterface::class)
80  ->disableOriginalConstructor()
81  ->getMock();
82  $this->output = $this->getMockBuilder(OutputInterface::class)
83  ->disableOriginalConstructor()
84  ->getMock();
85  $this->objectManager = $this->getMockBuilder(ObjectManagerInterface::class)
86  ->disableOriginalConstructor()
87  ->getMock();
88  $this->filesystem = $this->getMockBuilder(Filesystem::class)
89  ->disableOriginalConstructor()
90  ->getMock();
91  $this->directoryWrite = $this->getMockBuilder(WriteInterface::class)
92  ->disableOriginalConstructor()
93  ->getMock();
94  $this->filesystem->method('getDirectoryWrite')
95  ->willReturn($this->directoryWrite);
96 
97  $this->userCollection = $this->getMockBuilder(Collection::class)
98  ->disableOriginalConstructor()
99  ->getMock();
100  $lists = $this->getMockBuilder(Lists::class)
101  ->disableOriginalConstructor()
102  ->getMock();
103 
104  $lists->method('getLocaleList')
105  ->willReturn([
106  'fr_FR' => 'France',
107  'de_DE' => 'Germany',
108  'nl_NL' => 'Netherlands',
109  'en_US' => 'USA',
110  ]);
111  $locale = $objectManager->getObject(Locale::class, ['lists' => $lists]);
112 
113  $this->deployFilesystem = $objectManager->getObject(
114  DeployFilesystem::class,
115  [
116  'storeView' => $this->storeView,
117  'shell' => $this->shell,
118  'filesystem' => $this->filesystem,
119  'userCollection' => $this->userCollection,
120  'locale' => $locale,
121  ]
122  );
123 
124  $this->cmdPrefix = PHP_BINARY . ' -f ' . BP . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . 'magento ';
125  }
126 
127  public function testRegenerateStatic()
128  {
129  $storeLocales = ['fr_FR', 'de_DE', 'nl_NL'];
130  $this->storeView->method('retrieveLocales')
131  ->willReturn($storeLocales);
132 
133  $setupDiCompileCmd = $this->cmdPrefix . 'setup:di:compile';
134  $this->shell->expects(self::at(0))
135  ->method('execute')
136  ->with($setupDiCompileCmd);
137 
138  $this->initAdminLocaleMock('en_US');
139 
140  $usedLocales = ['fr_FR', 'de_DE', 'nl_NL', 'en_US'];
141  $staticContentDeployCmd = $this->cmdPrefix . 'setup:static-content:deploy -f '
142  . implode(' ', $usedLocales);
143  $this->shell->expects(self::at(1))
144  ->method('execute')
145  ->with($staticContentDeployCmd);
146 
147  $this->output->expects(self::at(0))
148  ->method('writeln')
149  ->with('Starting compilation');
150  $this->output->expects(self::at(2))
151  ->method('writeln')
152  ->with('Compilation complete');
153  $this->output->expects(self::at(3))
154  ->method('writeln')
155  ->with('Starting deployment of static content');
156  $this->output->expects(self::at(5))
157  ->method('writeln')
158  ->with('Deployment of static content complete');
159 
160  $this->deployFilesystem->regenerateStatic($this->output);
161  }
162 
171  {
172  $storeLocales = ['fr_FR', 'de_DE', ';echo'];
173  $this->storeView->method('retrieveLocales')
174  ->willReturn($storeLocales);
175 
176  $this->initAdminLocaleMock('en_US');
177 
178  $this->deployFilesystem->regenerateStatic($this->output);
179  }
180 
189  {
190  $storeLocales = ['fr_FR', 'de_DE', 'en_US'];
191  $this->storeView->method('retrieveLocales')
192  ->willReturn($storeLocales);
193 
194  $this->initAdminLocaleMock(';echo');
195 
196  $this->deployFilesystem->regenerateStatic($this->output);
197  }
198 
205  private function initAdminLocaleMock($locale)
206  {
208  $user = $this->getMockBuilder(User::class)
209  ->disableOriginalConstructor()
210  ->getMock();
211  $user->method('getInterfaceLocale')
212  ->willReturn($locale);
213  $this->userCollection->method('getIterator')
214  ->willReturn(new \ArrayIterator([$user]));
215  }
216 }
output($string, $level=INFO, $label='')
$user
Definition: dummy_user.php:13
const BP
Definition: autoload.php:14