registerAutoloader() public static method

Registers an instance of this class as an autoloader.
public static registerAutoloader ( ) : void
return void
示例#1
0
<?php

/**
 * Phergie
 *
 * PHP version 5
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.
 * It is also available through the world-wide-web at this URL:
 * http://phergie.org/license
 *
 * @category  Phergie
 * @package   Phergie_Tests
 * @author    Phergie Development Team <*****@*****.**>
 * @copyright 2008-2011 Phergie Development Team (http://phergie.org)
 * @license   http://phergie.org/license New BSD License
 * @link      http://pear.phergie.org/package/Phergie_Tests
 */
error_reporting(E_ALL | E_STRICT);
// Phergie components require Phergie_Autoload to function correctly.
require_once dirname(__FILE__) . '/../Phergie/Autoload.php';
Phergie_Autoload::registerAutoloader();
示例#2
0
 /**
  * Tests that the autoloader strips off prefixes given to addPath() from class names before trying to find their
  * corresponding files. If it fails to do that, the class in this test shouldn't be loaded.
  *
  * @return void
  */
 public function testRemovesPrefixFromClassFileName()
 {
     // Fake environment and register autoloader
     $path = dirname(__FILE__) . '/Autoload/_PrefixRemovedFromClassFileNameTest';
     Phergie_Autoload::registerAutoloader();
     Phergie_Autoload::addPath($path, 'Phergie_Prefixed_');
     $this->assertTrue(class_exists('Phergie_Prefixed_Class', true));
 }
示例#3
0
 /**
  * Tests that expects an error if an expected class wasn't found in a file
  *
  * @return void
  */
 public function testClassNotInFile()
 {
     // Fake environment and register autoloader
     $path = dirname(__FILE__) . '/Autoload/_ClassNotInFileTest';
     set_include_path($path . PATH_SEPARATOR . get_include_path());
     Phergie_Autoload::registerAutoloader();
     try {
         class_exists('Phergie_Missing_Class', true);
         $this->fail('Expected exception not throwen');
     } catch (Phergie_Exception $e) {
         $this->assertEquals('Expected class Phergie_Missing_Class in ' . $path . '/Phergie/Missing/Class.php not found', $e->getMessage());
     }
 }
示例#4
0
 /**
  * Tests that the autoloader can register itself as an autoloader.
  *
  * @return void
  */
 public function testRegisterAutoloader()
 {
     Phergie_Autoload::registerAutoloader();
     $this->assertEquals(1, count(spl_autoload_functions()), 'Autoloader was not registered');
 }
示例#5
0
 /**
  * Tests that the autoloader can successfully autoload a class.
  *
  * @runInSeparateProcess
  * @depends testRegisterAutoloader
  * @return void
  */
 public function testLoad()
 {
     // Need this to load PHPUnit classes inside the separate process
     Phergie_Autoload::registerAutoloader();
     $class = 'Phergie_Bot';
     $autoload = new Phergie_Autoload();
     $this->assertFalse(class_exists($class, false));
     $autoload->load($class);
     $this->assertTrue(class_exists($class, false));
 }