|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Behat Gherkin. |
|
5
|
|
|
* (c) Konstantin Kudryashov <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Behat\Gherkin\Filter; |
|
12
|
|
|
|
|
13
|
|
|
use Behat\Gherkin\Node\FeatureNode; |
|
14
|
|
|
use Behat\Gherkin\Node\ScenarioInterface; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Filters scenarios by feature/scenario name. |
|
18
|
|
|
* |
|
19
|
|
|
* @author Konstantin Kudryashov <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class NameFilter extends SimpleFilter |
|
22
|
|
|
{ |
|
23
|
|
|
protected $filterString; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Initializes filter. |
|
27
|
|
|
* |
|
28
|
|
|
* @param string $filterString Name filter string |
|
29
|
|
|
*/ |
|
30
|
3 |
|
public function __construct($filterString) |
|
31
|
|
|
{ |
|
32
|
3 |
|
$this->filterString = trim($filterString); |
|
33
|
3 |
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Checks if Feature matches specified filter. |
|
37
|
|
|
* |
|
38
|
|
|
* @param FeatureNode $feature Feature instance |
|
39
|
|
|
* |
|
40
|
|
|
* @return Boolean |
|
41
|
|
|
*/ |
|
42
|
2 |
|
public function isFeatureMatch(FeatureNode $feature) |
|
43
|
|
|
{ |
|
44
|
2 |
|
if ('/' === $this->filterString[0]) { |
|
45
|
1 |
|
return 1 === preg_match($this->filterString, $feature->getTitle()); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
2 |
|
return false !== mb_strpos($feature->getTitle(), $this->filterString, 0, 'utf8'); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Checks if scenario or outline matches specified filter. |
|
53
|
|
|
* |
|
54
|
|
|
* @param ScenarioInterface $scenario Scenario or Outline node instance |
|
55
|
|
|
* |
|
56
|
|
|
* @return Boolean |
|
57
|
|
|
*/ |
|
58
|
2 |
|
public function isScenarioMatch(ScenarioInterface $scenario) |
|
59
|
|
|
{ |
|
60
|
2 |
|
if ('/' === $this->filterString[0] && 1 === preg_match($this->filterString, $scenario->getTitle())) { |
|
61
|
1 |
|
return true; |
|
62
|
2 |
|
} elseif (false !== mb_strpos($scenario->getTitle(), $this->filterString, 0, 'utf8')) { |
|
63
|
2 |
|
return true; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
2 |
|
return false; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|