3
* This file is part of PHPUnit.
5
* (c) Sebastian Bergmann <sebastian@phpunit.de>
7
* For the full copyright and license information, please view the LICENSE
8
* file that was distributed with this source code.
12
* We have a TestSuite object A.
13
* In TestSuite object A we have Tests tagged with @group.
14
* We want a TestSuite object B that contains TestSuite objects C, D, ...
15
* for the Tests tagged with @group C, @group D, ...
16
* Running the Tests from TestSuite object B results in Tests tagged with both
17
* @group C and @group D in TestSuite object A to be run twice .
20
* $suite = new PHPUnit_Extensions_GroupTestSuite($A, array('C', 'D'));
24
* @subpackage Extensions
25
* @author Sebastian Bergmann <sebastian@phpunit.de>
26
* @copyright Sebastian Bergmann <sebastian@phpunit.de>
27
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
28
* @link http://www.phpunit.de/
29
* @since Class available since Release 3.3.0
31
class PHPUnit_Extensions_GroupTestSuite extends PHPUnit_Framework_TestSuite
33
public function __construct(PHPUnit_Framework_TestSuite $suite, array $groups)
35
$groupSuites = array();
36
$name = $suite->getName();
38
foreach ($groups as $group) {
39
$groupSuites[$group] = new PHPUnit_Framework_TestSuite($name . ' - ' . $group);
40
$this->addTest($groupSuites[$group]);
43
$tests = new RecursiveIteratorIterator(
44
new PHPUnit_Util_TestSuiteIterator($suite),
45
RecursiveIteratorIterator::LEAVES_ONLY
48
foreach ($tests as $test) {
49
if ($test instanceof PHPUnit_Framework_TestCase) {
50
$testGroups = PHPUnit_Util_Test::getGroups(
51
get_class($test), $test->getName(false)
54
foreach ($groups as $group) {
55
foreach ($testGroups as $testGroup) {
56
if ($group == $testGroup) {
57
$groupSuites[$group]->addTest($test);