Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CliTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
18 
19 class CliTest extends \PHPUnit\Framework\TestCase
20 {
24  private $objectManager;
25 
29  private $filesystem;
30 
34  private $configFilePool;
35 
39  private $reader;
40 
44  private $writer;
45 
49  private $envConfig;
50 
54  protected function setUp()
55  {
56  $this->objectManager = Bootstrap::getObjectManager();
57  $this->configFilePool = $this->objectManager->get(ConfigFilePool::class);
58  $this->filesystem = $this->objectManager->get(Filesystem::class);
59  $this->reader = $this->objectManager->get(FileReader::class);
60  $this->writer = $this->objectManager->get(Writer::class);
61 
62  $this->envConfig = $this->reader->load(ConfigFilePool::APP_ENV);
63  }
64 
68  protected function tearDown()
69  {
70  $this->filesystem->getDirectoryWrite(DirectoryList::CONFIG)->writeFile(
71  $this->configFilePool->getPath(ConfigFilePool::APP_ENV),
72  "<?php\n return array();\n"
73  );
74 
75  $this->writer->saveConfig([ConfigFilePool::APP_ENV => $this->envConfig], true);
76  }
77 
86  public function testDocumentRootIsPublic($isPub, $params)
87  {
88  $config = include __DIR__ . '/_files/env.php';
89  $config['directories']['document_root_is_pub'] = $isPub;
90  $this->writer->saveConfig([ConfigFilePool::APP_ENV => $config], true);
91 
92  $cli = new Cli();
93  $cliReflection = new \ReflectionClass($cli);
94 
95  $serviceManagerProperty = $cliReflection->getProperty('serviceManager');
96  $serviceManagerProperty->setAccessible(true);
97  $serviceManager = $serviceManagerProperty->getValue($cli);
98  $deploymentConfig = $this->objectManager->get(DeploymentConfig::class);
99  $serviceManager->setAllowOverride(true);
100  $serviceManager->setService(DeploymentConfig::class, $deploymentConfig);
101  $serviceManagerProperty->setAccessible(false);
102 
103  $documentRootResolver = $cliReflection->getMethod('documentRootResolver');
104  $documentRootResolver->setAccessible(true);
105 
106  self::assertEquals($params, $documentRootResolver->invoke($cli));
107  }
108 
115  public function documentRootIsPubProvider(): array
116  {
117  return [
118  [true, [
119  'MAGE_DIRS' => [
120  'pub' => ['uri' => ''],
121  'media' => ['uri' => 'media'],
122  'static' => ['uri' => 'static'],
123  'upload' => ['uri' => 'media/upload']
124  ]
125  ]],
126  [false, []]
127  ];
128  }
129 }
$objectManager
Definition: bootstrap.php:17
$config
Definition: fraud_order.php:17
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
$deploymentConfig
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18
$filesystem