Skip to content
This repository has been archived by the owner on Dec 9, 2023. It is now read-only.

Commit

Permalink
Use ::class constants instead of __NAMESPACE__ when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
fre5h authored and nicolas-grekas committed Dec 16, 2019
1 parent f72e33f commit 9d32af2
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions Tests/DebugClassLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ public function testThrowingClass()
$this->expectException('Exception');
$this->expectExceptionMessage('boo');
try {
class_exists(__NAMESPACE__.'\Fixtures\Throwing');
class_exists(Fixtures\Throwing::class);
$this->fail('Exception expected');
} catch (\Exception $e) {
$this->assertSame('boo', $e->getMessage());
}

// the second call also should throw
class_exists(__NAMESPACE__.'\Fixtures\Throwing');
class_exists(Fixtures\Throwing::class);
}

public function testUnsilencing()
Expand All @@ -90,7 +90,7 @@ public function testUnsilencing()

// See below: this will fail with parse error
// but this should not be @-silenced.
@class_exists(__NAMESPACE__.'\TestingUnsilencing', true);
@class_exists(TestingUnsilencing::class, true);

$output = ob_get_clean();

Expand Down Expand Up @@ -141,7 +141,7 @@ public function testNameCaseMismatch()
{
$this->expectException('RuntimeException');
$this->expectExceptionMessage('Case mismatch between loaded and declared class names');
class_exists(__NAMESPACE__.'\TestingCaseMismatch', true);
class_exists(TestingCaseMismatch::class, true);
}

public function testFileCaseMismatch()
Expand All @@ -152,7 +152,7 @@ public function testFileCaseMismatch()
$this->markTestSkipped('Can only be run on case insensitive filesystems');
}

class_exists(__NAMESPACE__.'\Fixtures\CaseMismatch', true);
class_exists(Fixtures\CaseMismatch::class, true);
}

public function testPsr4CaseMismatch()
Expand All @@ -174,7 +174,7 @@ public function testNotPsr0Bis()

public function testClassAlias()
{
$this->assertTrue(class_exists(__NAMESPACE__.'\Fixtures\ClassAlias', true));
$this->assertTrue(class_exists(Fixtures\ClassAlias::class, true));
}

