DependencyCheckerTest.php 4.3 KB

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