Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DependenciesShowModulesCommandTest.php
Go to the documentation of this file.
1 <?php
7 
9 use Symfony\Component\Console\Tester\CommandTester;
10 
11 class DependenciesShowModulesCommandTest extends \PHPUnit\Framework\TestCase
12 {
16  private $command;
17 
21  private $commandTester;
22 
23  public function setUp()
24  {
25 
26  $modules = [
27  'Magento_A' => __DIR__ . '/_files/root/app/code/Magento/A',
28  'Magento_B' => __DIR__ . '/_files/root/app/code/Magento/B'
29  ];
30 
31  $objectManagerProvider = $this->createMock(\Magento\Setup\Model\ObjectManagerProvider::class);
32  $objectManager = $this->createMock(\Magento\Framework\App\ObjectManager::class);
33  $objectManagerProvider->expects($this->once())->method('get')->willReturn($objectManager);
34 
35  $themePackageListMock = $this->createMock(\Magento\Framework\View\Design\Theme\ThemePackageList::class);
36  $componentRegistrarMock = $this->createMock(\Magento\Framework\Component\ComponentRegistrar::class);
37  $componentRegistrarMock->expects($this->any())->method('getPaths')->will($this->returnValue($modules));
38  $dirSearchMock = $this->createMock(\Magento\Framework\Component\DirSearch::class);
39  $objectManager->expects($this->any())->method('get')->will($this->returnValueMap([
40  [\Magento\Framework\View\Design\Theme\ThemePackageList::class, $themePackageListMock],
41  [\Magento\Framework\Component\ComponentRegistrar::class, $componentRegistrarMock],
42  [\Magento\Framework\Component\DirSearch::class, $dirSearchMock]
43  ]));
44 
45  $this->command = new DependenciesShowModulesCommand($objectManagerProvider);
46  $this->commandTester = new CommandTester($this->command);
47  }
48 
49  public function tearDown()
50  {
51  if (file_exists(__DIR__ . '/_files/output/modules.csv')) {
52  unlink(__DIR__ . '/_files/output/modules.csv');
53  }
54  }
55 
56  public function testExecute()
57  {
58  $this->commandTester->execute(
59  ['--output' => __DIR__ . '/_files/output/modules.csv']
60  );
61  $this->assertEquals('Report successfully processed.' . PHP_EOL, $this->commandTester->getDisplay());
62  $fileContents = file_get_contents(__DIR__ . '/_files/output/modules.csv');
63  $this->assertContains(
64  ',All,Hard,Soft' . PHP_EOL . '"Total number of dependencies",2,2,0' . PHP_EOL,
65  $fileContents
66  );
67  $this->assertContains('"Dependencies for each module:",All,Hard,Soft'. PHP_EOL, $fileContents);
68  $this->assertContains(
69  'magento/module-a,1,1,0' . PHP_EOL . '" -- magento/module-b",,1,0' . PHP_EOL,
70  $fileContents
71  );
72  $this->assertContains(
73  'magento/module-b,1,1,0' . PHP_EOL . '" -- magento/module-a",,1,0' . PHP_EOL,
74  $fileContents
75  );
76  }
77 }
$objectManager
Definition: bootstrap.php:17
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60