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