1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php
use Codeception\Lib\Parser;
/**
* @group core
* Class ParserTest
*/
class ParserTest extends \Codeception\Test\Unit
{
/**
* @var Parser
*/
protected $parser;
/**
* @var \Codeception\Scenario
*/
protected $scenario;
protected $testMetadata;
protected function _before()
{
$cept = new \Codeception\Test\Cept('demo', 'DemoCept.php');
$this->testMetadata = $cept->getMetadata();
$this->scenario = new Codeception\Scenario($cept);
$this->parser = new Parser($this->scenario, $this->testMetadata);
}
public function testParsingFeature()
{
$code = "<?php\n \\\$I->wantTo('run this test'); ";
$this->parser->parseFeature($code);
$this->assertEquals('run this test', $this->scenario->getFeature());
$code = "<?php\n \\\$I->wantToTest('this run'); ";
$this->parser->parseFeature($code);
$this->assertEquals('test this run', $this->scenario->getFeature());
}
public function testParsingWithWhitespace()
{
$code = "<?php\n \\\$I->wantTo( 'run this test' ); ";
$this->parser->parseFeature($code);
$this->assertEquals('run this test', $this->scenario->getFeature());
}
public function testScenarioOptions()
{
$code = <<<EOF
<?php
// @group davert
// @env windows
\$I = new AcceptanceTeser(\$scenario);
EOF;
$this->parser->parseScenarioOptions($code);
$this->assertContains('davert', $this->testMetadata->getGroups());
$this->assertContains('windows', $this->testMetadata->getEnv());
}
public function testCommentedInBlockScenarioOptions()
{
$code = <<<EOF
<?php
/**
* @skip
*/
EOF;
$this->parser->parseScenarioOptions($code);
$this->assertTrue($this->testMetadata->isBlocked());
}
public function testFeatureCommented()
{
$code = "<?php\n //\\\$I->wantTo('run this test'); ";
$this->parser->parseFeature($code);
$this->assertNull($this->scenario->getFeature());
$code = "<?php\n /*\n \\\$I->wantTo('run this test'); \n */";
$this->parser->parseFeature($code);
$this->assertNull($this->scenario->getFeature());
}
public function testScenarioSkipOptionsHandled()
{
$code = "<?php\n // @skip pass along";
$this->parser->parseScenarioOptions($code);
$this->assertTrue($this->testMetadata->isBlocked());
}
public function testScenarioIncompleteOptionHandled()
{
$code = "<?php\n // @incomplete not ready yet";
$this->parser->parseScenarioOptions($code);
$this->assertTrue($this->testMetadata->isBlocked());
}
public function testSteps()
{
$code = file_get_contents(\Codeception\Configuration::projectDir().'tests/cli/UnitCept.php');
$this->assertContains('$I->seeInThisFile', $code);
$this->parser->parseSteps($code);
$text = $this->scenario->getText();
$this->assertContains("I see in this file", $text);
}
public function testStepsWithFriends()
{
$code = file_get_contents(\Codeception\Configuration::projectDir().'tests/web/FriendsCept.php');
$this->assertContains('$I->haveFriend', $code);
$this->parser->parseSteps($code);
$text = $this->scenario->getText();
$this->assertContains("jon does", $text);
$this->assertContains("I have friend", $text);
$this->assertContains("back to me", $text);
}
public function testParseFile()
{
$classes = Parser::getClassesFromFile(codecept_data_dir('SimpleTest.php'));
$this->assertEquals(['SampleTest'], $classes);
}
public function testParseFileWithClass()
{
if (version_compare(PHP_VERSION, '5.5.0', '<')) {
$this->markTestSkipped('only for php 5.5');
}
$classes = Parser::getClassesFromFile(codecept_data_dir('php55Test'));
$this->assertEquals(['php55Test'], $classes);
}
public function testParseFileWithAnonymousClass()
{
if (version_compare(PHP_VERSION, '7.0.0', '<')) {
$this->markTestSkipped('only for php 7');
}
$classes = Parser::getClassesFromFile(codecept_data_dir('php70Test'));
$this->assertEquals(['php70Test'], $classes);
}
/*
* https://github.com/Codeception/Codeception/issues/1779
*/
public function testParseFileWhichUnsetsFileVariable()
{
$classes = Parser::getClassesFromFile(codecept_data_dir('unsetFile.php'));
$this->assertEquals([], $classes);
}
/**
* @group core
* @throws \Codeception\Exception\TestParseException
*/
public function testModernValidation()
{
if (PHP_MAJOR_VERSION < 7) {
$this->markTestSkipped();
}
$this->setExpectedException('Codeception\Exception\TestParseException');
Parser::load(codecept_data_dir('Invalid.php'));
}
/**
* @group core
*/
public function testClassesFromFile()
{
$classes = Parser::getClassesFromFile(codecept_data_dir('DummyClass.php'));
$this->assertContains('DummyClass', $classes);
$classes = Parser::getClassesFromFile(codecept_data_dir('SimpleWithDependencyInjectionCest.php'));
$this->assertContains('simpleDI\\LoadedTestWithDependencyInjectionCest', $classes);
$this->assertContains('simpleDI\\AnotherCest', $classes);
}
}