|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Behat\Behat\Context\Context; |
|
4
|
|
|
use Behat\Behat\Hook\Scope\AfterScenarioScope; |
|
5
|
|
|
use Behat\Behat\Hook\Scope\BeforeScenarioScope; |
|
6
|
|
|
use Behat\Behat\Tester\Exception\PendingException; |
|
7
|
|
|
use TechDivision\Import\Adapter\PhpFilesystemAdapter; |
|
8
|
|
|
use Behat\Symfony2Extension\Context\KernelAwareContext; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Defines application features from the specific context. |
|
12
|
|
|
*/ |
|
13
|
|
|
class ConsoleContext implements Context, KernelAwareContext |
|
14
|
|
|
{ |
|
15
|
|
|
|
|
16
|
|
|
use Behat\Symfony2Extension\Context\KernelDictionary; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* The Magento 2 installation directory. |
|
20
|
|
|
* |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
private $installDir; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* The output of the last executed command. |
|
27
|
|
|
* |
|
28
|
|
|
* @var array |
|
29
|
|
|
*/ |
|
30
|
|
|
private $output = array(); |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* The return value of the last executed command. |
|
34
|
|
|
* |
|
35
|
|
|
* @var integer |
|
36
|
|
|
*/ |
|
37
|
|
|
private $exitCode = 0; |
|
38
|
|
|
|
|
39
|
|
|
/** @BeforeFeature */ |
|
40
|
|
|
public static function prepareForTheFeature() |
|
41
|
|
|
{ |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** @BeforeScenario */ |
|
45
|
|
|
public function before(BeforeScenarioScope $scope) |
|
|
|
|
|
|
46
|
|
|
{ |
|
47
|
|
|
|
|
48
|
|
|
$this->installDir = $this->getContainer()->getParameter('install_dir'); |
|
49
|
|
|
|
|
50
|
|
|
$filesystemAdapter = new PhpFilesystemAdapter(); |
|
51
|
|
|
|
|
52
|
|
|
foreach (glob(sprintf('%s/var/importexport/*', $this->installDir)) as $file) { |
|
53
|
|
|
if (is_file($file)) { |
|
54
|
|
|
$filesystemAdapter->delete($file); |
|
55
|
|
|
} else { |
|
56
|
|
|
$filesystemAdapter->removeDir($file, true); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** @AfterScenario */ |
|
62
|
|
|
public function after(AfterScenarioScope $scope) |
|
|
|
|
|
|
63
|
|
|
{ |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
protected function appendInstallDir($cmd) |
|
67
|
|
|
{ |
|
68
|
|
|
return sprintf('%s --installation-dir=%s', $cmd, $this->installDir); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
protected function prependInstallDir($cmd) |
|
72
|
|
|
{ |
|
73
|
|
|
return sprintf('%s/%s', $this->installDir, $cmd); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @Given a third party system has copied the file :arg1 into the import folder :arg2 |
|
78
|
|
|
*/ |
|
79
|
|
|
public function aThirdPartySystemHasCopiedTheFileIntoTheImportFolder($arg1, $arg2) |
|
80
|
|
|
{ |
|
81
|
|
|
|
|
82
|
|
|
if (copy($arg1, $dest = sprintf('%s/%s/%s', $this->installDir, $arg2, basename($arg1)))) { |
|
83
|
|
|
return; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
throw new \Exception(sprintf('Can\'t copy file %s to %s', $arg1, $dest)); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @Given that a new file :arg1 containing data is available |
|
91
|
|
|
*/ |
|
92
|
|
|
public function thatANewFileContainingDataIsAvailable($arg1) |
|
93
|
|
|
{ |
|
94
|
|
|
|
|
95
|
|
|
if (is_file($this->prependInstallDir($arg1))) { |
|
96
|
|
|
return; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
throw new \Exception(sprintf('Can\'t find file %s', $arg1)); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @When the command :arg1 has been executed |
|
104
|
|
|
*/ |
|
105
|
|
|
public function theCommandHasBeenExecuted($arg1) |
|
106
|
|
|
{ |
|
107
|
|
|
exec($this->appendInstallDir($arg1), $this->output, $this->exitCode); |
|
108
|
|
|
PHPUnit_Framework_Assert::assertNotEquals(1, $this->exitCode); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @When the magento command :arg1 has been executed |
|
113
|
|
|
*/ |
|
114
|
|
|
public function theMagentoCommandHasBeenExecuted($arg1) |
|
115
|
|
|
{ |
|
116
|
|
|
exec($this->prependInstallDir($arg1), $this->output, $this->exitCode); |
|
117
|
|
|
PHPUnit_Framework_Assert::assertNotEquals(1, $this->exitCode); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @Given the magento index has been updated |
|
122
|
|
|
*/ |
|
123
|
|
|
public function theMagentoIndexHasBeenUpdated() |
|
124
|
|
|
{ |
|
125
|
|
|
$this->theMagentoCommandHasBeenExecuted('bin/magento indexer:reindex'); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @Then all the data in the file :arg1 has been imported |
|
130
|
|
|
*/ |
|
131
|
|
|
public function allTheDataInTheFileHasBeenImported2($arg1) |
|
|
|
|
|
|
132
|
|
|
{ |
|
133
|
|
|
throw new PendingException(); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
public function getExitCode() |
|
137
|
|
|
{ |
|
138
|
|
|
return $this->exitCode; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
public function getOutput() |
|
142
|
|
|
{ |
|
143
|
|
|
return $this->output; |
|
144
|
|
|
} |
|
145
|
|
|
} |
|
146
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.