[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/core/tests/cases/ -> lmbClassPathTest.class.php (source)

   1  <?php
   2  /*
   3   * Limb PHP Framework
   4   *
   5   * @link http://limb-project.com 
   6   * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
   7   * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
   8   */
   9  lmb_require('limb/core/src/lmbClassPath.class.php');
  10  
  11  class TestStubForClassPathTest
  12  {
  13    var $a;
  14    var $b;
  15  
  16    function __construct($a=null, $b=null)
  17    {
  18      $this->a = $a;
  19      $this->b = $b;
  20    }
  21  }
  22  
  23  class lmbClassPathTest extends UnitTestCase
  24  {
  25    function setUp()
  26    {
  27      if(!is_dir(LIMB_VAR_DIR))
  28        mkdir(LIMB_VAR_DIR);
  29    }
  30  
  31    function testInvalidClassPath()
  32    {
  33      try
  34      {
  35        $class_path = new lmbClassPath(null);
  36        $this->assertTrue(false);
  37      }
  38      catch(lmbException $e){}
  39  
  40      try
  41      {
  42        $class_path = new lmbClassPath(false);
  43        $this->assertTrue(false);
  44      }
  45      catch(lmbException $e){}
  46  
  47      try
  48      {
  49        $class_path = new lmbClassPath(3);
  50        $this->assertTrue(false);
  51      }
  52      catch(lmbException $e){}
  53  
  54      //Do we need this behaviour? Is it an unneccessary overhead to check for this?

  55      /*try

  56      {

  57        $class_path = new lmbClassPath('invalid.class.path');

  58        $this->assertTrue(false);

  59      }

  60      catch(lmbException $e){}*/
  61    }
  62  
  63    function testGetClassName()
  64    {
  65      $class_path = new lmbClassPath('/foo/Bar');
  66      $this->assertEqual($class_path->getClassName(), 'Bar');
  67  
  68      $class_path = new lmbClassPath('Bar');
  69      $this->assertEqual($class_path->getClassName(), 'Bar');
  70    }
  71  
  72    function testCreateHandle()
  73    {
  74      $class_path = new lmbClassPath('TestStubForClassPathTest');
  75      $handle = $class_path->createHandle();
  76  
  77      $this->assertEqual(get_class($handle), 'lmbHandle');
  78      $this->assertEqual(get_class($handle->resolve()), 'TestStubForClassPathTest');
  79    }
  80  
  81    function testCreateHandlePassArgs()
  82    {
  83      $class_path = new lmbClassPath('TestStubForClassPathTest');
  84      $handle = $class_path->createHandle(array(1, 2));
  85  
  86      $this->assertEqual(get_class($handle), 'lmbHandle');
  87      $this->assertEqual($handle->a, 1);
  88      $this->assertEqual($handle->b, 2);
  89    }
  90  
  91    function testCreateObjectRequireClass()
  92    {
  93      file_put_contents(LIMB_VAR_DIR . '/FooBarZooTest.class.php', "<?php\n class FooBarZooTest{}\n ?>");
  94  
  95      $class_path = new lmbClassPath(LIMB_VAR_DIR . '/FooBarZooTest');
  96      $this->assertEqual(get_class($class_path->createObject()), 'FooBarZooTest');
  97  
  98      unlink(LIMB_VAR_DIR . '/FooBarZooTest.class.php');
  99    }
 100  
 101    function testImport()
 102    {
 103      file_put_contents(LIMB_VAR_DIR . '/FooBarZooTest2.class.php', "<?php\n class FooBarZooTest2{}\n ?>");
 104  
 105      $class_path = new lmbClassPath(LIMB_VAR_DIR . '/FooBarZooTest2');
 106  
 107      $this->assertFalse(class_exists('FooBarZooTest2', true));
 108      $class_path->import();
 109      $this->assertTrue(class_exists('FooBarZooTest2', true));
 110  
 111      unlink(LIMB_VAR_DIR . '/FooBarZooTest2.class.php');
 112    }
 113  
 114    function testImportShortNamedClassFromNonExistingFile()
 115    {
 116      $class_path = new lmbClassPath('FooBarHeyZoo');
 117  
 118      try
 119      {
 120        $class_path->import();
 121        $this->assertTrue(false);
 122      }
 123      catch(lmbException $e){}
 124    }
 125  
 126    function testImportShortNamedClass()
 127    {
 128      file_put_contents(LIMB_VAR_DIR . '/FooBarZooTest3.class.php', "<?php\n class FooBarZooTest3{}\n ?>");
 129  
 130      require_once(LIMB_VAR_DIR . '/FooBarZooTest3.class.php');
 131  
 132      $class_path = new lmbClassPath('FooBarZooTest3');
 133      $class_path->import();
 134  
 135      unlink(LIMB_VAR_DIR . '/FooBarZooTest3.class.php');
 136    }
 137  
 138    function testCreateObjectNoArgs()
 139    {
 140      $class_path = new lmbClassPath('TestStubForClassPathTest');
 141      $obj = $class_path->createObject();
 142  
 143      $this->assertEqual(get_class($obj), 'TestStubForClassPathTest');
 144    }
 145  
 146    function testCreateObjectPassArgs()
 147    {
 148      $class_path = new lmbClassPath('TestStubForClassPathTest');
 149      $obj = $class_path->createObject(array(1, 2));
 150  
 151      $this->assertEqual(get_class($obj), 'TestStubForClassPathTest');
 152      $this->assertEqual($obj->a, 1);
 153      $this->assertEqual($obj->b, 2);
 154    }
 155  
 156    function testCreateStaticCall()
 157    {
 158      $obj = lmbClassPath :: create('TestStubForClassPathTest', array(1, 2));
 159      $this->assertEqual(get_class($obj), 'TestStubForClassPathTest');
 160      $this->assertEqual($obj->a, 1);
 161      $this->assertEqual($obj->b, 2);
 162    }
 163  
 164    function testExpandConstants()
 165    {
 166      file_put_contents(LIMB_VAR_DIR . '/FooBarZooTest2.class.php', "<?php\n class FooBarZooTest2{}\n ?>");
 167  
 168      $class_path = new lmbClassPath('{LIMB_VAR_DIR}/FooBarZooTest2');
 169      $this->assertEqual(get_class($class_path->createObject()), 'FooBarZooTest2');
 170  
 171      unlink(LIMB_VAR_DIR . '/FooBarZooTest2.class.php');
 172    }
 173  }
 174  ?>


Generated: Fri Dec 5 04:05:07 2008 Cross-referenced by PHPXref 0.7