public function testUseStatements() { $class = new PhpClass(); $this->assertEquals(array(), $class->getUseStatements()); $this->assertSame($class, $class->setUseStatements(array('foo' => 'bar'))); $this->assertEquals(array('foo' => 'bar'), $class->getUseStatements()); $this->assertSame($class, $class->addUseStatement('Foo\\Bar')); $this->assertEquals(array('foo' => 'bar', 'Bar' => 'Foo\\Bar'), $class->getUseStatements()); $this->assertSame($class, $class->addUseStatement('Foo\\Bar', 'Baz')); $this->assertEquals(array('foo' => 'bar', 'Bar' => 'Foo\\Bar', 'Baz' => 'Foo\\Bar'), $class->getUseStatements()); $this->assertTrue($class->hasUseStatement('bar')); $class->removeUseStatement('bar'); $this->assertFalse($class->hasUseStatement('bar')); // from reflection require_once __DIR__ . '/../fixture/DummyTrait.php'; $statements = ReflectionUtils::getUseStatements(new \ReflectionClass('gossi\\codegen\\tests\\fixture\\DummyTrait')); $this->assertEquals(['gossi\\codegen\\tests\\fixture\\VeryDummyTrait'], $statements); require_once __DIR__ . '/../fixture/ClassWithTraits.php'; $statements = ReflectionUtils::getUseStatements(new \ReflectionClass('gossi\\codegen\\tests\\fixture\\ClassWithTraits')); $this->assertEquals(['DT' => 'gossi\\codegen\\tests\\fixture\\DummyTrait'], $statements); }
public function testUseStatements() { $class = new PhpClass(); $this->assertTrue($class->getUseStatements()->isEmpty()); $this->assertSame($class, $class->setUseStatements(['foo' => 'bar'])); $this->assertEquals(['foo' => 'bar'], $class->getUseStatements()->toArray()); $this->assertSame($class, $class->addUseStatement('Foo\\Bar')); $this->assertEquals(['foo' => 'bar', 'Bar' => 'Foo\\Bar'], $class->getUseStatements()->toArray()); $this->assertSame($class, $class->addUseStatement('Foo\\Bar', 'Baz')); $this->assertEquals(['foo' => 'bar', 'Bar' => 'Foo\\Bar', 'Baz' => 'Foo\\Bar'], $class->getUseStatements()->toArray()); $this->assertTrue($class->hasUseStatement('bar')); $class->removeUseStatement('bar'); $this->assertFalse($class->hasUseStatement('bar')); $class->clearUseStatements(); $class->addUseStatement('ArrayList'); $this->assertEquals(['ArrayList' => 'ArrayList'], $class->getUseStatements()->toArray()); // declareUse $this->assertEquals('ArrayList', $class->declareUse('phootwork\\collection\\ArrayList')); $this->assertEquals('Foo', $class->declareUse('phootwork\\collection\\Stack', 'Foo')); $class->declareUses('phootwork\\collection\\Set', 'phootwork\\collection\\Map'); $this->assertTrue($class->hasUseStatement('phootwork\\collection\\Set')); $this->assertTrue($class->hasUseStatement('phootwork\\collection\\Map')); }
public function testUseStatements() { $class = new PhpClass(); $class->addUseStatement('Symfony\\Component\\Console\\Application', 'Console'); $this->assertEquals(['Console' => 'Symfony\\Component\\Console\\Application'], $class->getUseStatements()); $this->assertEquals('Console', $class->getUseAlias('Symfony\\Component\\Console\\Application')); $class->addUseStatement('Logger'); $this->assertEquals(['Console' => 'Symfony\\Component\\Console\\Application', 'Logger' => 'Logger'], $class->getUseStatements()); $this->assertEquals('Logger', $class->getUseAlias('Logger')); }