1 | <?php |
||
23 | class FeatureContext extends \Behat\MinkExtension\Context\RawMinkContext |
||
|
|||
24 | { |
||
25 | /** |
||
26 | * @var array |
||
27 | */ |
||
28 | private $classes; |
||
29 | |||
30 | /** |
||
31 | * @var ObjectManager |
||
32 | */ |
||
33 | private $manager; |
||
34 | |||
35 | /** |
||
36 | * @var SchemaTool |
||
37 | */ |
||
38 | private $schemaTool; |
||
39 | |||
40 | /** |
||
41 | * Initializes context. |
||
42 | * |
||
43 | * @param ManagerRegistry $doctrine |
||
44 | */ |
||
45 | public function __construct(ManagerRegistry $doctrine) |
||
46 | { |
||
47 | $this->manager = $doctrine->getManager(); |
||
48 | $this->schemaTool = new SchemaTool($this->manager); |
||
49 | $this->classes = $this->manager->getMetadataFactory()->getAllMetadata(); |
||
50 | $this->inspector = new JsonInspector('javascript'); |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * @Given there is :nb dummy objects |
||
55 | * |
||
56 | * @param int $nbr |
||
57 | */ |
||
58 | public function thereIsDummyObjects($nbr) |
||
59 | { |
||
60 | for ($i = 1; $i <= $nbr; ++$i) { |
||
61 | $dummy = new Dummy(); |
||
62 | $dummy->setName('Dummy #'.$i); |
||
63 | $dummy->setAlias('Alias #'.($nbr - $i)); |
||
64 | |||
65 | $this->manager->persist($dummy); |
||
66 | } |
||
67 | |||
68 | $this->manager->flush(); |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * Checks that given JSON node is null |
||
73 | * |
||
74 | * @Then the JSON node :node should be null |
||
75 | */ |
||
76 | public function theJsonNodeShouldBeNull($node) |
||
77 | { |
||
78 | $actual = $this->getJsonNodeValue($node); |
||
79 | PHPUnit::assertNull($actual, sprintf('The node value is `%s`', json_encode($actual))); |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * @Then the JSON node :node should be equal to the boolean :value |
||
84 | */ |
||
85 | public function theJsonNodeShouldBeEmpty($node, $value) |
||
86 | { |
||
87 | $actual = $this->getJsonNodeValue($node); |
||
88 | |||
89 | if ('false' === $value) { |
||
90 | $value = false; |
||
91 | } else { |
||
92 | $value = (bool) $value; |
||
93 | } |
||
94 | |||
95 | PHPUnit::assertEquals($value, $actual, sprintf('The node value is `%s`', json_encode($actual))); |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * @param string $node JSON node. |
||
100 | * |
||
101 | * @return mixed JSON node value. |
||
102 | */ |
||
103 | private function getJsonNodeValue($node) |
||
104 | { |
||
105 | $json = $this->getJson(); |
||
106 | return $this->inspector->evaluate($json, $node); |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * @return Json Get JSON content of the response. |
||
111 | */ |
||
112 | private function getJson() |
||
116 | } |
||
117 |
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.