/**
  * Checks if deployment configuration has been changed by a test
  *
  * Changing deployment configuration violates isolation between tests, so further tests may become broken.
  * To fix this issue, find out why this test changes deployment configuration.
  * If this is intentional, then it must be reverted to the previous state within the test.
  * After that, the application needs to be wiped out and reinstalled.
  *
  * @param \PHPUnit_Framework_TestCase $test
  * @return void
  */
 public function endTest(\PHPUnit_Framework_TestCase $test)
 {
     $config = $this->reader->load();
     if ($this->config != $config) {
         $error = "\n\nERROR: deployment configuration is corrupted. The application state is no longer valid.\n" . 'Further tests may fail.' . " This test failure may be misleading, if you are re-running it on a corrupted application.\n" . $test->toString() . "\n";
         $test->fail($error);
     }
 }
Example #2
0
 /**
  * Saves config
  *
  * @param array $data
  * @param bool $override
  * @return void
  */
 public function saveConfig(array $data, $override = false)
 {
     $paths = $this->configFilePool->getPaths();
     foreach ($data as $fileKey => $config) {
         if (isset($paths[$fileKey])) {
             if ($this->filesystem->getDirectoryWrite(DirectoryList::CONFIG)->isExist($paths[$fileKey])) {
                 $currentData = $this->reader->load($fileKey);
                 if ($override) {
                     $config = array_merge($currentData, $config);
                 } else {
                     $config = array_replace_recursive($currentData, $config);
                 }
             }
             $contents = $this->formatter->format($config);
             try {
                 $this->filesystem->getDirectoryWrite(DirectoryList::CONFIG)->writeFile($paths[$fileKey], $contents);
             } catch (FileSystemException $e) {
                 throw new FileSystemException(new Phrase('Deployment config file %1 is not writable.', [$paths[$fileKey]]));
             }
             if (function_exists('opcache_invalidate')) {
                 opcache_invalidate($this->filesystem->getDirectoryRead(DirectoryList::CONFIG)->getAbsolutePath($paths[$fileKey]));
             }
         }
     }
     $this->deploymentConfig->resetData();
 }
 /**
  * Loads the configuration data
  *
  * @return void
  */
 private function load()
 {
     if (null === $this->data) {
         $this->data = $this->reader->load();
         if ($this->overrideData) {
             $this->data = array_replace($this->data, $this->overrideData);
         }
         // flatten data for config retrieval using get()
         $this->flatData = $this->flattenParams($this->data);
     }
 }
 /**
  * Prepare mocks for update modules tests and returns the installer to use
  *
  * @return Installer
  */
 private function prepareForUpdateModulesTests()
 {
     $allModules = ['Foo_One' => [], 'Bar_Two' => [], 'New_Module' => []];
     $cacheManager = $this->getMock('Magento\\Framework\\App\\Cache\\Manager', [], [], '', false);
     $cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['foo', 'bar']);
     $cacheManager->expects($this->once())->method('clean');
     $this->objectManager->expects($this->any())->method('get')->will($this->returnValueMap([['Magento\\Framework\\App\\Cache\\Manager', $cacheManager]]));
     $this->moduleLoader->expects($this->once())->method('load')->willReturn($allModules);
     $expectedModules = [ConfigFilePool::APP_CONFIG => ['modules' => ['Bar_Two' => 0, 'Foo_One' => 1, 'New_Module' => 1]]];
     $this->config->expects($this->atLeastOnce())->method('isAvailable')->willReturn(true);
     $newObject = $this->createObject(false, false);
     $this->configReader->expects($this->once())->method('load')->willReturn(['modules' => ['Bar_Two' => 0, 'Foo_One' => 1, 'Old_Module' => 0]]);
     $this->configWriter->expects($this->once())->method('saveConfig')->with($expectedModules);
     return $newObject;
 }
 public function testUpdateModulesSequence()
 {
     $varDir = $this->getMockForAbstractClass('Magento\\Framework\\Filesystem\\Directory\\WriteInterface');
     $varDir->expects($this->exactly(2))->method('getAbsolutePath')->willReturn('/var');
     $this->filesystem->expects($this->exactly(2))->method('getDirectoryWrite')->willReturn($varDir);
     $allModules = ['Foo_One' => [], 'Bar_Two' => [], 'New_Module' => []];
     $this->moduleLoader->expects($this->once())->method('load')->willReturn($allModules);
     $expectedModules = ['Bar_Two' => 0, 'Foo_One' => 1, 'New_Module' => 1];
     $this->config->expects($this->atLeastOnce())->method('isAvailable')->willReturn(true);
     $this->deploymentConfigFactory->expects($this->once())->method('create')->with($expectedModules)->willReturn($this->deploymentConfig);
     $newObject = $this->createObject(false, false);
     $this->configReader->expects($this->once())->method('load')->willReturn(['modules' => ['Bar_Two' => 0, 'Foo_One' => 1, 'Old_Module' => 0]]);
     $this->configWriter->expects($this->once())->method('update')->with($this->deploymentConfig);
     $this->logger->expects($this->at(0))->method('log')->with('File system cleanup:');
     $this->logger->expects($this->at(1))->method('log')->with('The directory \'/var\' doesn\'t exist - skipping cleanup');
     $this->logger->expects($this->at(3))->method('log')->with('Updating modules:');
     $newObject->updateModulesSequence();
 }
