|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Sylius package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Paweł Jędrzejewski |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Sylius\Behat\MultiContainerExtension\Context\Environment; |
|
13
|
|
|
|
|
14
|
|
|
use Behat\Behat\Context\Context; |
|
15
|
|
|
use Behat\Behat\Context\Environment\ContextEnvironment; |
|
16
|
|
|
use Behat\Behat\Context\Exception\ContextNotFoundException; |
|
17
|
|
|
use Behat\Behat\Context\Exception\WrongContextClassException; |
|
18
|
|
|
use Behat\Testwork\Environment\StaticEnvironment; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @author Kamil Kokot <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
|
final class UninitializedContextServiceEnvironment extends StaticEnvironment implements ContextEnvironment |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var array[] |
|
27
|
|
|
*/ |
|
28
|
|
|
private $contextServices = []; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param string $serviceId |
|
32
|
|
|
* @param string $contextClass |
|
33
|
|
|
*/ |
|
34
|
|
|
public function registerContextClass($serviceId, $contextClass) |
|
35
|
|
|
{ |
|
36
|
|
|
if (!class_exists($contextClass)) { |
|
37
|
|
|
throw new ContextNotFoundException(sprintf( |
|
38
|
|
|
'`%s` context class not found and can not be used.', |
|
39
|
|
|
$contextClass |
|
40
|
|
|
), $contextClass); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
$reflClass = new \ReflectionClass($contextClass); |
|
44
|
|
|
|
|
45
|
|
|
if (!$reflClass->implementsInterface(Context::class)) { |
|
46
|
|
|
throw new WrongContextClassException(sprintf( |
|
47
|
|
|
'Every context class must implement Behat Context interface, but `%s` does not.', |
|
48
|
|
|
$contextClass |
|
49
|
|
|
), $contextClass); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
$this->contextServices[$serviceId] = $contextClass; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* {@inheritdoc} |
|
57
|
|
|
*/ |
|
58
|
|
|
public function hasContexts() |
|
59
|
|
|
{ |
|
60
|
|
|
return count($this->contextServices) > 0; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* {@inheritdoc} |
|
65
|
|
|
*/ |
|
66
|
|
|
public function getContextClasses() |
|
67
|
|
|
{ |
|
68
|
|
|
return array_values($this->contextServices); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* {@inheritdoc} |
|
73
|
|
|
*/ |
|
74
|
|
|
public function hasContextClass($class) |
|
75
|
|
|
{ |
|
76
|
|
|
return array_search($class, $this->contextServices, true); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @return array[] |
|
81
|
|
|
*/ |
|
82
|
|
|
public function getContextsServicesIds() |
|
83
|
|
|
{ |
|
84
|
|
|
return array_keys($this->contextServices); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|