/** * testGetMethodNamesReturnsExpectedResult * * @return void * @covers PHP_PMD_Node_Class * @covers PHP_PMD_Node_AbstractType * @group phpmd * @group phpmd::node * @group unittest */ public function testGetMethodNamesReturnsExpectedResult() { $class = new PHP_Depend_Code_Class(null); $class->addMethod(new PHP_Depend_Code_Method(__CLASS__)); $class->addMethod(new PHP_Depend_Code_Method(__FUNCTION__)); $node = new PHP_PMD_Node_Class($class); $this->assertEquals(array(__CLASS__, __FUNCTION__), $node->getMethodNames()); }
/** * testMagicWakeupSetsSourceFileOnChildMethods * * @return void */ public function testMagicWakeupSetsSourceFileOnChildMethods() { $class = new PHP_Depend_Code_Class(__CLASS__); $class->setCache(new PHP_Depend_Util_Cache_Driver_Memory()); $method = new PHP_Depend_Code_Method(__FUNCTION__); $class->addMethod($method); $class->setContext($this->getMock('PHP_Depend_Builder_Context')); $file = new PHP_Depend_Code_File(__FILE__); $class->setSourceFile($file); $class->__wakeup(); self::assertSame($file, $method->getSourceFile()); }
/** * testMagicWakeupSetsParentOnChildMethods * * @return void * @group pdepend * @group pdepend::code * @group unittest */ public function testMagicWakeupSetsParentOnChildMethods() { $class = new PHP_Depend_Code_Class(__CLASS__); $method = new PHP_Depend_Code_Method(__FUNCTION__); $class->addMethod($method); $class->setContext($this->getMock('PHP_Depend_Builder_Context')); $method->setParent(null); $class->__wakeup(); self::assertSame($class, $method->getParent()); }
/** * Tests that the {@link PHP_Depend_Code_Class::addMethod()} method adds a * method to the internal list and sets the context class as parent. * * @return void * @covers PHP_Depend_Code_AbstractClassOrInterface * @covers PHP_Depend_Code_Class * @group pdepend * @group pdepend::code * @group unittest */ public function testAddNewMethod() { $class = new PHP_Depend_Code_Class('clazz', 0); $method = new PHP_Depend_Code_Method('method', 0); $this->assertNull($method->getParent()); $class->addMethod($method); $this->assertSame($class, $method->getParent()); $this->assertEquals(1, $class->getMethods()->count()); }
/** * Tests that the {@link PHP_Depend_Code_Class::addMethod()} reparents the * new method if it already has a parent class instance. * * @return void * @covers PHP_Depend_Code_AbstractClassOrInterface * @covers PHP_Depend_Code_Class * @group pdepend * @group pdepend::code * @group unittest */ public function testAddNewMethodAndReparent() { $class1 = new PHP_Depend_Code_Class('clazz1', 0); $class2 = new PHP_Depend_Code_Class('clazz2', 0); $method = new PHP_Depend_Code_Method('method', 0); $class1->addMethod($method); $this->assertSame($class1, $method->getParent()); $this->assertSame($method, $class1->getMethods()->current()); $class2->addMethod($method); $this->assertSame($class2, $method->getParent()); $this->assertSame($method, $class2->getMethods()->current()); $this->assertEquals(0, $class1->getMethods()->count()); }