Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ee495f8

Browse files
committed
merged branch kriswallsmith/class-loader/idempotent (PR #7245)
This PR was merged into the 2.1 branch. Commits ------- 27cc0df Merge pull request #1 from merk/class-loader/idempotent 95af84c Fixed test to use Reflection bb08247 [ClassLoader] tweaked test 73bead7 [ClassLoader] made DebugClassLoader idempotent Discussion ---------- [ClassLoader] made DebugClassLoader idempotent The DebugClassLoader will wrap itself if `enable()` is called multiple time, such as when running functional tests. Please merge to 2.2 and master ASAP. | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | ~ | License | MIT | Doc PR | ~ --------------------------------------------------------------------------- by kriswallsmith at 2013-03-07T16:38:55Z ping @fabpot: this will speed up lots of functional tests :) --------------------------------------------------------------------------- by kriswallsmith at 2013-03-08T04:51:51Z @fabpot fixed by @merk
2 parents 7241be9 + 27cc0df commit ee495f8

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

src/Symfony/Component/ClassLoader/DebugClassLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public static function enable()
5353
}
5454

5555
foreach ($functions as $function) {
56-
if (is_array($function) && method_exists($function[0], 'findFile')) {
56+
if (is_array($function) && !$function[0] instanceof self && method_exists($function[0], 'findFile')) {
5757
$function = array(new static($function[0]), 'loadClass');
5858
}
5959

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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

Comments
 (0)