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
18 * @group C and @group D in TestSuite object A to be run twice .
21 * $suite = new PHPUnit_Extensions_GroupTestSuite($A, array('C', 'D'));
24 * @since Class available since Release 3.3.0
26 class PHPUnit_Extensions_GroupTestSuite extends PHPUnit_Framework_TestSuite
28 public function __construct(PHPUnit_Framework_TestSuite $suite, array $groups)
30 $groupSuites = array();
31 $name = $suite->getName();
33 foreach ($groups as $group) {
34 $groupSuites[$group] = new PHPUnit_Framework_TestSuite($name . ' - ' . $group);
35 $this->addTest($groupSuites[$group]);
38 $tests = new RecursiveIteratorIterator(
39 new PHPUnit_Util_TestSuiteIterator($suite),
40 RecursiveIteratorIterator::LEAVES_ONLY
43 foreach ($tests as $test) {
44 if ($test instanceof PHPUnit_Framework_TestCase) {
45 $testGroups = PHPUnit_Util_Test::getGroups(
50 foreach ($groups as $group) {
51 foreach ($testGroups as $testGroup) {
52 if ($group == $testGroup) {
53 $groupSuites[$group]->addTest($test);