Exemple #1
0
 /**
  * Asserts that registerAutoloader registers callbacks at the stack and
  * can be removed
  *
  * @param AutoloadAPI $api      An AutoloadAPI object
  * @param Mixed       $callback The callback
  *
  * @dataProvider provideCallbacks
  * @return void
  */
 public function testRegisterAndRemove(AutoloadAPI $api, $callback)
 {
     $api->registerAutoloader($callback);
     $this->assertTrue(in_array($callback, $api->getRegisteredAutoloaders()));
     // The autoloader loads now any class
     $class = uniqid('Test');
     $object = new $class();
     $this->assertEquals($class, $object->getName());
     $api->removeAutoloader($callback);
     $this->assertFalse(in_array($callback, $api->getRegisteredAutoloaders()));
     // There is no autoloader left which would load any class
     $class = uniqid('Test2');
     $helper = new AutoloaderTestHelper($this);
     $helper->assertNotLoadable($class);
 }
Exemple #2
0
 /**
  * Deletes all temporary files
  *
  * @return void
  */
 public function tearDown()
 {
     AutoloaderTestHelper::deleteDirectory('.');
     AutoloaderTestHelper::deleteDirectory(TestIndex::getIndexDirectory(), false);
 }
Exemple #3
0
 /**
  * Provides testLoadsOfFiles() with test cases
  *
  * A test case is an instance of AutoloaderFileIterator and a class path.
  * The class path should contain a large amount of files.
  *
  * @see testLoadsOfFiles()
  * @return Array
  */
 public function provideTestLoadsOfFiles()
 {
     AutoloaderTestHelper::deleteDirectory("testLoadsOfFiles");
     $alTestHelper = new AutoloaderTestHelper($this);
     for ($i = 0; $i < 150; $i++) {
         $alTestHelper->makeClass("anyClass", "testLoadsOfFiles/flat");
     }
     for ($i = 0; $i < 150; $i++) {
         $alTestHelper->makeClass("anyClass", "testLoadsOfFiles" . str_repeat('/sub', $i));
     }
     return array(array(new AutoloaderFileIterator_PriorityList(), "testLoadsOfFiles/flat"), array(new AutoloaderFileIterator_Simple(), "testLoadsOfFiles/flat"), array(new AutoloaderFileIterator_SimpleCached(), "testLoadsOfFiles/flat"), array(new AutoloaderFileIterator_PriorityList(), "testLoadsOfFiles/sub"), array(new AutoloaderFileIterator_Simple(), "testLoadsOfFiles/sub"), array(new AutoloaderFileIterator_SimpleCached(), "testLoadsOfFiles/sub"));
 }
 /**
  * Returns test cases for testAutoload()
  *
  * A test case is class name and a path to the definition of this
  * class name.
  *
  * @see testAutoload()
  * @return array
  */
 public function provideTestAutoload()
 {
     $autoloaderTestHelper = new AutoloaderTestHelper($this);
     $return = array();
     $class = $autoloaderTestHelper->makeClass("ClassA", 'testInternal');
     $return[] = array($class, $autoloaderTestHelper->getGeneratedClassPath($class));
     $class = $autoloaderTestHelper->makeClass("ClassA2", 'testInternal');
     $return[] = array($class, $autoloaderTestHelper->getGeneratedClassPath($class));
     $class = $autoloaderTestHelper->makeClass("ClassB", 'testInternal/sub');
     $return[] = array($class, $autoloaderTestHelper->getGeneratedClassPath($class));
     return $return;
 }
