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
<?php
namespace Codeception\Lib;
use Codeception\Util\Stub;
class GroupManagerTest extends \Codeception\Test\Unit
{
/**
* @var \Codeception\Lib\GroupManager
*/
protected $manager;
// tests
public function testGroupsFromArray()
{
$this->manager = new GroupManager(['important' => ['UserTest.php:testName', 'PostTest.php']]);
$test1 = $this->makeTestCase('UserTest.php', 'testName');
$test2 = $this->makeTestCase('PostTest.php');
$test3 = $this->makeTestCase('UserTest.php', 'testNot');
$this->assertContains('important', $this->manager->groupsForTest($test1));
$this->assertContains('important', $this->manager->groupsForTest($test2));
$this->assertNotContains('important', $this->manager->groupsForTest($test3));
}
public function testGroupsFromFile()
{
$this->manager = new GroupManager(['important' => 'tests/data/test_groups']);
$test1 = $this->makeTestCase('tests/UserTest.php', 'testName');
$test2 = $this->makeTestCase('tests/PostTest.php');
$test3 = $this->makeTestCase('tests/UserTest.php', 'testNot');
$this->assertContains('important', $this->manager->groupsForTest($test1));
$this->assertContains('important', $this->manager->groupsForTest($test2));
$this->assertNotContains('important', $this->manager->groupsForTest($test3));
}
public function testGroupsFromFileOnWindows()
{
$this->manager = new GroupManager(['important' => 'tests/data/group_3']);
$test = $this->makeTestCase('tests/WinTest.php');
$this->assertContains('important', $this->manager->groupsForTest($test));
}
public function testGroupsFromArrayOnWindows()
{
$this->manager = new GroupManager(['important' => ['tests\WinTest.php']]);
$test = $this->makeTestCase('tests/WinTest.php');
$this->assertContains('important', $this->manager->groupsForTest($test));
}
public function testGroupsByPattern()
{
$this->manager = new GroupManager(['group_*' => 'tests/data/group_*']);
$test1 = $this->makeTestCase('tests/UserTest.php');
$test2 = $this->makeTestCase('tests/PostTest.php');
$this->assertContains('group_1', $this->manager->groupsForTest($test1));
$this->assertContains('group_2', $this->manager->groupsForTest($test2));
}
public function testGroupsByDifferentPattern()
{
$this->manager = new GroupManager(['g_*' => 'tests/data/group_*']);
$test1 = $this->makeTestCase('tests/UserTest.php');
$test2 = $this->makeTestCase('tests/PostTest.php');
$this->assertContains('g_1', $this->manager->groupsForTest($test1));
$this->assertContains('g_2', $this->manager->groupsForTest($test2));
}
public function testGroupsFileHandlesWhitespace()
{
$this->manager = new GroupManager(['whitespace_group_test' => 'tests/data/whitespace_group_test']);
$goodTest = $this->makeTestCase('tests/WhitespaceTest.php');
$badTest = $this->makeTestCase('');
$this->assertContains('whitespace_group_test', $this->manager->groupsForTest($goodTest));
$this->assertEmpty($this->manager->groupsForTest($badTest));
}
protected function makeTestCase($file, $name = '')
{
return Stub::make(
'\Codeception\Lib\DescriptiveTestCase',
[
'getReportFields' => ['file' => codecept_root_dir() . $file],
'getName' => $name
]
);
}
}
class DescriptiveTestCase extends \Codeception\Test\Unit
{
}