Skip to content

Commit

Permalink
merged branch kriswallsmith/class-loader/idempotent (PR #7245)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fabpot committed Mar 8, 2013
2 parents 7241be9 + 27cc0df commit ee495f8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Symfony/Component/ClassLoader/DebugClassLoader.php
Expand Up @@ -53,7 +53,7 @@ public static function enable()
}

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

Expand Down
51 changes: 51 additions & 0 deletions src/Symfony/Component/ClassLoader/Tests/DebugClassLoaderTest.php
@@ -0,0 +1,51 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\ClassLoader\Tests;

use Symfony\Component\ClassLoader\ClassLoader;
use Symfony\Component\ClassLoader\DebugClassLoader;

class DebugClassLoaderTest extends \PHPUnit_Framework_TestCase
{
private $loader;

protected function setUp()
{
$this->loader = new ClassLoader();
spl_autoload_register(array($this->loader, 'loadClass'));
}

protected function tearDown()
{
spl_autoload_unregister(array($this->loader, 'loadClass'));
}

public function testIdempotence()
{
DebugClassLoader::enable();
DebugClassLoader::enable();

$functions = spl_autoload_functions();
foreach ($functions as $function) {
if (is_array($function) && $function[0] instanceof DebugClassLoader) {
$reflClass = new \ReflectionClass($function[0]);
$reflProp = $reflClass->getProperty('classFinder');
$reflProp->setAccessible(true);

$this->assertNotInstanceOf('Symfony\Component\ClassLoader\DebugClassLoader', $reflProp->getValue($function[0]));
return;
}
}

throw new \Exception('DebugClassLoader did not register');
}
}

1 comment on commit ee495f8

@stof
Copy link
Member

@stof stof commented on ee495f8 Mar 11, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fabpot could this be merged into 2.2 ? The extra wrappings are making our testsuite reaching the max nesting level...

Please sign in to comment.