protected function loadFile($contents, $path = 'qaz.php') { $container = new Container(); $container->set('file', $file = new SourceFile($container, $path, $contents)); $container->set('parser', new Parser($container), ['diagnostics']); return [$file, new Diagnostics($container)]; }
protected function loadFile($contents, $path = 'qaz.php') { $container = new Container(); $container->set('file', new SourceFile($container, $path, $contents)); $container->set('parser', $parser = new Parser($container)); return [$parser, new DocCommentParser($container)]; }
public function test_getPathsForClass_notFound() { $container = new Container(); $container->set('io', new FileIO()); $container->set('file', new SourceFile($container, '/foobar/qaz.php', '')); $locator = new ComposerLocator($container); $this->assertSame([], $locator->getPathsForClass(self::class)); }
protected function loadFile($contents, $path = 'qaz.php') { $container = new Container(); $container->set('file', new SourceFile($container, $path, $contents)); $container->set('parser', new Parser($container)); $container->set('doc_comment', new DocCommentParser($container)); $container->set('name_resolver', new NameResolver($container)); return new FileReflection($container); }
protected function infer(array $nodes, $reflection) { $container = new Container(); $parser = $this->getMockBuilder(Parser::class)->disableOriginalConstructor()->getMock(); $parser->method('getNodes')->willReturn($nodes); $resolver = $this->getMockBuilder(NameResolver::class)->disableOriginalConstructor()->getMock(); $container->set('parser', $parser); $container->set('name_resolver', $resolver); $container->set('reflection', $reflection); (new ReflectionInferrer($container))->run(); }
protected function infer(array $nodes) { $container = new Container(); $parser = $this->getMockBuilder(Parser::class)->disableOriginalConstructor()->getMock(); $parser->method('getNodes')->willReturn($nodes); $resolver = $this->getMockBuilder(NameResolver::class)->disableOriginalConstructor()->getMock(); $container->set('parser', $parser); $container->set('name_resolver', $resolver); $container->set('typeinfer.basic', new BasicInferrer($container), ['typeinfer.visitor']); (new TypeInferrer($container))->run(); }
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_stdlib() { $container = new Container(); $container->set('io', new FileIO()); $jr = new JsonReflection($container, __DIR__ . '/../../../../data/stdlib.json'); $this->assertGreaterThan(0, count($jr->getFunctions())); }
public function complete(array $nodes, array $methods = [], array $props = [], array $consts = []) { $container = new Container(); $parser = $this->getMockBuilder(Parser::class)->disableOriginalConstructor()->getMock(); $parser->method('getNodesAtOffset')->with($this->equalTo(5), $this->equalTo(true))->willReturn($nodes); $container->set('parser', $parser); $typeinfer = $this->getMockBuilder(TypeInferrer::class)->disableOriginalConstructor()->getMock(); $typeinfer->method('run')->willReturn(null); $container->set('typeinfer', $typeinfer); $reflection = $this->getMockBuilder(Reflection::class)->setMethods(['findAllMethods', 'findAllProperties', 'findAllClassConsts'])->disableOriginalConstructor()->getMock(); $reflection->method('findAllMethods')->with($this->equalTo('\\C'))->willReturn($methods); $reflection->method('findAllProperties')->with($this->equalTo('\\C'))->willReturn($props); $reflection->method('findAllClassConsts')->with($this->equalTo('\\C'))->willReturn($consts); $container->set('reflection', $reflection); $completer = new Completer($container); return $completer->complete(5); }
public function testChaining() { $parent = new Container(); $a = new \stdClass(); $b = new \stdClass(); $parent->set('a', $a); $parent->set('b', $b); $child = new Container($parent); $bb = new \stdClass(); $c = new \stdClass(); $child->set('b', $bb); $child->set('c', $c); $this->assertSame($a, $parent->get('a')); $this->assertSame($b, $parent->get('b')); $this->assertSame($a, $child->get('a')); $this->assertSame($bb, $child->get('b')); $this->assertSame($c, $child->get('c')); }
protected function prepare(...$classes) { $map = []; foreach ($classes as $class) { $map[] = [$class->getName(), [$class]]; } $container = new Container(); $refl = $this->createMock(ReflectionInterface::class); $refl->method('findClass')->will($this->returnValueMap($map)); $container->set('reflection', $refl, ['reflection']); return new Reflection($container); }
public function test_New() { $loc = new OffsetLocation('/qaz.php', 5); $cls = (new Class_())->setLocation($loc); $name = new Name\FullyQualified('A\\B\\C'); $expr = new Expr\New_($name, []); $container = new Container(); $parser = $this->getMockBuilder(Parser::class)->disableOriginalConstructor()->getMock(); $parser->method('getNodesAtOffset')->with($this->equalTo(5))->willReturn([$name, $expr]); $container->set('parser', $parser); $nameResolver = $this->getMockBuilder(NameResolver::class)->disableOriginalConstructor()->getMock(); $nameResolver->method('run')->willReturn(null); $container->set('name_resolver', $nameResolver); $reflection = $this->getMockBuilder(Reflection::class)->disableOriginalConstructor()->getMock(); $reflection->method('findClass')->with($this->equalTo('\\A\\B\\C'))->willReturn([$cls]); $reflection->method('findFunction')->with($this->equalTo('\\A\\B\\C'))->willReturn([]); $reflection->method('findConst')->with($this->equalTo('\\A\\B\\C'))->willReturn([]); $container->set('reflection', $reflection); $container->set('goto.name_definition', new GoToClassDefinition($container), ['goto']); $goto = new GoTo_($container); $this->assertSame([$loc], $goto->getGoToLocations(5)); }
public function addIndexerComponents(Container $container, array $options) { if ($options['indexer']['enabled']) { $container->set('parser', new Parser($container), ['diagnostics']); $container->set('name_resolver', new NameResolver($container)); $container->set('reflection', new FileReflection($container), ['reflection']); $container->set('index_data.reflection', new ReflectionIndexData($container), ['index_data']); } }
protected function loadFile($contents, $path = 'qaz.php') { $container = new Container(); $container->set('file', new SourceFile($container, $path, $contents)); return new Parser($container); }