|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[email protected]> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Component\ClassLoader\Tests; |
| 13 | + |
| 14 | +use Symfony\Component\ClassLoader\ClassLoader; |
| 15 | +use Symfony\Component\ClassLoader\DebugClassLoader; |
| 16 | + |
| 17 | +class DebugClassLoaderTest extends \PHPUnit_Framework_TestCase |
| 18 | +{ |
| 19 | + private $loader; |
| 20 | + |
| 21 | + protected function setUp() |
| 22 | + { |
| 23 | + $this->loader = new ClassLoader(); |
| 24 | + spl_autoload_register(array($this->loader, 'loadClass')); |
| 25 | + } |
| 26 | + |
| 27 | + protected function tearDown() |
| 28 | + { |
| 29 | + spl_autoload_unregister(array($this->loader, 'loadClass')); |
| 30 | + } |
| 31 | + |
| 32 | + public function testIdempotence() |
| 33 | + { |
| 34 | + DebugClassLoader::enable(); |
| 35 | + DebugClassLoader::enable(); |
| 36 | + |
| 37 | + $functions = spl_autoload_functions(); |
| 38 | + foreach ($functions as $function) { |
| 39 | + if (is_array($function) && $function[0] instanceof DebugClassLoader) { |
| 40 | + $reflClass = new \ReflectionClass($function[0]); |
| 41 | + $reflProp = $reflClass->getProperty('classFinder'); |
| 42 | + $reflProp->setAccessible(true); |
| 43 | + |
| 44 | + $this->assertNotInstanceOf('Symfony\Component\ClassLoader\DebugClassLoader', $reflProp->getValue($function[0])); |
| 45 | + return; |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + throw new \Exception('DebugClassLoader did not register'); |
| 50 | + } |
| 51 | +} |
0 commit comments