~tcuthbert/wordpress/openstack-objectstorage

« back to all changes in this revision

Viewing changes to vendor/phpunit/phpunit/src/Runner/Filter/Test.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
 * @package    PHPUnit
 
13
 * @subpackage Runner
 
14
 * @author     Sebastian Bergmann <sebastian@phpunit.de>
 
15
 * @copyright  Sebastian Bergmann <sebastian@phpunit.de>
 
16
 * @license    http://www.opensource.org/licenses/BSD-3-Clause  The BSD 3-Clause License
 
17
 * @link       http://www.phpunit.de/
 
18
 * @since      Class available since Release 4.0.0
 
19
 */
 
20
class PHPUnit_Runner_Filter_Test extends RecursiveFilterIterator
 
21
{
 
22
    /**
 
23
     * @var string
 
24
     */
 
25
    protected $filter = null;
 
26
 
 
27
    /**
 
28
     * @var integer
 
29
     */
 
30
    protected $filterMin;
 
31
    /**
 
32
     * @var integer
 
33
     */
 
34
    protected $filterMax;
 
35
 
 
36
    /**
 
37
     * @param RecursiveIterator $iterator
 
38
     * @param string            $filter
 
39
     */
 
40
    public function __construct(RecursiveIterator $iterator, $filter)
 
41
    {
 
42
        parent::__construct($iterator);
 
43
        $this->setFilter($filter);
 
44
    }
 
45
 
 
46
    /**
 
47
     * @param string $filter
 
48
     */
 
49
    protected function setFilter($filter)
 
50
    {
 
51
        if (PHPUnit_Util_Regex::pregMatchSafe($filter, '') === false) {
 
52
            // Handles:
 
53
            //  * testAssertEqualsSucceeds#4
 
54
            //  * testAssertEqualsSucceeds#4-8
 
55
            if (preg_match('/^(.*?)#(\d+)(?:-(\d+))?$/', $filter, $matches)) {
 
56
                if (isset($matches[3]) && $matches[2] < $matches[3]) {
 
57
                    $filter = sprintf(
 
58
                        '%s.*with data set #(\d+)$',
 
59
                        $matches[1]
 
60
                    );
 
61
 
 
62
                    $this->filterMin = $matches[2];
 
63
                    $this->filterMax = $matches[3];
 
64
                } else {
 
65
                    $filter = sprintf(
 
66
                        '%s.*with data set #%s$',
 
67
                        $matches[1],
 
68
                        $matches[2]
 
69
                    );
 
70
                }
 
71
            } // Handles:
 
72
            //  * testDetermineJsonError@JSON_ERROR_NONE
 
73
            //  * testDetermineJsonError@JSON.*
 
74
            elseif (preg_match('/^(.*?)@(.+)$/', $filter, $matches)) {
 
75
                $filter = sprintf(
 
76
                    '%s.*with data set "%s"$',
 
77
                    $matches[1],
 
78
                    $matches[2]
 
79
                );
 
80
            }
 
81
 
 
82
            // Escape delimiters in regular expression. Do NOT use preg_quote,
 
83
            // to keep magic characters.
 
84
            $filter = sprintf('/%s/', str_replace(
 
85
                '/', '\\/', $filter
 
86
            ));
 
87
        }
 
88
 
 
89
        $this->filter = $filter;
 
90
    }
 
91
 
 
92
    /**
 
93
     * @return boolean
 
94
     */
 
95
    public function accept()
 
96
    {
 
97
        $test = $this->getInnerIterator()->current();
 
98
 
 
99
        if ($test instanceof PHPUnit_Framework_TestSuite) {
 
100
            return true;
 
101
        }
 
102
 
 
103
        $tmp = PHPUnit_Util_Test::describe($test, false);
 
104
 
 
105
        if ($tmp[0] != '') {
 
106
            $name = join('::', $tmp);
 
107
        } else {
 
108
            $name = $tmp[1];
 
109
        }
 
110
 
 
111
        $accepted = preg_match($this->filter, $name, $matches);
 
112
 
 
113
        if ($accepted && isset($this->filterMax)) {
 
114
            $set = end($matches);
 
115
            $accepted = $set >= $this->filterMin && $set <= $this->filterMax;
 
116
        }
 
117
 
 
118
        return $accepted;
 
119
    }
 
120
}