Exemple #5
0
 /**
  * Provides code with an array of defined classes
  *
  * @return Array
  */
 public function provideSource()
 {
     $cases = array(array(array("Test"), "<?php interface Test{}?>"), array(array("teSt"), "<?php interface teSt{}?>"), array(array("Test"), "<?php abstract class Test{}?>"), array(array("Test"), "<?php\nclass Test{\n}?>"), array(array("Test"), "<?php\n class Test {\n}?>"), array(array("Test"), "<?php\nclass Test\n {\n}?>"), array(array("Test"), "<?php\nclass Test \n {\n}?>"), array(array("Test"), "<?php\nClass Test \n {\n}?>"), array(array("Test"), "<?php\nclass Test \n {\n}?>"), array(array("Test1", "Test"), "<?php\nclass Test1 \n {\n}\nclass Test \n {\n} ?>"), array(array("Test1", "Test"), "<?php\nclass Test1 \n {\n}\\interface Test \n {\n} ?>"), array(array("Test1", "Test"), "<?php\nabstract class Test1 \n {\n}\\interface Test \n {\n} ?>"), array(array("Test1", "Test"), "<?php\ninterface Test1 \n {\n}\\interface Test \n {\n} ?>"));
     // These tests works only if PHP >= 5.3
     $helper = new AutoloaderTestHelper($this);
     if ($helper->hasNamespaceSupport()) {
         $cases[] = array(array('de\\malkusch\\autoloader\\test\\ns\\bracket\\Test1', 'de\\malkusch\\autoloader\\test\\ns\\bracket\\Test2'), file_get_contents(dirname(__FILE__) . "/namespaceDefinitions/Bracket.php"));
         $cases[] = array(array('de\\malkusch\\autoloader\\test\\ns\\multibracket\\A\\Test1', 'de\\malkusch\\autoloader\\test\\ns\\multibracket\\A\\Test2', 'de\\malkusch\\autoloader\\test\\ns\\multibracket\\B\\Test1', 'de\\malkusch\\autoloader\\test\\ns\\multibracket\\B\\Test2'), file_get_contents(dirname(__FILE__) . "/namespaceDefinitions/MultiBracket.php"));
         $cases[] = array(array('de\\malkusch\\autoloader\\test\\ns\\multinobracket\\A\\Test1', 'de\\malkusch\\autoloader\\test\\ns\\multinobracket\\A\\Test2', 'de\\malkusch\\autoloader\\test\\ns\\multinobracket\\B\\Test1', 'de\\malkusch\\autoloader\\test\\ns\\multinobracket\\B\\Test2'), file_get_contents(dirname(__FILE__) . "/namespaceDefinitions/MultiNoBracket.php"));
         $cases[] = array(array('de\\malkusch\\autoloader\\test\\ns\\nobracket\\Test1', 'de\\malkusch\\autoloader\\test\\ns\\nobracket\\Test2'), file_get_contents(dirname(__FILE__) . "/namespaceDefinitions/NoBracket.php"));
     }
     return $cases;
 }
 /**
  * Asserts that including the file Autoloader.php will register each time an
  * instance of Autoloader with the correct class path
  * 
  * @see Autoloader.php
  * @return void
  */
 public function testSeveralRequiredAutoloaders()
 {
     $autoloaders = Autoloader::getRegisteredAutoloaders();
     Autoloader::removeAll();
     $autoloaderPath = __DIR__ . "/../autoloader.php";
     $classA = $this->_autoloaderTestHelper->makeClass("A", "a");
     $classA2 = $this->_autoloaderTestHelper->makeClass("A2", "a");
     $requireA = $this->_autoloaderTestHelper->makeClass("requireA", "a", "<?php require '{$autoloaderPath}' ?>");
     $classB = $this->_autoloaderTestHelper->makeClass("B", "b");
     $requireB = $this->_autoloaderTestHelper->makeClass("requireB", "b", "<?php require '{$autoloaderPath}' ?>");
     $this->_autoloaderTestHelper->assertNotLoadable($classA);
     $this->_autoloaderTestHelper->assertNotLoadable($classA2);
     include AutoloaderTestHelper::getClassDirectory() . DIRECTORY_SEPARATOR . "a" . DIRECTORY_SEPARATOR . "{$requireA}.test.php";
     $this->_autoloaderTestHelper->assertLoadable($classA);
     $this->_autoloaderTestHelper->assertNotLoadable($classB);
     include AutoloaderTestHelper::getClassDirectory() . DIRECTORY_SEPARATOR . "b" . DIRECTORY_SEPARATOR . "{$requireB}.test.php";
     $this->_autoloaderTestHelper->assertLoadable($classA);
     $this->_autoloaderTestHelper->assertLoadable($classA2);
     $this->_autoloaderTestHelper->assertLoadable($classB);
     Autoloader::removeAll();
     foreach ($autoloaders as $autoloader) {
         $autoloader->register();
     }
 }