~jacekn/wordpress/wp-plugin-swift-storage-v2

« back to all changes in this revision

Viewing changes to vendor/phpunit/phpunit/src/Extensions/GroupTestSuite.php

  • Committer: Jacek Nykis
  • Date: 2015-02-11 15:35:31 UTC
  • Revision ID: jacek.nykis@canonical.com-20150211153531-hmy6zi0ov2qfkl0b
Initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/*
 
3
 * This file is part of PHPUnit.
 
4
 *
 
5
 * (c) Sebastian Bergmann <sebastian@phpunit.de>
 
6
 *
 
7
 * For the full copyright and license information, please view the LICENSE
 
8
 * file that was distributed with this source code.
 
9
 */
 
10
 
 
11
/**
 
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 .
 
18
 *
 
19
 * <code>
 
20
 * $suite = new PHPUnit_Extensions_GroupTestSuite($A, array('C', 'D'));
 
21
 * </code>
 
22
 *
 
23
 * @package    PHPUnit
 
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
 
30
 */
 
31
class PHPUnit_Extensions_GroupTestSuite extends PHPUnit_Framework_TestSuite
 
32
{
 
33
    public function __construct(PHPUnit_Framework_TestSuite $suite, array $groups)
 
34
    {
 
35
        $groupSuites = array();
 
36
        $name        = $suite->getName();
 
37
 
 
38
        foreach ($groups as $group) {
 
39
            $groupSuites[$group] = new PHPUnit_Framework_TestSuite($name . ' - ' . $group);
 
40
            $this->addTest($groupSuites[$group]);
 
41
        }
 
42
 
 
43
        $tests = new RecursiveIteratorIterator(
 
44
            new PHPUnit_Util_TestSuiteIterator($suite),
 
45
            RecursiveIteratorIterator::LEAVES_ONLY
 
46
        );
 
47
 
 
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)
 
52
                );
 
53
 
 
54
                foreach ($groups as $group) {
 
55
                    foreach ($testGroups as $testGroup) {
 
56
                        if ($group == $testGroup) {
 
57
                            $groupSuites[$group]->addTest($test);
 
58
                        }
 
59
                    }
 
60
                }
 
61
            }
 
62
        }
 
63
    }
 
64
}