You are here

public function ClassLoaderTest::testClassExistsWithSilentAutoloader in Plug 7

File

lib/doctrine/common/tests/Doctrine/Tests/Common/ClassLoaderTest.php, line 46

Class

ClassLoaderTest

Namespace

Doctrine\Tests\Common

Code

public function testClassExistsWithSilentAutoloader() {
  $test = $this;
  $silentLoader = function ($className) use ($test) {
    $test
      ->assertSame('ClassLoaderTest\\ClassE', $className);
    require __DIR__ . '/ClassLoaderTest/ClassE.php';
  };
  $additionalLoader = function () use ($test) {
    $test
      ->fail('Should not call this loader, class was already loaded');
  };
  $this
    ->assertFalse(ClassLoader::classExists('ClassLoaderTest\\ClassE'));
  spl_autoload_register($silentLoader);
  spl_autoload_register($additionalLoader);
  $this
    ->assertTrue(ClassLoader::classExists('ClassLoaderTest\\ClassE'));
  spl_autoload_unregister($additionalLoader);
  spl_autoload_unregister($silentLoader);
}