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
|
|
|
public function getExitCode() |
67
|
|
|
{ |
68
|
|
|
return $this->exitCode; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function getOutput() |
72
|
|
|
{ |
73
|
|
|
return $this->output; |
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 a success message has to be rendered |
130
|
|
|
*/ |
131
|
|
|
public function assertSuccessMessage() |
132
|
|
|
{ |
133
|
|
|
$this->assertMessage('/Successfully executed command \w+:\w+:?\w+? with serial \w+-\w+-\w+-\w+-\w+ in \d+:\d+:\d+ s/'); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @When the process has been finished |
138
|
|
|
* @When the import process has been finished |
139
|
|
|
* @When the deletion process has been finished |
140
|
|
|
* @When the replacement process has been finished |
141
|
|
|
* @When the attribute import process has been finished |
142
|
|
|
* @When the attribute deletion process has been finished |
143
|
|
|
* @When the attribute replacement process has been finished |
144
|
|
|
* @When the attribute set import process has been finished |
145
|
|
|
* @When the attribute set deletion process has been finished |
146
|
|
|
* @When the attribute set replacement process has been finished |
147
|
|
|
* @When the category import process has been finished |
148
|
|
|
* @When the category deletion process has been finished |
149
|
|
|
* @When the category replacement process has been finished |
150
|
|
|
* @When the product import process has been finished |
151
|
|
|
* @When the product deletion process has been finished |
152
|
|
|
* @When the product replacement process has been finished |
153
|
|
|
*/ |
154
|
|
|
public function assertExitCode() |
155
|
|
|
{ |
156
|
|
|
PHPUnit_Framework_Assert::assertSame(0, $this->exitCode); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @Then a message :arg1 has to be rendered |
161
|
|
|
*/ |
162
|
|
|
public function assertMessage($arg1) |
163
|
|
|
{ |
164
|
|
|
PHPUnit_Framework_Assert::assertRegExp($arg1, array_pop($this->output)); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
protected function appendInstallDir($cmd) |
168
|
|
|
{ |
169
|
|
|
return sprintf('%s --installation-dir=%s', $cmd, $this->installDir); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
protected function prependInstallDir($cmd) |
173
|
|
|
{ |
174
|
|
|
return sprintf('%s/%s', $this->installDir, $cmd); |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.