Repository navigation
Expand file tree
/
Copy pathSuiteManagerTest.php
More file actions
137 lines (119 loc) · 4.88 KB
/
Copy pathSuiteManagerTest.php
File metadata and controls
137 lines (119 loc) · 4.88 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
declare(strict_types=1);
if (!defined('PHPUNIT_TESTSUITE')) {
define('PHPUNIT_TESTSUITE', true);
}
/**
* @group core
* Class SuiteManagerTest
*/
class SuiteManagerTest extends \Codeception\PHPUnit\TestCase
{
/**
* @var \Codeception\SuiteManager
*/
protected \Codeception\SuiteManager $suiteman;
/**
* @var \Symfony\Component\EventDispatcher\EventDispatcher
*/
protected \Symfony\Component\EventDispatcher\EventDispatcher $dispatcher;
/**
* @var \Codeception\PHPUnit\Runner
*/
protected \Codeception\PHPUnit\Runner $runner;
public function _setUp()
{
$this->dispatcher = new Symfony\Component\EventDispatcher\EventDispatcher;
$settings = \Codeception\Configuration::$defaultSuiteSettings;
$settings['actor'] = 'CodeGuy';
$this->suiteman = new \Codeception\SuiteManager($this->dispatcher, 'suite', $settings);
$printer = \Codeception\Stub::makeEmpty(\PHPUnit\TextUI\ResultPrinter::class);
$this->runner = new \Codeception\PHPUnit\Runner;
$this->runner->setPrinter($printer);
}
/**
* @group core
*/
public function testRun()
{
$events = [];
$eventListener = function ($event, $eventName) use (&$events) {
$events[] = $eventName;
};
$this->dispatcher->addListener('suite.before', $eventListener);
$this->dispatcher->addListener('suite.after', $eventListener);
$this->suiteman->run(
$this->runner,
new \PHPUnit\Framework\TestResult,
['colors' => false, 'steps' => true, 'debug' => false, 'report_useless_tests' => false, 'disallow_test_output' => false]
);
$this->assertSame($events, ['suite.before', 'suite.after']);
}
/**
* @group core
*/
public function testFewTests()
{
if (version_compare(phpversion(), '8.1', '>=') && PHP_OS_FAMILY === 'Windows') {
$this->markTestSkipped("Temporary disabled for windows php version 8.1 and greater.");
}
$file = \Codeception\Configuration::dataDir().'SimpleCest.php';
$this->suiteman->loadTests($file);
$this->assertSame(2, $this->suiteman->getSuite()->count());
$file = \Codeception\Configuration::dataDir().'SimpleWithNoClassCest.php';
$this->suiteman->loadTests($file);
$this->assertSame(3, $this->suiteman->getSuite()->count());
}
/**
* When running multiple environments, getClassesFromFile() method in SuiteManager is called once for each env.
* See \Codeception\Codecept::runSuite() - for each env new SuiteManager is created and tests loaded.
* Make sure that calling getClassesFromFile() multiple times will always return the same classes.
*
* @group core
*/
public function testAddCestWithEnv()
{
if (version_compare(phpversion(), '8.1', '>=') && PHP_OS_FAMILY === 'Windows') {
$this->markTestSkipped("Temporary disabled for windows php version 8.1 and greater.");
}
$file = \Codeception\Configuration::dataDir().'SimpleNamespacedTest.php';
$this->suiteman->loadTests($file);
$this->assertSame(3, $this->suiteman->getSuite()->count());
$newSuiteMan = new \Codeception\SuiteManager(
$this->dispatcher,
'suite',
\Codeception\Configuration::$defaultSuiteSettings
);
$newSuiteMan->loadTests($file);
$this->assertSame(3, $newSuiteMan->getSuite()->count());
}
public function testDependencyResolution()
{
$this->suiteman->loadTests(codecept_data_dir().'SimpleWithDependencyInjectionCest.php');
$this->assertSame(3, $this->suiteman->getSuite()->count());
}
public function testGroupEventsAreFired()
{
$events = [];
$eventListener = function ($event, $eventName) use (&$events) {
$events[] = $eventName;
};
$this->dispatcher->addListener('test.before', $eventListener);
$this->dispatcher->addListener('test.before.admin', $eventListener);
$this->dispatcher->addListener('test.after', $eventListener);
$this->dispatcher->addListener('test.after.admin', $eventListener);
$this->suiteman->loadTests(codecept_data_dir().'SimpleAdminGroupCest.php');
$result = new \PHPUnit\Framework\TestResult;
$listener = new \Codeception\PHPUnit\Listener($this->dispatcher);
$result->addListener($listener);
$this->suiteman->run(
$this->runner,
$result,
['silent' => true, 'colors' => false, 'steps' => true, 'debug' => false, 'report_useless_tests' => false, 'disallow_test_output' => false]
);
$this->assertContains('test.before', $events);
$this->assertContains('test.before.admin', $events);
$this->assertContains('test.after', $events);
$this->assertContains('test.after.admin', $events);
}
}