Fix bug in style changes for the Use cases on the live site.
[yaffs-website] / vendor / phpunit / phpunit / src / Util / Fileloader.php
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 methods to load PHP sourcefiles.
13  *
14  * @since Class available since Release 2.3.0
15  */
16 class PHPUnit_Util_Fileloader
17 {
18     /**
19      * Checks if a PHP sourcefile is readable.
20      * The sourcefile is loaded through the load() method.
21      *
22      * @param string $filename
23      *
24      * @return string
25      *
26      * @throws PHPUnit_Framework_Exception
27      */
28     public static function checkAndLoad($filename)
29     {
30         $includePathFilename = stream_resolve_include_path($filename);
31
32         if (!$includePathFilename || !is_readable($includePathFilename)) {
33             throw new PHPUnit_Framework_Exception(
34                 sprintf('Cannot open file "%s".' . "\n", $filename)
35             );
36         }
37
38         self::load($includePathFilename);
39
40         return $includePathFilename;
41     }
42
43     /**
44      * Loads a PHP sourcefile.
45      *
46      * @param string $filename
47      *
48      * @return mixed
49      *
50      * @since  Method available since Release 3.0.0
51      */
52     public static function load($filename)
53     {
54         $oldVariableNames = array_keys(get_defined_vars());
55
56         include_once $filename;
57
58         $newVariables     = get_defined_vars();
59         $newVariableNames = array_diff(
60             array_keys($newVariables),
61             $oldVariableNames
62         );
63
64         foreach ($newVariableNames as $variableName) {
65             if ($variableName != 'oldVariableNames') {
66                 $GLOBALS[$variableName] = $newVariables[$variableName];
67             }
68         }
69
70         return $filename;
71     }
72 }