|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Sergii Bondarenko, <[email protected]> |
|
4
|
|
|
*/ |
|
5
|
|
|
namespace Behat; |
|
6
|
|
|
|
|
7
|
|
|
// Interface for environments. |
|
8
|
|
|
use Behat\Testwork\Environment\Environment; |
|
9
|
|
|
// Interface for environments with contexts. |
|
10
|
|
|
use Behat\Behat\Context\Environment\ContextEnvironment; |
|
11
|
|
|
// Interface for uninitialized environments with contexts. |
|
12
|
|
|
use Behat\Behat\Context\Environment\UninitializedContextEnvironment; |
|
13
|
|
|
// Interface for environment readers. |
|
14
|
|
|
use Behat\Testwork\Environment\Reader\EnvironmentReader as EnvironmentReaderInterface; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class EnvironmentReader. |
|
18
|
|
|
* |
|
19
|
|
|
* @package Behat |
|
20
|
|
|
*/ |
|
21
|
|
|
final class EnvironmentReader implements EnvironmentReaderInterface |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* Path to extension sources. |
|
25
|
|
|
* |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
private $path = ''; |
|
29
|
|
|
/** |
|
30
|
|
|
* Namespace of the extension. |
|
31
|
|
|
* |
|
32
|
|
|
* @var string |
|
33
|
|
|
*/ |
|
34
|
|
|
private $namespace = ''; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* EnvironmentReader constructor. |
|
38
|
|
|
* |
|
39
|
|
|
* @param string $path |
|
40
|
|
|
* @param string $namespace |
|
41
|
|
|
*/ |
|
42
|
|
|
public function __construct($path, $namespace) |
|
43
|
|
|
{ |
|
44
|
|
|
$this->path = $path; |
|
45
|
|
|
$this->namespace = $namespace; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* {@inheritdoc} |
|
50
|
|
|
*/ |
|
51
|
|
|
public function supportsEnvironment(Environment $environment) |
|
52
|
|
|
{ |
|
53
|
|
|
return $environment instanceof ContextEnvironment; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* {@inheritdoc} |
|
58
|
|
|
*/ |
|
59
|
|
|
public function readEnvironmentCallees(Environment $environment) |
|
60
|
|
|
{ |
|
61
|
|
|
if ($environment instanceof UninitializedContextEnvironment) { |
|
62
|
|
|
// Read all extension contexts. |
|
63
|
|
|
foreach (new \RecursiveIteratorIterator( |
|
64
|
|
|
new \RecursiveDirectoryIterator($this->path, \FilesystemIterator::SKIP_DOTS) |
|
65
|
|
|
) as $path => $object) { |
|
66
|
|
|
$basename = basename($path); |
|
67
|
|
|
|
|
68
|
|
|
// Allow names which not starts from "Raw" and ends by "Context.php". |
|
69
|
|
|
if (strrpos($basename, 'Context.php') !== false && strpos($basename, 'Raw') !== 0) { |
|
70
|
|
|
$class = strtr($path, [$this->path => $this->namespace, '.php' => '', '/' => '\\']); |
|
71
|
|
|
|
|
72
|
|
|
if (!$environment->hasContextClass($class)) { |
|
73
|
|
|
$environment->registerContextClass($class); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
// Just return an empty array and allow Behat to scan context classes for callees. |
|
80
|
|
|
return []; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|