~tcuthbert/wordpress/openstack-objectstorage

« back to all changes in this revision

Viewing changes to vendor/phpunit/phpunit/src/Util/Blacklist.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
 * Utility class for blacklisting PHPUnit's own source code files.
 
13
 *
 
14
 * @package    PHPUnit
 
15
 * @subpackage Util
 
16
 * @author     Sebastian Bergmann <sebastian@phpunit.de>
 
17
 * @copyright  Sebastian Bergmann <sebastian@phpunit.de>
 
18
 * @license    http://www.opensource.org/licenses/BSD-3-Clause  The BSD 3-Clause License
 
19
 * @link       http://www.phpunit.de/
 
20
 * @since      Class available since Release 4.0.0
 
21
 */
 
22
class PHPUnit_Util_Blacklist
 
23
{
 
24
    /**
 
25
     * @var array
 
26
     */
 
27
    public static $blacklistedClassNames = array(
 
28
        'File_Iterator' => 1,
 
29
        'PHP_CodeCoverage' => 1,
 
30
        'PHP_Invoker' => 1,
 
31
        'PHP_Timer' => 1,
 
32
        'PHP_Token' => 1,
 
33
        'PHPUnit_Framework_TestCase' => 2,
 
34
        'PHPUnit_Extensions_Database_TestCase' => 2,
 
35
        'PHPUnit_Framework_MockObject_Generator' => 2,
 
36
        'PHPUnit_Extensions_SeleniumTestCase' => 2,
 
37
        'PHPUnit_Extensions_Story_TestCase' => 2,
 
38
        'Text_Template' => 1,
 
39
        'Symfony\Component\Yaml\Yaml' => 1,
 
40
        'SebastianBergmann\Diff\Diff' => 1,
 
41
        'SebastianBergmann\Environment\Runtime' => 1,
 
42
        'SebastianBergmann\Comparator\Comparator' => 1,
 
43
        'SebastianBergmann\Exporter\Exporter' => 1,
 
44
        'SebastianBergmann\RecursionContext\Context' => 1,
 
45
        'SebastianBergmann\Version' => 1,
 
46
        'Composer\Autoload\ClassLoader' => 1,
 
47
        'Doctrine\Instantiator\Instantiator' => 1
 
48
    );
 
49
 
 
50
    /**
 
51
     * @var array
 
52
     */
 
53
    private static $directories;
 
54
 
 
55
    /**
 
56
     * @return array
 
57
     * @since  Method available since Release 4.1.0
 
58
     */
 
59
    public function getBlacklistedDirectories()
 
60
    {
 
61
        $this->initialize();
 
62
 
 
63
        return self::$directories;
 
64
    }
 
65
 
 
66
    /**
 
67
     * @param  string  $file
 
68
     * @return boolean
 
69
     */
 
70
    public function isBlacklisted($file)
 
71
    {
 
72
        if (defined('PHPUNIT_TESTSUITE')) {
 
73
            return false;
 
74
        }
 
75
 
 
76
        $this->initialize();
 
77
 
 
78
        foreach (self::$directories as $directory) {
 
79
            if (strpos($file, $directory) === 0) {
 
80
                return true;
 
81
            }
 
82
        }
 
83
 
 
84
        return false;
 
85
    }
 
86
 
 
87
    private function initialize()
 
88
    {
 
89
        if (self::$directories === null) {
 
90
            self::$directories = array();
 
91
 
 
92
            foreach (self::$blacklistedClassNames as $className => $parent) {
 
93
                if (!class_exists($className)) {
 
94
                    continue;
 
95
                }
 
96
 
 
97
                $reflector = new ReflectionClass($className);
 
98
                $directory = $reflector->getFileName();
 
99
 
 
100
                for ($i = 0; $i < $parent; $i++) {
 
101
                    $directory = dirname($directory);
 
102
                }
 
103
 
 
104
                self::$directories[] = $directory;
 
105
            }
 
106
 
 
107
            // Hide process isolation workaround on Windows.
 
108
            // @see PHPUnit_Util_PHP::factory()
 
109
            // @see PHPUnit_Util_PHP_Windows::process()
 
110
            if (DIRECTORY_SEPARATOR === '\\') {
 
111
                // tempnam() prefix is limited to first 3 chars.
 
112
                // @see http://php.net/manual/en/function.tempnam.php
 
113
                self::$directories[] = sys_get_temp_dir() . '\\PHP';
 
114
            }
 
115
        }
 
116
    }
 
117
}