Example #6
0
 /**
  * Saves config
  *
  * @param array $data
  * @param bool $override
  * @return void
  */
 public function saveConfig(array $data, $override = false)
 {
     $paths = $this->configFilePool->getPaths();
     foreach ($data as $fileKey => $config) {
         if (isset($paths[$fileKey])) {
             if ($this->filesystem->getDirectoryWrite(DirectoryList::CONFIG)->isExist($paths[$fileKey])) {
                 $currentData = $this->reader->load($paths[$fileKey]);
                 if ($override) {
                     $config = array_merge($currentData, $config);
                 } else {
                     $config = array_replace_recursive($currentData, $config);
                 }
             }
             $contents = $this->formatter->format($config);
             $this->filesystem->getDirectoryWrite(DirectoryList::CONFIG)->writeFile($paths[$fileKey], $contents);
         }
     }
     $this->deploymentConfig->resetData();
 }
Example #7
0
 public function testUpdateModulesSequence()
 {
     $allModules = ['Foo_One' => [], 'Bar_Two' => [], 'New_Module' => []];
     $this->cleanupFiles->expects($this->once())->method('clearCodeGeneratedClasses')->will($this->returnValue(["The directory '/generation' doesn't exist - skipping cleanup"]));
     $cache = $this->getMock('Magento\\Framework\\App\\Cache', [], [], '', false);
     $cache->expects($this->once())->method('clean');
     $this->objectManager->expects($this->once())->method('create')->will($this->returnValueMap([['Magento\\Framework\\App\\Cache', [], $cache]]));
     $this->moduleLoader->expects($this->once())->method('load')->willReturn($allModules);
     $expectedModules = [ConfigFilePool::APP_CONFIG => ['modules' => ['Bar_Two' => 0, 'Foo_One' => 1, 'New_Module' => 1]]];
     $this->config->expects($this->atLeastOnce())->method('isAvailable')->willReturn(true);
     $newObject = $this->createObject(false, false);
     $this->configReader->expects($this->once())->method('load')->willReturn(['modules' => ['Bar_Two' => 0, 'Foo_One' => 1, 'Old_Module' => 0]]);
     $this->configWriter->expects($this->once())->method('saveConfig')->with($expectedModules);
     $this->logger->expects($this->at(0))->method('log')->with('Cache cleared successfully');
     $this->logger->expects($this->at(1))->method('log')->with('File system cleanup:');
     $this->logger->expects($this->at(2))->method('log')->with('The directory \'/generation\' doesn\'t exist - skipping cleanup');
     $this->logger->expects($this->at(3))->method('log')->with('Updating modules:');
     $newObject->updateModulesSequence();
 }
Example #8
0
 /**
  * Persists the data into file
  *
  * @param array $data
  * @return void
  */
 private function write($data)
 {
     $contents = $this->formatter->format($data);
     $this->filesystem->getDirectoryWrite(DirectoryList::CONFIG)->writeFile($this->reader->getFile(), $contents);
 }
Example #9
0
 /**
  * @expectedException \Exception
  * @expectedExceptionMessage Key collision
  */
 public function testMergingWithDuplicateEndValues()
 {
     $configFilePool = $this->getMock('Magento\\Framework\\Config\\File\\ConfigFilePool', [], [], '', false);
     $files = [['configKeyOne', 'config.php'], ['configKeyTwo', 'duplicateConfig.php']];
     $configFilePool->expects($this->any())->method('getPath')->will($this->returnValueMap($files));
     $configFilePool->expects($this->any())->method('getPaths')->willReturn(['configKeyOne' => 'config.php', 'configKeyTwo' => 'duplicateConfig.php']);
     $object = new Reader($this->dirList, $this->driverPool, $configFilePool);
     $object->load();
 }
