Пример #1
0
 public function testParseProperty_defaultValue()
 {
     $access = \vc\Tokens\Access::buildAccess($this->oneTokenReader()->thenAPublic->thenSomeSpace->thenAVariable('$var')->thenSomeSpace->thenAnEquals->thenAnInteger(789)->thenASemicolon);
     $sig = new \vc\Data\Signature(120, new \vc\Data\Comment('Note'));
     $this->assertEquals(r8(new \vc\Data\Property(120, new \vc\Data\Comment('Note')))->setName('$var')->setValue(new \vc\Data\Value(789, 'int')), $this->getPropertyParser()->parseProperty($sig, $access));
     $this->assertEndOfTokens($access);
 }
Пример #2
0
 /**
  * Parses the given token reader
  *
  * @param \r8\FileSys\File $path The file to parse
  * @return \vc\Data\File
  */
 public function parse(\r8\FileSys\File $path)
 {
     $file = new \vc\Data\File($path->getPath());
     $tokens = \vc\Tokens\Access::buildAccess(new \vc\Tokens\Parser(new \r8\Stream\In\File($path)));
     $this->comment->parse($file, $tokens);
     return $file;
 }
Пример #3
0
 public function testParseConstant_Heredoc()
 {
     $access = \vc\Tokens\Access::buildAccess($this->oneTokenReader()->thenAConst->thenSomeSpace->thenAName('NAME')->thenSomeSpace->thenAnEquals->thenSomeSpace->thenAHereDoc('contents')->thenASemicolon->thenAClass);
     $parser = $this->getConstantParser();
     $this->assertEquals(r8(new \vc\Data\Constant('NAME'))->setValue(new \vc\Data\Value('contents', 'string')), $parser->parseConstant($access));
     $this->assertHasToken(Token::T_CLASS, $access);
 }
Пример #4
0
 public function testUntilBlockEnds()
 {
     $access = \vc\Tokens\Access::buildAccess($this->oneTokenReader()->thenAFunction->thenACloseBlock->thenAClass);
     $until = $access->untilBlockEnds();
     $this->assertThat($until, $this->isInstanceOf('\\vc\\Tokens\\Access'));
     $this->assertHasToken(Token::T_FUNCTION, $until);
     $this->assertEndOfTokens($until);
 }
Пример #5
0
 public function testNoCommentFound()
 {
     $reader = \vc\Tokens\Access::buildAccess($this->oneTokenReader()->thenAnOpenTag->thenSomeSpace->thenAClass->thenADocComment('This is a file comment'));
     $parser = new \vc\Parser\File\Comment(new \vc\Parser\Comment(), $this->getStub('vc\\Parser\\File\\NSpaces'));
     $file = new \vc\Data\File('file.php');
     $parser->parse($file, $reader);
     $this->assertEquals(new \vc\Data\Comment(), $file->getComment());
 }
Пример #6
0
 public function testParseAnonymousFunc_ReturnsReference()
 {
     $access = \vc\Tokens\Access::buildAccess($this->oneTokenReader()->thenAFunction->thenSomeSpace->thenAnAmpersand->thenOpenParens->thenCloseParens->thenASemicolon);
     $routine = $this->getMockForAbstractClass('\\vc\\Data\\Routine', array(1));
     $this->getFuncParser()->parseRoutine($routine, $access);
     $this->assertNull($routine->getName());
     $this->assertTrue($routine->getReturnRef());
     $this->assertEndOfTokens($access);
 }
Пример #7
0
 public function testParse_MultipleSemicolonNamespaceDefinitions()
 {
     $file = new \vc\Data\File('path.php');
     $access = \vc\Tokens\Access::buildAccess($this->oneTokenReader()->thenANamespace('sub\\sub2')->thenASemicolon->thenAFunction->thenANamespace('ns2')->thenASemicolon->thenAFunction);
     $parser = new \vc\Parser\File\NSpaces(new \vc\Parser\Path(), $this->getNSpaceParser(2));
     $parser->parse($file, $access);
     $this->assertEquals(array(new \vc\Data\NSpace('sub\\sub2'), new \vc\Data\NSpace('ns2')), $file->getNamespaces());
     $this->assertEndOfTokens($access);
 }
Пример #8
0
 public function testParseIFace_Constant()
 {
     $access = \vc\Tokens\Access::buildAccess($this->oneTokenReader()->thenAConst->thenAName('CONST')->thenAnEquals->thenAnInteger(123)->thenASemicolon);
     $iface = new \vc\Data\Type\IFace(1);
     $parser = new \vc\Parser\IFace\Members(new \vc\Parser\Constant(new \vc\Parser\Value(new \vc\Parser\Brackets(), new \vc\Parser\Path())), $this->getStub('\\vc\\Parser\\Routine\\Method'));
     $parser->parseMembers($iface, $access);
     $this->assertEquals(1, count($iface->getConstants()));
     $this->assertEndOfTokens($access);
 }
