public function test_StaticPropertyFetch_self() { $prop = (new Property())->setName('x')->setStatic(true)->setType(Type::int_()); $refl = $this->getMockBuilder(Reflection::class)->disableOriginalConstructor()->getMock(); $refl->expects($this->once())->method('findProperty')->with($this->equalTo('\\C'), $this->equalTo('$x'))->willReturn($prop); $expr = new Expr\StaticPropertyFetch(new Name('self'), 'x'); $class = new Stmt\Class_('C', ['stmts' => [new Stmt\ClassMethod('f', ['stmts' => [$expr]])]], ['namespacedName' => new Name\FullyQualified('C')]); $this->infer([$class], $refl); $this->assertTrue($expr->getAttribute('type')->equals(Type::int_())); $this->assertSame([$prop], $expr->getAttribute('reflections')); }
public function test_Ternary() { $var1 = new Expr\Variable('a', ['type' => Type::array_()]); $var2 = new Expr\Variable('b', ['type' => Type::int_()]); $var3 = new Expr\Variable('c', ['type' => Type::float_()]); $expr = new Expr\Ternary($var1, $var2, $var3); $this->infer([$expr]); $this->assertTrue($expr->getAttribute('type')->equals(Type::alternatives([Type::int_(), Type::float_()]))); $expr = new Expr\Ternary($var1, null, $var3); $this->infer([$expr]); $this->assertTrue($expr->getAttribute('type')->equals(Type::alternatives([Type::array_(), Type::float_()]))); }
public function test_getType() { $expr = new Expr\Variable('qaz', ['type' => Type::int_()]); $container = new Container(); $parser = $this->getMockBuilder(Parser::class)->disableOriginalConstructor()->getMock(); $parser->method('getNodes')->willReturn([]); $parser->method('getNodesAtOffset')->with($this->equalTo(7))->willReturn([$expr]); $resolver = $this->getMockBuilder(NameResolver::class)->disableOriginalConstructor()->getMock(); $container->set('parser', $parser); $container->set('name_resolver', $resolver); $this->assertTrue(Type::int_()->equals((new TypeInferrer($container))->getType(7))); }
public function test_MethodCall_self() { $class = (new Class_())->setName('\\C'); $method = (new Method())->setName('qaz')->setClass($class)->setDocReturnType(Type::int_()); $cls = new Name('self'); $cls->setAttribute('resolved', new Name\FullyQualified('C')); $id = new Identifier('q'); $expr = new Expr\StaticCall($cls, $id, []); $ctxmeth = new Stmt\ClassMethod('mm'); $ctxcls = new Stmt\Class_('C'); $ctxcls->setAttribute('namespacedName', '\\C'); $completions = $this->complete([$id, $expr, $ctxmeth, $ctxcls], [$method]); $this->assertCount(1, $completions); }