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