bug #10308 [Debug] enhance non-PSR-0 compatibility for case mismatch test (nicolas-grekas)
This PR was merged into the 2.5-dev branch.
Discussion
----------
[Debug] enhance non-PSR-0 compatibility for case mismatch test
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | no
| License | MIT
| Doc PR | no
Fix compatibility with non-PSR-0/4 loading schemes.
See https://github.com/symfony/symfony/pull/10201#issuecomment-35567573
Commits
-------
120e197
[Debug] enhance non-PSR-0 compatibility for case mismatch test
This commit is contained in:
commit
a8209307f8
@ -176,18 +176,30 @@ class DebugClassLoader
|
||||
$class = substr($class, 1);
|
||||
}
|
||||
|
||||
$i = -1;
|
||||
$tail = str_replace('\\', DIRECTORY_SEPARATOR, $class).'.php';
|
||||
$i = 0;
|
||||
$tail = DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $class).'.php';
|
||||
$len = strlen($tail);
|
||||
|
||||
do {
|
||||
$tail = substr($tail, $i+1);
|
||||
$len -= $i+1;
|
||||
$tail = substr($tail, $i);
|
||||
$len -= $i;
|
||||
|
||||
if (! substr_compare($file, $tail, -$len, $len, true) && substr_compare($file, $tail, -$len, $len, false)) {
|
||||
throw new \RuntimeException(sprintf('Case mismatch between class and source file names: %s vs %s', $class, $file));
|
||||
if (0 === substr_compare($file, $tail, -$len, $len, true)) {
|
||||
if (0 !== substr_compare($file, $tail, -$len, $len, false)) {
|
||||
if (method_exists($this->classLoader[0], 'getClassMap')) {
|
||||
$map = $this->classLoader[0]->getClassMap();
|
||||
} else {
|
||||
$map = array();
|
||||
}
|
||||
|
||||
if (! isset($map[$class])) {
|
||||
throw new \RuntimeException(sprintf('Case mismatch between class and source file names: %s vs %s', $class, $file));
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
} while (false !== $i = strpos($tail, '\\'));
|
||||
} while (false !== $i = strpos($tail, DIRECTORY_SEPARATOR, 1));
|
||||
|
||||
if (! $exists) {
|
||||
if (false !== strpos($class, '/')) {
|
||||
|
@ -140,6 +140,24 @@ class DebugClassLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
class_exists(__NAMESPACE__.'\Fixtures\CaseMismatch', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
*/
|
||||
public function testPsr4CaseMismatch()
|
||||
{
|
||||
class_exists(__NAMESPACE__.'\Fixtures\Psr4CaseMismatch', true);
|
||||
}
|
||||
|
||||
public function testNotPsr0()
|
||||
{
|
||||
$this->assertTrue(class_exists(__NAMESPACE__.'\Fixtures\NotPSR0', true));
|
||||
}
|
||||
|
||||
public function testNotPsr0Bis()
|
||||
{
|
||||
$this->assertTrue(class_exists(__NAMESPACE__.'\Fixtures\NotPSR0bis', true));
|
||||
}
|
||||
}
|
||||
|
||||
class ClassLoader
|
||||
@ -148,6 +166,11 @@ class ClassLoader
|
||||
{
|
||||
}
|
||||
|
||||
public function getClassMap()
|
||||
{
|
||||
return array(__NAMESPACE__.'\Fixtures\NotPSR0bis' => __DIR__ . '/Fixtures/notPsr0Bis.php');
|
||||
}
|
||||
|
||||
public function findFile($class)
|
||||
{
|
||||
if (__NAMESPACE__.'\TestingUnsilencing' === $class) {
|
||||
@ -158,6 +181,12 @@ class ClassLoader
|
||||
eval('namespace '.__NAMESPACE__.'; class TestingCaseMisMatch {}');
|
||||
} elseif (__NAMESPACE__.'\Fixtures\CaseMismatch' === $class) {
|
||||
return __DIR__ . '/Fixtures/casemismatch.php';
|
||||
} elseif (__NAMESPACE__.'\Fixtures\Psr4CaseMismatch' === $class) {
|
||||
return __DIR__ . '/Fixtures/psr4/Psr4CaseMismatch.php';
|
||||
} elseif (__NAMESPACE__.'\Fixtures\NotPSR0' === $class) {
|
||||
return __DIR__ . '/Fixtures/reallyNotPsr0.php';
|
||||
} elseif (__NAMESPACE__.'\Fixtures\NotPSR0bis' === $class) {
|
||||
return __DIR__ . '/Fixtures/notPsr0Bis.php';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Debug\Tests\Fixtures;
|
||||
|
||||
class NotPSR0bis
|
||||
{
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Debug\Tests\Fixtures;
|
||||
|
||||
class PSR4CaseMismatch
|
||||
{
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Debug\Tests\Fixtures;
|
||||
|
||||
class NotPSR0
|
||||
{
|
||||
}
|
Reference in New Issue
Block a user