|
1
|
|
|
<?php |
|
2
|
|
|
use AspectMock\Test as test; |
|
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
class CodeceptionTest extends \Codeception\TestCase\Test |
|
5
|
|
|
{ |
|
6
|
|
|
protected $container; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @var \AspectMock\Proxy\ClassProxy |
|
10
|
|
|
*/ |
|
11
|
|
|
protected $codecept; |
|
12
|
|
|
|
|
13
|
|
|
protected function _before() |
|
14
|
|
|
{ |
|
15
|
|
|
$this->codecept = test::double('Robo\Task\Testing\Codecept', [ |
|
16
|
|
|
'executeCommand' => null, |
|
17
|
|
|
'output' => new \Symfony\Component\Console\Output\NullOutput() |
|
18
|
|
|
]); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
// tests |
|
22
|
|
|
public function testCodeceptionCommand() |
|
23
|
|
|
{ |
|
24
|
|
|
$this->assertEquals( |
|
25
|
|
|
'codecept.phar run', |
|
26
|
|
|
trim((new \Robo\Task\Testing\Codecept('codecept.phar'))->getCommand())); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function testCodeceptionRun() |
|
30
|
|
|
{ |
|
31
|
|
|
$task = new \Robo\Task\Testing\Codecept('codecept.phar'); |
|
32
|
|
|
$task->setLogger(new \Psr\Log\NullLogger()); |
|
33
|
|
|
|
|
34
|
|
|
$task->run(); |
|
35
|
|
|
$this->codecept->verifyInvoked('executeCommand'); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testCodeceptOptions() |
|
39
|
|
|
{ |
|
40
|
|
|
$this->assertEquals( |
|
41
|
|
|
'codecept run unit Codeception/Command --group core --env process1 --coverage', |
|
42
|
|
|
(new \Robo\Task\Testing\Codecept('codecept')) |
|
43
|
|
|
->suite('unit') |
|
44
|
|
|
->test('Codeception/Command') |
|
45
|
|
|
->group('core') |
|
46
|
|
|
->env('process1') |
|
47
|
|
|
->coverage() |
|
48
|
|
|
->getCommand() |
|
49
|
|
|
); |
|
50
|
|
|
|
|
51
|
|
|
$failGroupName = 'failed1'; |
|
52
|
|
|
$this->assertRegExp( |
|
53
|
|
|
"|^codecept run tests/unit/Codeception -c ~/Codeception --xml result\\.xml --html --no-rebuild --override ['\"]extensions: config: Codeception\\\\Extension\\\\RunFailed: fail-group: {$failGroupName}['\"]$|", |
|
54
|
|
|
(new \Robo\Task\Testing\Codecept('codecept')) |
|
55
|
|
|
->test('tests/unit/Codeception') |
|
56
|
|
|
->configFile('~/Codeception') |
|
57
|
|
|
->xml('result.xml') |
|
58
|
|
|
->html() |
|
59
|
|
|
->noRebuild() |
|
60
|
|
|
->failGroup($failGroupName) |
|
61
|
|
|
->getCommand() |
|
62
|
|
|
); |
|
63
|
|
|
|
|
64
|
|
|
$this->assertContains( |
|
65
|
|
|
' --debug', |
|
66
|
|
|
(new \Robo\Task\Testing\Codecept('codecept.phar'))->debug()->getCommand()); |
|
67
|
|
|
$this->assertContains( |
|
68
|
|
|
' --silent', |
|
69
|
|
|
(new \Robo\Task\Testing\Codecept('codecept.phar'))->silent()->getCommand()); |
|
70
|
|
|
$this->assertContains( |
|
71
|
|
|
' --skip-group g', |
|
72
|
|
|
(new \Robo\Task\Testing\Codecept('codecept.phar'))->excludeGroup('g')->getCommand()); |
|
73
|
|
|
$this->assertContains( |
|
74
|
|
|
'--tap', |
|
75
|
|
|
(new \Robo\Task\Testing\Codecept('codecept.phar'))->tap()->getCommand()); |
|
76
|
|
|
$this->assertContains( |
|
77
|
|
|
'--json', |
|
78
|
|
|
(new \Robo\Task\Testing\Codecept('codecept.phar'))->json()->getCommand()); |
|
79
|
|
|
$this->assertContains( |
|
80
|
|
|
'--no-rebuild', |
|
81
|
|
|
(new \Robo\Task\Testing\Codecept('codecept.phar'))->noRebuild()->getCommand()); |
|
82
|
|
|
$failGroupName = 'failed2'; |
|
83
|
|
|
$this->assertRegExp( |
|
84
|
|
|
"|--override ['\"]extensions: config: Codeception\\\\Extension\\\\RunFailed: fail-group: {$failGroupName}['\"]|", |
|
85
|
|
|
(new \Robo\Task\Testing\Codecept('codecept.phar'))->failGroup($failGroupName)->getCommand()); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
} |
|
89
|
|
|
|
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: