Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DependencyCheckerTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class DependencyCheckerTest extends \PHPUnit\Framework\TestCase
11 {
12  public function testCheckDependencies()
13  {
14  $composerApp =
15  $this->createPartialMock(\Composer\Console\Application::class, ['setAutoExit', 'resetComposer', 'run']);
16  $directoryList = $this->createMock(\Magento\Framework\App\Filesystem\DirectoryList::class);
17  $directoryList->expects($this->exactly(2))->method('getRoot');
18  $composerApp->expects($this->once())->method('setAutoExit')->with(false);
19 
20  $composerApp->expects($this->at(2))->method('run')->willReturnCallback(
21  function ($input, $buffer) {
22  $output = 'magento/package-b requires magento/package-a (1.0)' . PHP_EOL .
23  'magento/project-community-edition requires magento/package-a (1.0)' . PHP_EOL .
24  'magento/package-c requires magento/package-a (1.0)' . PHP_EOL;
25  $buffer->writeln($output);
26  }
27  );
28  $composerApp->expects($this->at(4))->method('run')->willReturnCallback(
29  function ($input, $buffer) {
30  $output = 'magento/package-c requires magento/package-b (1.0)' . PHP_EOL .
31  'magento/project-community-edition requires magento/package-a (1.0)' . PHP_EOL .
32  'magento/package-d requires magento/package-b (1.0)' . PHP_EOL;
33  $buffer->writeln($output);
34  }
35  );
36 
37  $dependencyChecker = new DependencyChecker($composerApp, $directoryList);
38  $expected = [
39  'magento/package-a' => ['magento/package-b', 'magento/package-c'],
40  'magento/package-b' => ['magento/package-c', 'magento/package-d'],
41  ];
42  $this->assertEquals(
43  $expected,
44  $dependencyChecker->checkDependencies(['magento/package-a', 'magento/package-b'])
45  );
46  }
47 
49  {
50  $composerApp =
51  $this->createPartialMock(\Composer\Console\Application::class, ['setAutoExit', 'resetComposer', 'run']);
52  $directoryList = $this->createMock(\Magento\Framework\App\Filesystem\DirectoryList::class);
53  $directoryList->expects($this->exactly(3))->method('getRoot');
54  $composerApp->expects($this->once())->method('setAutoExit')->with(false);
55 
56  $composerApp->expects($this->at(2))->method('run')->willReturnCallback(
57  function ($input, $buffer) {
58  $output = 'magento/package-b requires magento/package-a (1.0)' . PHP_EOL .
59  'magento/project-community-edition requires magento/package-a (1.0)' . PHP_EOL .
60  'magento/package-c requires magento/package-a (1.0)' . PHP_EOL;
61  $buffer->writeln($output);
62  }
63  );
64  $composerApp->expects($this->at(4))->method('run')->willReturnCallback(
65  function ($input, $buffer) {
66  $output = 'magento/package-c requires magento/package-b (1.0)' . PHP_EOL .
67  'magento/project-community-edition requires magento/package-a (1.0)' . PHP_EOL .
68  'magento/package-d requires magento/package-b (1.0)' . PHP_EOL;
69  $buffer->writeln($output);
70  }
71  );
72  $composerApp->expects($this->at(6))->method('run')->willReturnCallback(
73  function ($input, $buffer) {
74  $output = 'magento/package-d requires magento/package-c (1.0)' . PHP_EOL .
75  'magento/project-community-edition requires magento/package-a (1.0)' . PHP_EOL;
76  $buffer->writeln($output);
77  }
78  );
79 
80  $dependencyChecker = new DependencyChecker($composerApp, $directoryList);
81  $expected = [
82  'magento/package-a' => [],
83  'magento/package-b' => ['magento/package-d'],
84  'magento/package-c' => ['magento/package-d'],
85  ];
86  $this->assertEquals(
87  $expected,
88  $dependencyChecker->checkDependencies(
89  ['magento/package-a', 'magento/package-b', 'magento/package-c'],
90  true
91  )
92  );
93  }
94 }