/**
Expand Down Expand Up @@ -216,7 +216,7 @@ public function testInterfaceExtendsDeprecatedInterface()
$e = error_reporting(0);
trigger_error('', E_USER_NOTICE);

class_exists('Test\\'.__NAMESPACE__.'\\NonDeprecatedInterfaceClass', true);
class_exists('Test\\'.NonDeprecatedInterfaceClass::class, true);

error_reporting($e);
restore_error_handler();
Expand Down Expand Up @@ -264,7 +264,7 @@ public function testReservedForPhp7()
$e = error_reporting(0);
trigger_error('', E_USER_NOTICE);

class_exists('Test\\'.__NAMESPACE__.'\\Float', true);
class_exists('Test\\'.Float::class, true);

error_reporting($e);
restore_error_handler();
Expand All @@ -289,7 +289,7 @@ public function testExtendedFinalClass()
require __DIR__.'/Fixtures/FinalClasses.php';

$i = 1;
while (class_exists($finalClass = __NAMESPACE__.'\\Fixtures\\FinalClass'.$i++, false)) {
while (class_exists($finalClass = Fixtures\FinalClass::class.$i++, false)) {
spl_autoload_call($finalClass);
class_exists('Test\\'.__NAMESPACE__.'\\Extends'.substr($finalClass, strrpos($finalClass, '\\') + 1), true);
}
Expand All @@ -315,7 +315,7 @@ public function testExtendedFinalMethod()
set_error_handler(function ($type, $msg) use (&$deprecations) { $deprecations[] = $msg; });
$e = error_reporting(E_USER_DEPRECATED);

class_exists(__NAMESPACE__.'\\Fixtures\\ExtendedFinalMethod', true);
class_exists(Fixtures\ExtendedFinalMethod::class, true);

error_reporting($e);
restore_error_handler();
Expand All @@ -334,7 +334,7 @@ public function testExtendedDeprecatedMethodDoesntTriggerAnyNotice()
$e = error_reporting(0);
trigger_error('', E_USER_NOTICE);

class_exists('Test\\'.__NAMESPACE__.'\\ExtendsAnnotatedClass', true);
class_exists('Test\\'.ExtendsAnnotatedClass::class, true);

error_reporting($e);
restore_error_handler();
Expand All @@ -351,7 +351,7 @@ public function testInternalsUse()
set_error_handler(function ($type, $msg) use (&$deprecations) { $deprecations[] = $msg; });
$e = error_reporting(E_USER_DEPRECATED);

class_exists('Test\\'.__NAMESPACE__.'\\ExtendsInternals', true);
class_exists('Test\\'.ExtendsInternals::class, true);

error_reporting($e);
restore_error_handler();
Expand All @@ -370,7 +370,7 @@ public function testUseTraitWithInternalMethod()
set_error_handler(function ($type, $msg) use (&$deprecations) { $deprecations[] = $msg; });
$e = error_reporting(E_USER_DEPRECATED);

class_exists('Test\\'.__NAMESPACE__.'\\UseTraitWithInternalMethod', true);
class_exists('Test\\'.UseTraitWithInternalMethod::class, true);

error_reporting($e);
restore_error_handler();
Expand All @@ -380,7 +380,7 @@ class_exists('Test\\'.__NAMESPACE__.'\\UseTraitWithInternalMethod', true);

public function testEvaluatedCode()
{
$this->assertTrue(class_exists(__NAMESPACE__.'\Fixtures\DefinitionInEvaluatedCode', true));
$this->assertTrue(class_exists(Fixtures\DefinitionInEvaluatedCode::class, true));
}
}

Expand All @@ -399,11 +399,11 @@ public function findFile($class)
{
$fixtureDir = __DIR__.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR;

if (__NAMESPACE__.'\TestingUnsilencing' === $class) {
if (TestingUnsilencing::class === $class) {
eval('-- parse error --');
} elseif (__NAMESPACE__.'\TestingStacking' === $class) {
} elseif (TestingStacking::class === $class) {
eval('namespace '.__NAMESPACE__.'; class TestingStacking { function foo() {} }');
} elseif (__NAMESPACE__.'\TestingCaseMismatch' === $class) {
} elseif (TestingCaseMismatch::class === $class) {
eval('namespace '.__NAMESPACE__.'; class TestingCaseMisMatch {}');
} elseif (__NAMESPACE__.'\Fixtures\Psr4CaseMismatch' === $class) {
return $fixtureDir.'psr4'.\DIRECTORY_SEPARATOR.'Psr4CaseMismatch.php';
Expand All @@ -413,30 +413,30 @@ public function findFile($class)
return $fixtureDir.'notPsr0Bis.php';
} elseif ('Symfony\Bridge\Debug\Tests\Fixtures\ExtendsDeprecatedParent' === $class) {
eval('namespace Symfony\Bridge\Debug\Tests\Fixtures; class ExtendsDeprecatedParent extends \\'.__NAMESPACE__.'\Fixtures\DeprecatedClass {}');
} elseif ('Test\\'.__NAMESPACE__.'\DeprecatedParentClass' === $class) {
} elseif ('Test\\'.DeprecatedParentClass::class === $class) {
eval('namespace Test\\'.__NAMESPACE__.'; class DeprecatedParentClass extends \\'.__NAMESPACE__.'\Fixtures\DeprecatedClass {}');
} elseif ('Test\\'.__NAMESPACE__.'\DeprecatedInterfaceClass' === $class) {
} elseif ('Test\\'.DeprecatedInterfaceClass::class === $class) {
eval('namespace Test\\'.__NAMESPACE__.'; class DeprecatedInterfaceClass implements \\'.__NAMESPACE__.'\Fixtures\DeprecatedInterface {}');
} elseif ('Test\\'.__NAMESPACE__.'\NonDeprecatedInterfaceClass' === $class) {
} elseif ('Test\\'.NonDeprecatedInterfaceClass::class === $class) {
eval('namespace Test\\'.__NAMESPACE__.'; class NonDeprecatedInterfaceClass implements \\'.__NAMESPACE__.'\Fixtures\NonDeprecatedInterface {}');
} elseif ('Test\\'.__NAMESPACE__.'\Float' === $class) {
} elseif ('Test\\'.Float::class === $class) {
eval('namespace Test\\'.__NAMESPACE__.'; class Float {}');
} elseif (0 === strpos($class, 'Test\\'.__NAMESPACE__.'\ExtendsFinalClass')) {
} elseif (0 === strpos($class, 'Test\\'.ExtendsFinalClass::class)) {
$classShortName = substr($class, strrpos($class, '\\') + 1);
eval('namespace Test\\'.__NAMESPACE__.'; class '.$classShortName.' extends \\'.__NAMESPACE__.'\Fixtures\\'.substr($classShortName, 7).' {}');
} elseif ('Test\\'.__NAMESPACE__.'\ExtendsAnnotatedClass' === $class) {
} elseif ('Test\\'.ExtendsAnnotatedClass::class === $class) {
eval('namespace Test\\'.__NAMESPACE__.'; class ExtendsAnnotatedClass extends \\'.__NAMESPACE__.'\Fixtures\AnnotatedClass {
public function deprecatedMethod() { }
}');
} elseif ('Test\\'.__NAMESPACE__.'\ExtendsInternals' === $class) {
} elseif ('Test\\'.ExtendsInternals::class === $class) {
eval('namespace Test\\'.__NAMESPACE__.'; class ExtendsInternals extends ExtendsInternalsParent {
use \\'.__NAMESPACE__.'\Fixtures\InternalTrait;
public function internalMethod() { }
}');
} elseif ('Test\\'.__NAMESPACE__.'\ExtendsInternalsParent' === $class) {
} elseif ('Test\\'.ExtendsInternalsParent::class === $class) {
eval('namespace Test\\'.__NAMESPACE__.'; class ExtendsInternalsParent extends \\'.__NAMESPACE__.'\Fixtures\InternalClass implements \\'.__NAMESPACE__.'\Fixtures\InternalInterface { }');
} elseif ('Test\\'.__NAMESPACE__.'\UseTraitWithInternalMethod' === $class) {
} elseif ('Test\\'.UseTraitWithInternalMethod::class === $class) {
eval('namespace Test\\'.__NAMESPACE__.'; class UseTraitWithInternalMethod { use \\'.__NAMESPACE__.'\Fixtures\TraitWithInternalMethod; }');
}

Expand Down

0 comments on commit 9d32af2

Please sign in to comment.