public function getIsSubtypeTests() { $tests = array(); try { $registry = new TypeRegistry(); $foo = new Clazz('Foo'); $foo->setSuperClass('Bar'); $foo->setSuperClasses(array('Bar')); $foo->setImplementedInterfaces(array('Baz', 'FooBar')); $foo->setNormalized(true); $tests[] = array($foo, new InterfaceC('FooBar'), true); $tests[] = array($foo, new InterfaceC('Foo'), false); $tests[] = array($foo, $foo, true); $tests[] = array($foo, new Clazz('Bar'), true); $tests[] = array($foo, new Clazz('FooBar'), false); $tests[] = array($foo, NamedType::createResolved($registry, new InterfaceC('Baz')), true); $tests[] = array($foo, NamedType::createResolved($registry, new InterfaceC('Moo')), false); $tests[] = array($foo, NamedType::createResolved($registry, new Clazz('Foo')), true); $tests[] = array($foo, NamedType::createResolved($registry, new Clazz('FoooFooo')), false); $tests[] = array($foo, new UnknownType($registry, false), true); $tests[] = array($foo, new NoObjectType($registry), true); $tests[] = array($foo, new BooleanType($registry), false); $tests[] = array($foo, new IntegerType($registry), false); $tests[] = array($foo, new DoubleType($registry), false); $tests[] = array($foo, new StringType($registry), false); $tests[] = array($foo, $registry->createUnionType(array('string', new InterfaceC('Baz'))), true); $tests[] = array($foo, $registry->createUnionType(array('string', 'boolean')), false); } catch (\Exception $ex) { echo sprintf("Could not get tests for isSubtypeTests(): %s\n", $ex->getMessage() . ' on line ' . $ex->getLine() . ' in file ' . $ex->getFile()); } return $tests; }
public function testObjectTypes() { $class = new \Scrutinizer\PhpAnalyzer\Model\Clazz('Foo'); $class->setNormalized(true); $this->registry->registerClass($class); $this->assertUnion('object<Foo>', new NamedType($this->registry, 'Foo'), $class); $named = new NamedType($this->registry, 'Foo'); $named->setReferencedType($class); $this->assertUnion('object<Foo>', $named, $class); }
public function testNullableThisType() { $class = new Clazz('Foo'); $class->setNormalized(true); $this->registry->registerClass($class); $builder = new UnionTypeBuilder($this->registry); $this->assertCount(0, $builder->getAlternates()); $builder->addAlternate($this->registry->getNativeType('null')); $this->assertCount(1, $builder->getAlternates()); $builder->addAlternate(new ThisType($this->registry, $class)); $this->assertCount(2, $builder->getAlternates()); $type = $builder->build(); $this->assertInstanceOf('Scrutinizer\\PhpAnalyzer\\PhpParser\\Type\\UnionType', $type); }
private function setUpClass($class, array $extends) { $class = new Clazz($class); if (isset($extends[$class->getName()])) { $parentClass = $this->setUpClass($extends[$class->getName()], $extends); $class->setSuperClasses(array_merge(array($parentClass->getName()), $parentClass->getSuperClasses())); $class->setSuperClass($parentClass->getName()); } $class->setNormalized(true); $this->registry->registerClass($class); return $class; }
private function createClass($class) { $n = new \PHPParser_Node_Name_FullyQualified(explode("\\", $class)); if (is_string($class)) { $class = new \Scrutinizer\PhpAnalyzer\Model\Clazz($class); $class->setNormalized(true); $this->registry->registerClass($class); } $n->setAttribute('type', $class); return $n; }
/** * @group equals */ public function testEqualsWithResolvedNamedAndResolvedType() { $a = new NamedType($this->registry, 'Foo'); $b = new \Scrutinizer\PhpAnalyzer\Model\Clazz('Foo'); $b->setNormalized(true); $a->setReferencedType($b); $this->assertTrue($a->equals($b)); $this->assertTrue($b->equals($a)); $a = new NamedType($this->registry, 'Foo'); $c = new \Scrutinizer\PhpAnalyzer\Model\Clazz('Foo'); $c->setNormalized(true); $a->setReferencedType($c); $this->assertTrue($c->equals($a)); $this->assertTrue($a->equals($c)); }