FeatureContext   A
last analyzed

Complexity

Total Complexity 21

Size/Duplication

Total Lines 160
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 7

Importance

Changes 0
Metric Value
wmc 21
lcom 2
cbo 7
dl 0
loc 160
rs 10
c 0
b 0
f 0

14 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A createSchema() 0 8 1
A iWriteIn() 0 5 1
A shouldBeARegisteredFormType() 0 5 1
A shouldNotBeARegisteredFormType() 0 7 2
A shouldBeARegisteredTwigExtension() 0 8 2
A shouldNotBeARegisteredTwigExtension() 0 8 2
A shouldBeARegisteredValidator() 0 5 1
A shouldNotBeARegisteredValidator() 0 7 2
A shouldBeARegisteredService() 0 5 1
A shouldNotBeARegisteredService() 0 7 2
A visitRoute() 0 13 2
A theFileShouldContain() 0 6 2
A writeContent() 0 7 1
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
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
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)
0 ignored issues
show
Bug introduced by
There is no parameter named $parameters. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
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