예제 #1
0
 public function testProperties()
 {
     $class = new PhpClass();
     $this->assertEquals(array(), $class->getProperties());
     $this->assertSame($class, $class->setProperty($prop = new PhpProperty('foo')));
     $this->assertSame(array('foo' => $prop), $class->getProperties());
     $this->assertTrue($class->hasProperty('foo'));
     $this->assertSame($class, $class->removeProperty('foo'));
     $this->assertEquals(array(), $class->getProperties());
     $prop = new PhpProperty('bam');
     $class->setProperty($prop);
     $this->assertTrue($class->hasProperty($prop));
     $this->assertSame($class, $class->removeProperty($prop));
     $class->setProperty($orphaned = new PhpProperty('orphaned'));
     $this->assertSame($class, $orphaned->getParent());
     $this->assertSame($orphaned, $class->getProperty('orphaned'));
     $this->assertSame($orphaned, $class->getProperty($orphaned));
     $this->assertEmpty($class->getProperty('prop-not-found'));
     $this->assertTrue($class->hasProperty($orphaned));
     $this->assertSame($class, $class->setProperties([$prop, $prop2 = new PhpProperty('bar')]));
     $this->assertSame(['bam' => $prop, 'bar' => $prop2], $class->getProperties());
     $this->assertNull($orphaned->getParent());
 }
예제 #2
0
 public function testProperties()
 {
     $class = new PhpClass();
     $this->assertTrue($class->getProperties()->isEmpty());
     $this->assertSame($class, $class->setProperty($prop = new PhpProperty('foo')));
     $this->assertSame(['foo' => $prop], $class->getProperties()->toArray());
     $this->assertTrue($class->hasProperty('foo'));
     $this->assertSame($class, $class->removeProperty('foo'));
     $this->assertTrue($class->getProperties()->isEmpty());
     $prop = new PhpProperty('bam');
     $class->setProperty($prop);
     $this->assertTrue($class->hasProperty($prop));
     $this->assertSame($class, $class->removeProperty($prop));
     $class->setProperty($orphaned = new PhpProperty('orphaned'));
     $this->assertSame($class, $orphaned->getParent());
     $this->assertSame($orphaned, $class->getProperty('orphaned'));
     $this->assertSame($orphaned, $class->getProperty($orphaned));
     $this->assertTrue($class->hasProperty($orphaned));
     $this->assertSame($class, $class->setProperties([$prop, $prop2 = new PhpProperty('bar')]));
     $this->assertSame(['bam' => $prop, 'bar' => $prop2], $class->getProperties()->toArray());
     $this->assertEquals(['bam', 'bar'], $class->getPropertyNames()->toArray());
     $this->assertNull($orphaned->getParent());
     $this->assertFalse($class->getProperties()->isEmpty());
     $class->clearProperties();
     $this->assertTrue($class->getProperties()->isEmpty());
     try {
         $this->assertEmpty($class->getProperty('prop-not-found'));
     } catch (\InvalidArgumentException $e) {
         $this->assertNotNull($e);
     }
 }