1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Behat\Gherkin\Node\PyStringNode; |
4
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
5
|
|
|
use Behat\MinkExtension\Context\RawMinkContext; |
6
|
|
|
use Behat\Behat\Context\SnippetAcceptingContext; |
7
|
|
|
use Behat\Gherkin\Node\TableNode; |
8
|
|
|
|
9
|
|
|
class FeatureContext extends RawMinkContext implements SnippetAcceptingContext |
|
|
|
|
10
|
|
|
{ |
11
|
|
|
private $tmpDir; |
12
|
|
|
private $fs; |
13
|
|
|
private $app; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Initializes context. Every scenario gets its own context object. |
17
|
|
|
* |
18
|
|
|
* @param array $parameters Suite parameters (set them up through behat.yml) |
|
|
|
|
19
|
|
|
*/ |
20
|
|
|
public function __construct() |
21
|
|
|
{ |
22
|
|
|
$this->fs = new Filesystem; |
23
|
|
|
$this->tmpDir = __DIR__.'/fixtures/tmp'; |
24
|
|
|
$this->fs->remove($this->tmpDir); |
25
|
|
|
$this->writeContent($this->tmpDir.'/App/Resources/config/rad.yml'); |
26
|
|
|
$this->writeContent($this->tmpDir.'/App/Resources/config/rad_convention.yml'); |
27
|
|
|
$this->fs->mkdir($this->tmpDir.'/App/Entity'); |
28
|
|
|
$this->app = new \fixtures\AppKernel; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function createSchema() |
32
|
|
|
{ |
33
|
|
|
$this->app->boot(); |
34
|
|
|
$em = $this->app->getContainer()->get('doctrine.orm.default_entity_manager'); |
35
|
|
|
$schemaTool = new \Doctrine\ORM\Tools\SchemaTool($em); |
36
|
|
|
$schemaTool->dropSchema($em->getMetadataFactory()->getAllMetadata()); |
37
|
|
|
$schemaTool->createSchema($em->getMetadataFactory()->getAllMetadata()); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @Given I write in :path: |
42
|
|
|
*/ |
43
|
|
|
public function iWriteIn($path, PyStringNode $class) |
44
|
|
|
{ |
45
|
|
|
$path = $this->tmpDir.'/'.$path; |
46
|
|
|
$this->writeContent($path, $class); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @Then :alias should be a registered form type |
51
|
|
|
*/ |
52
|
|
|
public function shouldBeARegisteredFormType($alias) |
53
|
|
|
{ |
54
|
|
|
$this->app->boot(); |
55
|
|
|
$this->app->getContainer()->get('form.factory')->create($alias); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @Then :alias should not be a registered form type |
60
|
|
|
*/ |
61
|
|
|
public function shouldNotBeARegisteredFormType($alias) |
62
|
|
|
{ |
63
|
|
|
$this->app->boot(); |
64
|
|
|
if ($this->app->getContainer()->get('form.registry')->hasType($alias)) { |
65
|
|
|
throw new \LogicException(sprintf('Form type with alias %s was found', $alias)); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @Then :alias should be a registered twig extension |
71
|
|
|
*/ |
72
|
|
|
public function shouldBeARegisteredTwigExtension($alias) |
73
|
|
|
{ |
74
|
|
|
$this->app->boot(); |
75
|
|
|
$twig = $this->app->getContainer()->get('twig'); |
76
|
|
|
if (!$twig->hasExtension($alias)) { |
77
|
|
|
throw new \LogicException(sprintf('Twig extension with alias %s was not found.', $alias)); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @Then :alias should not be a registered twig extension |
83
|
|
|
*/ |
84
|
|
|
public function shouldNotBeARegisteredTwigExtension($alias) |
85
|
|
|
{ |
86
|
|
|
$this->app->boot(); |
87
|
|
|
$twig = $this->app->getContainer()->get('twig'); |
88
|
|
|
if ($twig->hasExtension($alias)) { |
89
|
|
|
throw new \LogicException(sprintf('Twig extension with alias %s was found.', $alias)); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @Then :alias should be a registered validator |
95
|
|
|
*/ |
96
|
|
|
public function shouldBeARegisteredValidator($alias) |
97
|
|
|
{ |
98
|
|
|
$this->app->boot(); |
99
|
|
|
$this->app->getContainer()->get(sprintf('app.validator.constraints.%s_validator', $alias)); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @Then :alias should not be a registered validator |
104
|
|
|
*/ |
105
|
|
|
public function shouldNotBeARegisteredValidator($alias) |
106
|
|
|
{ |
107
|
|
|
$this->app->boot(); |
108
|
|
|
if ($this->app->getContainer()->has(sprintf('app.validator.constraints.%s_validator', $alias))) { |
109
|
|
|
throw new \LogicException(sprintf('Valdiator with alias %s was found.', $alias)); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @Then :id should be a registered service |
115
|
|
|
*/ |
116
|
|
|
public function shouldBeARegisteredService($id) |
117
|
|
|
{ |
118
|
|
|
$this->app->boot(); |
119
|
|
|
$this->app->getContainer()->get($id); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @Then :id should not be a registered service |
124
|
|
|
*/ |
125
|
|
|
public function shouldNotBeARegisteredService($id) |
126
|
|
|
{ |
127
|
|
|
$this->app->boot(); |
128
|
|
|
if ($this->app->getContainer()->has($id)) { |
129
|
|
|
throw new \LogicException(sprintf('service %s was found.', $id)); |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @When I visit :route page |
135
|
|
|
* @When I visit :route page: |
136
|
|
|
*/ |
137
|
|
|
public function visitRoute($route, TableNode $params = null) |
138
|
|
|
{ |
139
|
|
|
$this->createSchema(); |
140
|
|
|
$this->app->boot(); |
141
|
|
|
$url = $this |
142
|
|
|
->app |
143
|
|
|
->getContainer() |
144
|
|
|
->get('router') |
145
|
|
|
->generate($route, $params ? $params->getRowsHash() : array()) |
146
|
|
|
; |
147
|
|
|
|
148
|
|
|
$this->getMink()->getSession()->visit($this->locatePath($url)); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @Then the file :file should contain :content |
153
|
|
|
*/ |
154
|
|
|
public function theFileShouldContain($file, $content) |
155
|
|
|
{ |
156
|
|
|
if ($content !== file_get_contents($this->tmpDir.'/'.$file)) { |
157
|
|
|
throw new \LogicException(sprintf('file %s does not contain %s.', $file, $content)); |
158
|
|
|
} |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
private function writeContent($path, $content = '') |
162
|
|
|
{ |
163
|
|
|
$this->fs->mkdir(dirname($path)); |
164
|
|
|
$fd = fopen($path, 'w'); |
165
|
|
|
fwrite($fd, $content); |
166
|
|
|
fclose($fd); |
167
|
|
|
} |
168
|
|
|
} |
169
|
|
|
|
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.