<?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();
/** * 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)); }
/** * 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()); } }
/** * 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'); }
/** * 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)); }