Example #10
0
 /**
  * Get current mode information
  *
  * @return string
  * @throws \Exception
  */
 public function getMode()
 {
     $env = $this->reader->load(ConfigFilePool::APP_ENV);
     return isset($env[State::PARAM_MODE]) ? $env[State::PARAM_MODE] : null;
 }
Example #11
0
    public function testUninstall()
    {
        $this->config->expects($this->once())->method('isAvailable')->willReturn(false);
        $this->configReader->expects($this->once())->method('getFiles')->willReturn(['ConfigOne.php', 'ConfigTwo.php']);
        $configDir = $this->getMockForAbstractClass('Magento\Framework\Filesystem\Directory\WriteInterface');
        $configDir
            ->expects($this->exactly(2))
            ->method('getAbsolutePath')
            ->will(
                $this->returnValueMap(
                    [
                        ['ConfigOne.php', '/config/ConfigOne.php'],
                        ['ConfigTwo.php', '/config/ConfigTwo.php']
                    ]
                )
            );
        $this->filesystem
            ->expects($this->any())
            ->method('getDirectoryWrite')
            ->will($this->returnValueMap([
                [DirectoryList::CONFIG, DriverPool::FILE, $configDir],
            ]));
        $this->logger->expects($this->at(0))->method('log')->with('Starting Magento uninstallation:');
        $this->logger
            ->expects($this->at(1))
            ->method('log')
            ->with('No database connection defined - skipping database cleanup');
        $cache = $this->getMock('Magento\Framework\App\Cache', [], [], '', false);
        $cache->expects($this->once())->method('clean');
        $this->objectManager->expects($this->once())
            ->method('create')
            ->will($this->returnValueMap([
                ['Magento\Framework\App\Cache', [], $cache],
            ]));
        $this->logger->expects($this->at(2))->method('log')->with('Cache cleared successfully');
        $this->logger->expects($this->at(3))->method('log')->with('File system cleanup:');
        $this->logger
            ->expects($this->at(4))
            ->method('log')
            ->with("The directory '/var' doesn't exist - skipping cleanup");
        $this->logger
            ->expects($this->at(5))
            ->method('log')
            ->with("The directory '/static' doesn't exist - skipping cleanup");
        $this->logger
            ->expects($this->at(6))
            ->method('log')
            ->with("The file '/config/ConfigOne.php' doesn't exist - skipping cleanup");
        $this->logger
            ->expects($this->at(7))
            ->method('log')
            ->with("The file '/config/ConfigTwo.php' doesn't exist - skipping cleanup");
        $this->logger->expects($this->once())->method('logSuccess')->with('Magento uninstallation complete.');
        $this->cleanupFiles->expects($this->once())->method('clearAllFiles')->will(
            $this->returnValue(
                [
                    "The directory '/var' doesn't exist - skipping cleanup",
                    "The directory '/static' doesn't exist - skipping cleanup"
                ]
            )
        );

        $this->object->uninstall();
    }
 /**
  * Removes deployment configuration
  *
  * @return void
  */
 private function deleteDeploymentConfig()
 {
     $configDir = $this->filesystem->getDirectoryWrite(DirectoryList::CONFIG);
     $configFiles = $this->deploymentConfigReader->getFiles();
     foreach ($configFiles as $configFile) {
         $absolutePath = $configDir->getAbsolutePath($configFile);
         if (!$configDir->isFile($configFile)) {
             $this->log->log("The file '{$absolutePath}' doesn't exist - skipping cleanup");
             continue;
         }
         try {
             $this->log->log($absolutePath);
             $configDir->delete($configFile);
         } catch (FileSystemException $e) {
             $this->log->log($e->getMessage());
         }
     }
 }
Example #13
0
 /**
  * @param string $file
  * @param array $expected
  * @dataProvider loadDataProvider
  */
 public function testLoad($file, $expected)
 {
     $this->dirList->expects($this->once())->method('getPath')->with(DirectoryList::CONFIG)->willReturn(__DIR__ . '/_files');
     $object = new Reader($this->dirList, $file);
     $this->assertSame($expected, $object->load());
 }