|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* (c) FSi sp. z o.o. <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
declare(strict_types=1); |
|
11
|
|
|
|
|
12
|
|
|
namespace FSi\Bundle\AdminBundle\Behat\Context; |
|
13
|
|
|
|
|
14
|
|
|
use Behat\Mink\Driver\Selenium2Driver; |
|
15
|
|
|
use Behat\Mink\Mink; |
|
16
|
|
|
use Behat\Mink\Session; |
|
17
|
|
|
use Behat\MinkExtension\Context\MinkAwareContext; |
|
18
|
|
|
use Behat\Symfony2Extension\Context\KernelAwareContext; |
|
19
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
20
|
|
|
use Doctrine\ORM\EntityRepository; |
|
21
|
|
|
use Faker\Factory; |
|
22
|
|
|
use Faker\Generator; |
|
23
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
24
|
|
|
use Symfony\Component\HttpKernel\KernelInterface; |
|
25
|
|
|
|
|
26
|
|
|
abstract class AbstractContext implements KernelAwareContext, MinkAwareContext |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* @var KernelInterface |
|
30
|
|
|
*/ |
|
31
|
|
|
private $kernel; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var Mink |
|
35
|
|
|
*/ |
|
36
|
|
|
private $mink; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var array |
|
40
|
|
|
*/ |
|
41
|
|
|
private $minkParameters; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var Generator|null |
|
45
|
|
|
*/ |
|
46
|
|
|
private $faker; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @var EntityManagerInterface|null |
|
50
|
|
|
*/ |
|
51
|
|
|
private $entityManager; |
|
52
|
|
|
|
|
53
|
|
|
public function setMink(Mink $mink): void |
|
54
|
|
|
{ |
|
55
|
|
|
$this->mink = $mink; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function setMinkParameters(array $parameters): void |
|
59
|
|
|
{ |
|
60
|
|
|
$this->minkParameters = $parameters; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function setKernel(KernelInterface $kernel): void |
|
64
|
|
|
{ |
|
65
|
|
|
$this->kernel = $kernel; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
protected function getRepository($className): EntityRepository |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->getEntityManager()->getRepository($className); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
protected function getEntityManager(): EntityManagerInterface |
|
74
|
|
|
{ |
|
75
|
|
|
if (null === $this->entityManager) { |
|
76
|
|
|
/** @var EntityManagerInterface $manager */ |
|
77
|
|
|
$entityManager = $this->getContainer()->get('doctrine.orm.entity_manager'); |
|
78
|
|
|
$this->entityManager = $entityManager; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
return $this->entityManager; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
protected function getFaker(): Generator |
|
85
|
|
|
{ |
|
86
|
|
|
if (null === $this->faker) { |
|
87
|
|
|
$this->faker = Factory::create(); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
return $this->faker; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
protected function getMinkParameters(): array |
|
94
|
|
|
{ |
|
95
|
|
|
return $this->minkParameters; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
protected function getSession($name = null): Session |
|
99
|
|
|
{ |
|
100
|
|
|
return $this->mink->getSession($name); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
protected function getKernel(): KernelInterface |
|
104
|
|
|
{ |
|
105
|
|
|
return $this->kernel; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
protected function getContainer(): ContainerInterface |
|
109
|
|
|
{ |
|
110
|
|
|
return $this->kernel->getContainer(); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
protected function isSeleniumDriverUsed(): bool |
|
114
|
|
|
{ |
|
115
|
|
|
return $this->getSession()->getDriver() instanceof Selenium2Driver; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
protected function parseScenarioValue($rawValue) |
|
119
|
|
|
{ |
|
120
|
|
|
$value = trim($rawValue); |
|
121
|
|
|
switch ($value) { |
|
122
|
|
|
case 'false': |
|
123
|
|
|
return false; |
|
124
|
|
|
case 'true': |
|
125
|
|
|
return true; |
|
126
|
|
|
default: |
|
127
|
|
|
return $value; |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|