|
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\MinkExtension\Context\MinkContext; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Defines application features from the specific context. |
|
12
|
|
|
*/ |
|
13
|
|
|
class FeatureContext extends MinkContext implements Context |
|
14
|
|
|
{ |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* The Magento 2 installation directory. |
|
18
|
|
|
* |
|
19
|
|
|
* @var string |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $installDir; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Initializes context. |
|
25
|
|
|
* |
|
26
|
|
|
* Every scenario gets its own context instance. |
|
27
|
|
|
* You can also pass arbitrary arguments to the |
|
28
|
|
|
* context constructor through behat.yml. |
|
29
|
|
|
* |
|
30
|
|
|
* @param string $installDir The Magento 2 installation directory |
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct($installDir) |
|
33
|
|
|
{ |
|
34
|
|
|
$this->installDir = $installDir; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** @BeforeFeature */ |
|
38
|
|
|
public static function prepareForTheFeature() |
|
39
|
|
|
{ |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** @BeforeScenario */ |
|
43
|
|
|
public function before(BeforeScenarioScope $scope) |
|
|
|
|
|
|
44
|
|
|
{ |
|
45
|
|
|
|
|
46
|
|
|
$filesystemAdapter = new PhpFilesystemAdapter(); |
|
47
|
|
|
|
|
48
|
|
|
foreach (glob(sprintf('%s/var/importexport/*', $this->installDir)) as $file) { |
|
49
|
|
|
if (is_file($file)) { |
|
50
|
|
|
$filesystemAdapter->delete($file); |
|
51
|
|
|
} else { |
|
52
|
|
|
$filesystemAdapter->removeDir($file, true); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** @AfterScenario */ |
|
58
|
|
|
public function after(AfterScenarioScope $scope) |
|
|
|
|
|
|
59
|
|
|
{ |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
protected function appendInstallDir($cmd) |
|
63
|
|
|
{ |
|
64
|
|
|
return sprintf('%s --installation-dir=%s', $cmd, $this->installDir); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
protected function prependInstallDir($cmd) |
|
68
|
|
|
{ |
|
69
|
|
|
return sprintf('%s/%s', $this->installDir, $cmd); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @Given a third party system has copied the file :arg1 into the import folder :arg2 |
|
74
|
|
|
*/ |
|
75
|
|
|
public function aThirdPartySystemHasCopiedTheFileIntoTheImportFolder2($arg1, $arg2) |
|
76
|
|
|
{ |
|
77
|
|
|
|
|
78
|
|
|
if (copy($arg1, $dest = sprintf('%s/%s/%s', $this->installDir, $arg2, basename($arg1)))) { |
|
79
|
|
|
return; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
throw new \Exception(sprintf('Can\'t copy file %s to %s', $arg1, $dest)); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @Given that a new file :arg1 containing data is available |
|
87
|
|
|
*/ |
|
88
|
|
|
public function thatANewFileContainingDataIsAvailable($arg1) |
|
89
|
|
|
{ |
|
90
|
|
|
|
|
91
|
|
|
if (is_file($this->prependInstallDir($arg1))) { |
|
92
|
|
|
return; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
throw new \Exception(sprintf('Can\'t find file %s', $arg1)); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @When the command :arg1 has been executed |
|
100
|
|
|
*/ |
|
101
|
|
|
public function theCommandHasBeenExecuted($arg1) |
|
102
|
|
|
{ |
|
103
|
|
|
$ret = 0; |
|
104
|
|
|
system($this->appendInstallDir($arg1), $ret); |
|
105
|
|
|
PHPUnit_Framework_Assert::assertNotEquals(1, $ret); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @When the magento command :arg1 has been executed |
|
110
|
|
|
*/ |
|
111
|
|
|
public function theMagentoCommandHasBeenExecuted($arg1) |
|
112
|
|
|
{ |
|
113
|
|
|
$ret = 0; |
|
114
|
|
|
system($this->prependInstallDir($arg1), $ret); |
|
115
|
|
|
PHPUnit_Framework_Assert::assertNotEquals(1, $ret); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* @Then all the data in the file :arg1 has been imported |
|
120
|
|
|
*/ |
|
121
|
|
|
public function allTheDataInTheFileHasBeenImported2($arg1) |
|
|
|
|
|
|
122
|
|
|
{ |
|
123
|
|
|
throw new PendingException(); |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.