|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Behat\Behat\Tester\Exception\PendingException; |
|
|
|
|
|
|
4
|
|
|
use Behat\Behat\Context\Context; |
|
|
|
|
|
|
5
|
|
|
use Behat\Behat\Context\SnippetAcceptingContext; |
|
|
|
|
|
|
6
|
|
|
use Behat\Gherkin\Node\PyStringNode; |
|
|
|
|
|
|
7
|
|
|
use Behat\Gherkin\Node\TableNode; |
|
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Defines application features from the specific context. |
|
11
|
|
|
*/ |
|
12
|
|
|
class FeatureContext implements Context, SnippetAcceptingContext |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var string Name of directory where test files are keept |
|
16
|
|
|
*/ |
|
17
|
|
|
private $sourceDir; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var string[] Arguments used when invoking readme-tester |
|
21
|
|
|
*/ |
|
22
|
|
|
private $args = []; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var integer Return value of the last readme-tester execution |
|
26
|
|
|
*/ |
|
27
|
|
|
private $returnValue = 0; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var array Parsed json formatted output from the last readme-tester execution |
|
31
|
|
|
*/ |
|
32
|
|
|
private $output; |
|
33
|
|
|
|
|
34
|
|
|
public function __construct() |
|
35
|
|
|
{ |
|
36
|
|
|
$this->sourceDir = sys_get_temp_dir() . '/readmetester-behat-' . rand() . '/'; |
|
37
|
|
|
mkdir($this->sourceDir); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function __destruct() |
|
41
|
|
|
{ |
|
42
|
|
|
exec("rm -rf {$this->sourceDir}"); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @Given a markdown file: |
|
47
|
|
|
*/ |
|
48
|
|
|
public function aMarkdownFile(PyStringNode $string) |
|
49
|
|
|
{ |
|
50
|
|
|
file_put_contents($this->sourceDir . rand() . '.md', (string)$string); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @Given a source file :filename: |
|
55
|
|
|
*/ |
|
56
|
|
|
public function aSourceFile($filename, PyStringNode $string) |
|
57
|
|
|
{ |
|
58
|
|
|
file_put_contents($this->sourceDir . $filename, (string)$string); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @Given the command line argument :argument |
|
64
|
|
|
*/ |
|
65
|
|
|
public function theCommandLineArgument($argument) |
|
66
|
|
|
{ |
|
67
|
|
|
$this->args[] = $argument; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @When I run readme tester |
|
73
|
|
|
*/ |
|
74
|
|
|
public function iRunReadmeTester() |
|
75
|
|
|
{ |
|
76
|
|
|
$command = realpath('bin/readme-tester') . " test {$this->sourceDir} --format=json " . implode(' ', $this->args); |
|
77
|
|
|
$cwd = getcwd(); |
|
78
|
|
|
chdir($this->sourceDir); |
|
79
|
|
|
exec($command, $output, $this->returnValue); |
|
80
|
|
|
$this->output = json_decode(implode($output), true); |
|
81
|
|
|
chdir($cwd); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @Then :number files are found |
|
86
|
|
|
*/ |
|
87
|
|
|
public function filesAreFound(int $number) |
|
88
|
|
|
{ |
|
89
|
|
|
if ($this->output['counts']['files'] != $number) { |
|
90
|
|
|
throw new \Exception("{$this->output['counts']['files']} files found, expected $number"); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @Then :number examples are evaluated |
|
96
|
|
|
*/ |
|
97
|
|
|
public function examplesAreEvaluated(int $number) |
|
98
|
|
|
{ |
|
99
|
|
|
if ($this->output['counts']['examples'] != $number) { |
|
100
|
|
|
throw new \Exception("{$this->output['counts']['examples']} examples evaluated, expected $number"); |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @Then :number examples are ignored |
|
106
|
|
|
*/ |
|
107
|
|
|
public function examplesAreInored(int $number) |
|
108
|
|
|
{ |
|
109
|
|
|
if ($this->output['counts']['ignored'] != $number) { |
|
110
|
|
|
throw new \Exception("{$this->output['counts']['ignored']} examples ignored, expected $number"); |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @Then :number expectations are found |
|
116
|
|
|
*/ |
|
117
|
|
|
public function expectationsAreFound(int $number) |
|
118
|
|
|
{ |
|
119
|
|
|
if ($this->output['counts']['assertions'] != $number) { |
|
120
|
|
|
throw new \Exception("{$this->output['counts']['assertions']} assertions found, expected $number"); |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @Then :number failures are found |
|
126
|
|
|
*/ |
|
127
|
|
|
public function failuresAreFound($number) |
|
128
|
|
|
{ |
|
129
|
|
|
if ($this->output['counts']['failures'] != $number) { |
|
130
|
|
|
throw new \Exception("{$this->output['counts']['failures']} failures found, expected $number"); |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* @Then the exit code is :code |
|
136
|
|
|
*/ |
|
137
|
|
|
public function theExitCodeIs(int $code) |
|
138
|
|
|
{ |
|
139
|
|
|
if ($this->returnValue !== $code) { |
|
140
|
|
|
throw new \Exception("Readme tester exited with {$this->returnValue}, expected $code"); |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths