1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Behat\Behat\Tester\Exception\PendingException; |
4
|
|
|
use Behat\Behat\Context\Context; |
5
|
|
|
use Behat\Behat\Context\SnippetAcceptingContext; |
6
|
|
|
use Behat\Gherkin\Node\PyStringNode; |
7
|
|
|
use Behat\Gherkin\Node\TableNode; |
8
|
|
|
use Behat\Behat\Hook\Scope\AfterScenarioScope; |
9
|
|
|
|
10
|
|
|
use Symfony\Component\Finder\Finder; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Defines application features from the specific context. |
14
|
|
|
*/ |
15
|
|
|
class FeatureContext implements Context, SnippetAcceptingContext |
|
|
|
|
16
|
|
|
{ |
17
|
|
|
private $dir; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Initializes context. |
21
|
|
|
* |
22
|
|
|
* Every scenario gets its own context instance. |
23
|
|
|
* You can also pass arbitrary arguments to the |
24
|
|
|
* context constructor through behat.yml. |
25
|
|
|
*/ |
26
|
|
|
public function __construct() |
27
|
|
|
{ |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @Given there is :dir directory in root of the application |
32
|
|
|
*/ |
33
|
|
|
public function thereIsDirectoryInRootOfTheApplication($dir) |
34
|
|
|
{ |
35
|
|
|
if (!file_exists($dir)) { |
36
|
|
|
mkdir($dir); |
37
|
|
|
} |
38
|
|
|
$this->dir = $dir; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @Given I am in a root directory of application |
43
|
|
|
*/ |
44
|
|
|
public function iAmInARootDirectoryOfApplication() |
45
|
|
|
{ |
46
|
|
|
|
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @Given I run :command |
51
|
|
|
*/ |
52
|
|
|
public function iRun($command) |
53
|
|
|
{ |
54
|
|
|
exec($command); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @Then I see the file witch name contains :fileName |
59
|
|
|
*/ |
60
|
|
|
public function iSeeTheFileWitchNameContains($fileName) |
61
|
|
|
{ |
62
|
|
|
$this->fileName = $fileName; |
|
|
|
|
63
|
|
|
$pattern = getcwd() . '/' . $this->dir; |
64
|
|
|
if (count((new Finder())->files()->in($pattern)->name('*' . $fileName)) === 0) { |
65
|
|
|
throw new \Exception('File does not exist'); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @Then this file body contains: |
71
|
|
|
*/ |
72
|
|
|
public function thisFileBodyContains(PyStringNode $string) |
73
|
|
|
{ |
74
|
|
|
$pattern = getcwd() . '/' . $this->dir; |
75
|
|
|
$content = ''; |
76
|
|
|
foreach ((new Finder())->files()->in($pattern)->name('*' . $this->fileName) as $file) { |
77
|
|
|
$content = $file->getContents(); |
78
|
|
|
} |
79
|
|
|
if (strpos($content, $string->getRaw()) === false) { |
80
|
|
|
throw new \Exception('File contains wrong data'); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @AfterScenario |
86
|
|
|
*/ |
87
|
|
|
public function deleteMigrations(AfterScenarioScope $scope) |
|
|
|
|
88
|
|
|
{ |
89
|
|
|
$pattern = getcwd() . '/' . $this->dir . '/*.php'; |
90
|
|
|
array_map('unlink', glob($pattern)); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.