Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
All Data Structures Namespaces Files Functions Variables Pages
SampleDataRemoveCommandTest.php
Go to the documentation of this file.
1 <?php
7 
9 use Symfony\Component\Console\Tester\CommandTester;
10 
12 {
13 
22  public function testExecute(array $sampleDataPackages, $appRunResult, $expectedMsg)
23  {
24  $this->setupMocks($sampleDataPackages, '/path/to/composer.json', $appRunResult);
25  $commandTester = $this->createCommandTester();
26  $commandTester->execute([]);
27 
28  $this->assertEquals($expectedMsg, $commandTester->getDisplay());
29  }
30 
39  public function testExecuteWithNoUpdate(array $sampleDataPackages, $appRunResult, $expectedMsg)
40  {
41  $this->setupMocks(
42  $sampleDataPackages,
43  '/path/to/composer.json',
44  $appRunResult,
45  ['--no-update' => 1]
46  );
47  $commandInput = ['--no-update' => 1];
48 
49  $commandTester = $this->createCommandTester();
50  $commandTester->execute($commandInput);
51 
52  $this->assertEquals($expectedMsg, $commandTester->getDisplay());
53  }
54 
58  public function processDataProvider()
59  {
60  return [
61  'No sample data found' => [
62  'sampleDataPackages' => [],
63  'appRunResult' => 1,
64  'expectedMsg' => 'There is no sample data for current set of modules.' . PHP_EOL,
65  ],
66  'Successful sample data installation' => [
67  'sampleDataPackages' => [
68  'magento/module-cms-sample-data' => '1.0.0-beta',
69  ],
70  'appRunResult' => 0,
71  'expectedMsg' => '',
72  ],
73  ];
74  }
75 
79  private function createCommandTester(): CommandTester
80  {
81  $commandTester = new CommandTester(
83  $this->filesystemMock,
84  $this->sampleDataDependencyMock,
85  $this->arrayInputFactoryMock,
86  $this->applicationFactoryMock
87  )
88  );
89  return $commandTester;
90  }
91 
97  protected function expectedComposerArguments(
98  array $sampleDataPackages,
99  string $pathToComposerJson
100  ) : array {
101  return [
102  'command' => 'remove',
103  '--working-dir' => $pathToComposerJson,
104  '--no-interaction' => 1,
105  '--no-progress' => 1,
106  'packages' => array_keys($sampleDataPackages),
107  ];
108  }
109 }
setupMocks( $sampleDataPackages, $pathToComposerJson, $appRunResult, $additionalComposerArgs=[])
testExecute(array $sampleDataPackages, $appRunResult, $expectedMsg)
expectedComposerArguments(array $sampleDataPackages, string $pathToComposerJson)
testExecuteWithNoUpdate(array $sampleDataPackages, $appRunResult, $expectedMsg)