Completed
Push — master ( 319b56...e8ca6b )
by Samuel
14s
created

FeatureContext::theValueShouldBeAnArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Behat\Sf2DemoBundle\Features\Context;
4
5
use Symfony\Component\HttpKernel\KernelInterface;
6
use Behat\Symfony2Extension\Context\KernelAwareContext;
7
8
class FeatureContext implements KernelAwareContext
9
{
10
    private $kernel;
11
    private $containerParameters;
12
    private $parameterKey;
13
14
    /**
15
     * Sets HttpKernel instance.
16
     * This method will be automatically called by Symfony2Extension ContextInitializer.
17
     *
18
     * @param KernelInterface $kernel
19
     */
20
    public function setKernel(KernelInterface $kernel)
21
    {
22
        $this->kernel = $kernel;
23
    }
24
25
    /**
26
     * @Given /^I have a kernel instance$/
27
     */
28
    public function iHaveAKernelInstance()
29
    {
30
        \PHPUnit_Framework_Assert::assertInstanceOf('Symfony\\Component\\HttpKernel\\KernelInterface', $this->kernel);
31
    }
32
33
    /**
34
     * @When /^I get container parameters from it$/
35
     */
36
    public function iGetContainerParametersFromIt()
37
    {
38
        $this->containerParameters = $this->kernel->getContainer()->getParameterBag()->all();
0 ignored issues
show
Bug introduced by
The method getParameterBag() does not exist on Symfony\Component\Depend...tion\ContainerInterface. Did you maybe mean getParameter()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
39
    }
40
41
    /**
42
     * @Then /^there should be "([^"]*)" parameter$/
43
     */
44
    public function thereShouldBeParameter($key)
45
    {
46
        \PHPUnit_Framework_Assert::assertArrayHasKey($key, $this->containerParameters);
47
        $this->parameterKey = $key;
48
    }
49
50
    /**
51
     * @Then /^there should not be "([^"]*)" parameter$/
52
     */
53
    public function thereShouldNotBeParameter($key)
54
    {
55
        \PHPUnit_Framework_Assert::assertArrayNotHasKey($key, $this->containerParameters);
56
    }
57
58
    /**
59
     * @Given /^it should be set to "([^"]*)" value$/
60
     */
61
    public function itShouldBeSetToValue($val)
62
    {
63
        \PHPUnit_Framework_Assert::assertSame($val, $this->containerParameters[$this->parameterKey]);
64
    }
65
66
    /**
67
     * @Then the value should be an array
68
     */
69
    public function theValueShouldBeAnArray()
70
    {
71
        \PHPUnit_Framework_Assert::assertInternalType('array', $this->containerParameters[$this->parameterKey]);
72
    }
73
74
    /**
75
     * @Then the array should contain only the values :arg
76
     * @param  string $arg Comma delimited string, to represent an array's values
77
     */
78
    public function theArrayShouldContainOnlyTheValues($arg)
79
    {
80
        $values = explode(',', $arg);
81
        
82
        \PHPUnit_Framework_Assert::assertSame($values, $this->containerParameters[$this->parameterKey]);
83
    }
84
}
85