Repository navigation
Expand file tree
/
Copy pathTestLoaderTest.php
More file actions
118 lines (99 loc) · 3.41 KB
/
Copy pathTestLoaderTest.php
File metadata and controls
118 lines (99 loc) · 3.41 KB
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
<?php
declare(strict_types=1);
/**
* Class TestLoaderTest
* @group load
*/
class TestLoaderTest extends \Codeception\PHPUnit\TestCase
{
/**
* @var \Codeception\Test\Loader
*/
protected \Codeception\Test\Loader $testLoader;
protected function _setUp()
{
$this->testLoader = new \Codeception\Test\Loader(['path' => \Codeception\Configuration::dataDir()]);
}
/**
* @group core
*/
public function testAddCept()
{
$this->testLoader->loadTest('SimpleCept.php');
$this->assertCount(1, $this->testLoader->getTests());
}
public function testAddTest()
{
$this->testLoader->loadTest('SimpleTest.php');
$this->assertCount(1, $this->testLoader->getTests());
}
public function testAddCeptAbsolutePath()
{
$this->testLoader->loadTest(codecept_data_dir('SimpleCept.php'));
$this->assertCount(1, $this->testLoader->getTests());
}
public function testAddCeptWithoutExtension()
{
$this->testLoader->loadTest('SimpleCept');
$this->assertCount(1, $this->testLoader->getTests());
}
/**
* @group core
*/
public function testLoadFileWithFewCases()
{
$this->testLoader->loadTest('SimpleNamespacedTest.php');
$this->assertCount(3, $this->testLoader->getTests());
}
/**
* @group core
*/
public function testLoadAllTests()
{
// to autoload dependencies
Codeception\Util\Autoload::addNamespace(
'Math',
codecept_data_dir().'claypit/tests/_support/Math'
);
Codeception\Util\Autoload::addNamespace(\Codeception\Module::class, codecept_data_dir().'claypit/tests/_support');
$this->testLoader = new \Codeception\Test\Loader(['path' => codecept_data_dir().'claypit/tests']);
$this->testLoader->loadTests();
$testNames = $this->getTestNames($this->testLoader->getTests());
$this->assertContainsTestName('AnotherCept', $testNames);
$this->assertContainsTestName('MageGuildCest:darkPower', $testNames);
$this->assertContainsTestName('FailingTest:testMe', $testNames);
$this->assertContainsTestName('MathCest:testAddition', $testNames);
$this->assertContainsTestName('MathTest:testAll', $testNames);
}
/**
* @return string[]
*/
protected function getTestNames($tests): array
{
$testNames = [];
foreach ($tests as $test) {
$testNames[] = \Codeception\Test\Descriptor::getTestSignature($test);
}
return $testNames;
}
protected function assertContainsTestName($name, iterable $testNames)
{
$this->assertContains($name, $testNames, "{$name} not found in tests");
}
public function testDataProviderReturningArray()
{
$this->testLoader->loadTest('SimpleWithDataProviderArrayCest.php');
$tests = $this->testLoader->getTests();
/** @var \PHPUnit\Framework\DataProviderTestSuite $firstTest */
$firstTest = $tests[0];
$this->assertSame(5, $firstTest->count());
}
public function testDataProviderReturningGenerator()
{
$this->testLoader->loadTest('SimpleWithDataProviderYieldGeneratorCest.php');
$tests = $this->testLoader->getTests();
/** @var \PHPUnit\Framework\DataProviderTestSuite $firstTest */
$firstTest = $tests[0];
$this->assertSame(5, $firstTest->count());
}
}