SampleDataRemoveCommandTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\SampleData\Test\Unit\Console\Command;
  7. use Magento\SampleData\Console\Command\SampleDataRemoveCommand;
  8. use Symfony\Component\Console\Tester\CommandTester;
  9. class SampleDataRemoveCommandTest extends AbstractSampleDataCommandTest
  10. {
  11. /**
  12. * @param array $sampleDataPackages
  13. * @param int $appRunResult - int 0 if everything went fine, or an error code
  14. * @param string $expectedMsg
  15. * @return void
  16. *
  17. * @dataProvider processDataProvider
  18. */
  19. public function testExecute(array $sampleDataPackages, $appRunResult, $expectedMsg)
  20. {
  21. $this->setupMocks($sampleDataPackages, '/path/to/composer.json', $appRunResult);
  22. $commandTester = $this->createCommandTester();
  23. $commandTester->execute([]);
  24. $this->assertEquals($expectedMsg, $commandTester->getDisplay());
  25. }
  26. /**
  27. * @param array $sampleDataPackages
  28. * @param int $appRunResult - int 0 if everything went fine, or an error code
  29. * @param string $expectedMsg
  30. * @return void
  31. *
  32. * @dataProvider processDataProvider
  33. */
  34. public function testExecuteWithNoUpdate(array $sampleDataPackages, $appRunResult, $expectedMsg)
  35. {
  36. $this->setupMocks(
  37. $sampleDataPackages,
  38. '/path/to/composer.json',
  39. $appRunResult,
  40. ['--no-update' => 1]
  41. );
  42. $commandInput = ['--no-update' => 1];
  43. $commandTester = $this->createCommandTester();
  44. $commandTester->execute($commandInput);
  45. $this->assertEquals($expectedMsg, $commandTester->getDisplay());
  46. }
  47. /**
  48. * @return array
  49. */
  50. public function processDataProvider()
  51. {
  52. return [
  53. 'No sample data found' => [
  54. 'sampleDataPackages' => [],
  55. 'appRunResult' => 1,
  56. 'expectedMsg' => 'There is no sample data for current set of modules.' . PHP_EOL,
  57. ],
  58. 'Successful sample data installation' => [
  59. 'sampleDataPackages' => [
  60. 'magento/module-cms-sample-data' => '1.0.0-beta',
  61. ],
  62. 'appRunResult' => 0,
  63. 'expectedMsg' => '',
  64. ],
  65. ];
  66. }
  67. /**
  68. * @return CommandTester
  69. */
  70. private function createCommandTester(): CommandTester
  71. {
  72. $commandTester = new CommandTester(
  73. new SampleDataRemoveCommand(
  74. $this->filesystemMock,
  75. $this->sampleDataDependencyMock,
  76. $this->arrayInputFactoryMock,
  77. $this->applicationFactoryMock
  78. )
  79. );
  80. return $commandTester;
  81. }
  82. /**
  83. * @param $sampleDataPackages
  84. * @param $pathToComposerJson
  85. * @return array
  86. */
  87. protected function expectedComposerArguments(
  88. array $sampleDataPackages,
  89. string $pathToComposerJson
  90. ) : array {
  91. return [
  92. 'command' => 'remove',
  93. '--working-dir' => $pathToComposerJson,
  94. '--no-interaction' => 1,
  95. '--no-progress' => 1,
  96. 'packages' => array_keys($sampleDataPackages),
  97. ];
  98. }
  99. }