Пример #9
0
 public function testParseAlias_MissingSemicolon()
 {
     $access = \vc\Tokens\Access::buildAccess($this->oneTokenReader()->thenAUse->thenSomeSpace->thenANamespacePath('sub1\\sub2')->thenSomeSpace->then(Token::T_AS, 'as')->thenSomeSpace->thenAName('renamed'));
     $parser = new \vc\Parser\NSpace\Alias(new \vc\Parser\Path());
     try {
         $parser->parseAlias($access);
         $this->fail("An expected exception was not thrown");
     } catch (\vc\Tokens\Exception\UnexpectedEnd $err) {
     }
 }
Пример #10
0
 public function testParseConstant()
 {
     $access = \vc\Tokens\Access::buildAccess($this->oneTokenReader()->thenAConst);
     $constant = new \vc\Data\Constant('CONST');
     $constParser = $this->getStub('\\vc\\Parser\\Constant');
     $constParser->expects($this->once())->method("parseConstant")->with($this->isInstanceOf('\\vc\\Tokens\\Access'))->will($this->returnCallback(function ($access) use($constant) {
         $access->popToken();
         return $constant;
     }));
     $sigParser = $this->getStub('\\vc\\Parser\\Object\\Signature');
     $sigParser->expects($this->never())->method("parseSignature");
     $class = new \vc\Data\Type\Cls(1);
     $parser = new \vc\Parser\Object\Members($constParser, $sigParser);
     $parser->parseMembers($class, $access);
     $this->assertSame(array($constant), $class->getConstants());
     $this->assertEndOfTokens($access);
 }
Пример #11
0
 public function testParseMethod_AbstractPrivateMethod()
 {
     $access = \vc\Tokens\Access::buildAccess($this->oneTokenReader()->thenAnAbstract->thenSomeSpace->thenAPrivate->thenSomeSpace->thenAFunction->thenSomeSpace->thenAName('MyFunc')->thenOpenParens->thenCloseParens->thenAnOpenBlock->thenACloseBlock);
     $sig = new \vc\Data\Signature(123);
     $this->assertEquals(r8(new \vc\Data\Routine\Method(123))->setName('MyFunc')->setAbstract(TRUE)->setVisibility(\vc\Data\Visibility::vPrivate()), $this->getMethodParser()->parseMethod($sig, $access));
 }
Пример #12
0
 public function testParseArgs_Combined()
 {
     $access = \vc\Tokens\Access::buildAccess($this->oneTokenReader()->thenOpenParens->thenANamespacePath('\\path\\to\\class')->thenSomeSpace->thenAnAmpersand->thenSomeSpace->thenAVariable('$test')->thenSomeSpace->thenAnEquals->thenSomeSpace->thenAnInteger(123)->thenAComma->thenAnArray->thenSomeSpace->thenAnAmpersand->thenSomeSpace->thenAVariable('$test2')->thenSomeSpace->thenAnEquals->thenSomeSpace->thenAnArrayValue(array(1))->thenCloseParens);
     $this->assertEquals(array(\r8(new \vc\Data\Arg())->setType('\\path\\to\\class')->setReference(TRUE)->setVariable('$test')->setDefault(new \vc\Data\Value(123, 'int')), \r8(new \vc\Data\Arg())->setType('array')->setReference(TRUE)->setVariable('$test2')->setDefault(new \vc\Data\Value('array( 0 => 1,)', 'array'))), $this->getArgParser()->parseArgs($access));
     $this->assertEndOfTokens($access);
 }
Пример #13
0
 public function testParseValue_ClassConstant()
 {
     $access = \vc\Tokens\Access::buildAccess($this->oneTokenReader()->thenSomeSpace->thenAnEquals->thenSomeSpace->thenANamespacePath('\\path')->then(Token::T_DOUBLE_COLON, '::')->thenAName('CONSTANT'));
     $parser = $this->getValueParser();
     $this->assertEquals(new \vc\Data\Value('\\path::CONSTANT', 'constant'), $parser->parseValue($access));
     $this->assertEndOfTokens($access);
 }
Пример #14
0
 public function testParsePathList_ThreePaths()
 {
     $access = \vc\Tokens\Access::buildAccess($this->oneTokenReader()->thenSomeSpace->thenANamespacePath('path\\to\\cls')->thenAComma->thenSomeSpace->thenANamespacePath('AnObject')->thenAComma->thenSomeSpace->thenANamespacePath('\\stdClass')->thenSomeSpace->thenAnOpenBlock);
     $this->assertEquals(array('path\\to\\cls', 'AnObject', '\\stdClass'), $this->getPathListParser()->parsePathList($access));
 }
Пример #15
0
 public function testParseNSpace_Many()
 {
     $access = \vc\Tokens\Access::buildAccess($this->oneTokenReader()->thenAnInterface->thenAClass->thenAConst->thenAFunction);
     $nspace = new \vc\Data\NSpace(1);
     $this->getNSpaceParser()->parseNSpace($nspace, $access);
     $this->assertEquals(2, count($nspace->getTypes()));
     $this->assertEquals(1, count($nspace->getConstants()));
     $this->assertEquals(1, count($nspace->getFunctions()));
     $this->assertEndOfTokens($access);
 }