Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TablesWhitelistGenerateCommandTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
10 use Symfony\Component\Console\Tester\CommandTester;
15 
20 {
24  private $tester;
25 
29  private $command;
30 
34  private $componentRegistrar;
35 
39  private $objectManager;
40 
44  private $cliCommand;
45 
49  private $moduleManager;
50 
54  public function setUp()
55  {
57  $this->command = $this->objectManager->create(
58  \Magento\Developer\Console\Command\TablesWhitelistGenerateCommand::class
59  );
60  $this->componentRegistrar = $this->objectManager->create(
61  \Magento\Framework\Component\ComponentRegistrar::class
62  );
63  $this->cliCommand = $this->objectManager->get(CliCommand::class);
64  $this->tester = new CommandTester($this->command);
65  $this->moduleManager = $this->objectManager->get(TestModuleManager::class);
66  }
67 
75  public function testExecute()
76  {
77  $modules = [
78  'Magento_TestSetupDeclarationModule1',
79  'Magento_TestSetupDeclarationModule8',
80  ];
81 
82  $this->cliCommand->install($modules);
83  foreach ($modules as $moduleName) {
84  $this->moduleManager->updateRevision(
85  $moduleName,
86  'whitelist_upgrade',
87  'db_schema.xml',
88  'etc'
89  );
90  }
91 
92  foreach ($modules as $moduleName) {
93  $this->checkWhitelistFile($moduleName);
94  }
95  }
96 
100  private function checkWhitelistFile(string $moduleName)
101  {
102  $modulePath = $this->componentRegistrar->getPath('module', $moduleName);
103  $whiteListFileName = $modulePath
104  . DIRECTORY_SEPARATOR
106  . DIRECTORY_SEPARATOR
108 
109  //run bin/magento declaration:generate:whitelist Magento_TestSetupDeclarationModule1 command.
110  $this->tester->execute(['--module-name' => $moduleName], ['interactive' => false]);
111  $this->assertSame(Cli::RETURN_SUCCESS, $this->tester->getStatusCode());
112 
113  $this->assertFileExists($whiteListFileName);
114  $this->assertContains('', $this->tester->getDisplay());
115 
116  $whitelistFileContent = file_get_contents($whiteListFileName);
117  $expectedWhitelistContent = file_get_contents(
118  dirname(__DIR__, 2)
119  . DIRECTORY_SEPARATOR
120  . implode(
121  DIRECTORY_SEPARATOR,
122  [
123  '_files',
124  'WhitelistGenerate',
125  str_replace('Magento_', '', $moduleName),
126  'db_schema_whitelist.json'
127  ]
128  )
129  );
130  $this->assertEquals($expectedWhitelistContent, $whitelistFileContent);
131  }
132 }
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60