Ejemplo n.º 1
0
 /**
  * Creates an abstract item instance.
  *
  * @return PHP_Depend_Code_AbstractItem
  */
 protected function createItem()
 {
     $class = new PHP_Depend_Code_Class(__CLASS__);
     $class->setSourceFile(new PHP_Depend_Code_File(__FILE__));
     $class->setCache(new PHP_Depend_Util_Cache_Driver_Memory());
     $class->setContext($this->getMock('PHP_Depend_Builder_Context'));
     return $class;
 }
Ejemplo n.º 2
0
 /**
  * testGetEndLineReturnsEndLineOfLastToken
  *
  * @return void
  * @group pdepend
  * @group pdepend::code
  * @group unittest
  */
 public function testGetEndLineReturnsEndLineOfLastToken()
 {
     $cache = $this->getMock('PHP_Depend_Util_Cache_Driver');
     $cache->expects($this->once())->method('type')->will($this->returnValue($cache));
     $class = new PHP_Depend_Code_Class(__CLASS__);
     $class->setCache($cache)->setTokens(array(new PHP_Depend_Token(1, 'a', 23, 42, 0, 0), new PHP_Depend_Token(2, 'b', 17, 32, 0, 0)));
     self::assertEquals(32, $class->getEndLine());
 }
Ejemplo n.º 3
0
 /**
  * Builds a new class instance or reuses a previous created class.
  *
  * Where possible you should give a qualified class name, that is prefixed
  * with the package identifier.
  *
  * <code>
  *   $builder->buildClass('php::depend::Parser');
  * </code>
  *
  * To determine the correct class, this method implements the following
  * algorithm.
  *
  * <ol>
  *   <li>Check for an exactly matching instance and reuse it.</li>
  *   <li>Check for a class instance that belongs to the default package. If
  *   such an instance exists, reuse it and replace the default package with
  *   the newly given package information.</li>
  *   <li>Check that the requested class is in the default package, if this
  *   is true, reuse the first class instance and ignore the default package.
  *   </li>
  *   <li>Create a new instance for the specified package.</li>
  * </ol>
  *
  * @param string $name The class name.
  *
  * @return PHP_Depend_Code_Class The created class object.
  */
 public function buildClass($name)
 {
     $this->checkBuilderState();
     $class = new PHP_Depend_Code_Class($this->extractTypeName($name));
     $class->setCache($this->cache)->setContext($this->context)->setSourceFile($this->defaultFile);
     return $class;
 }
Ejemplo n.º 4
0
 /**
  * Creates a ready to use class fixture.
  *
  * @param string $name Optional class name.
  *
  * @return PHP_Depend_Code_Class
  * @since 1.0.2
  */
 protected function createClassFixture($name = null)
 {
     $name = $name ? $name : get_class($this);
     $class = new PHP_Depend_Code_Class($name);
     $class->setSourceFile(new PHP_Depend_Code_File($GLOBALS['argv'][0]));
     $class->setCache(new PHP_Depend_Util_Cache_Driver_Memory());
     $class->setContext($this->getMock('PHP_Depend_Builder_Context'));
     return $class;
 }