/** * @expectedException \InvalidArgumentException */ public function testInvalidCommentAbove() { $original = '$value = variable_get("my_variable", NULL);'; /** @var StatementNode $statement_node */ $statement_node = Parser::parseSnippet($original); $statement_node->addCommentAbove(NULL); }
public function testCatches() { /** @var \Pharborist\Exceptions\TryCatchNode $tryCatch */ $tryCatch = Parser::parseSnippet('try { foo(); } catch (\\InvalidArgumentException $e) {}'); $this->assertTrue($tryCatch->catches('\\InvalidArgumentException')); $this->assertFalse($tryCatch->catches('\\DomainException')); }
protected function formatSnippet($snippet) { /** @var ParentNode $node */ $node = Parser::parseSnippet($snippet); $this->formatter->format($node); return $node->getText(); }
protected function formatSnippet($snippet) { /** @var ParentNode $node */ $node = Parser::parseSnippet($snippet); $formatter = FormatterFactory::getDrupalFormatter(); $formatter->format($node); return $node->getText(); }
public function testGetPreviousCall() { $call = Parser::parseSnippet('\\Drupal::database()->insert("razmatazz");')->firstChild(); $this->assertInstanceOf('\\Pharborist\\Objects\\ObjectMethodCallNode', $call); $this->assertInstanceOf('\\Pharborist\\Objects\\ClassMethodCallNode', $call->getPreviousCall()); $call = Parser::parseSnippet('$raz->matazz();')->firstChild(); $this->assertInstanceOf('\\Pharborist\\Objects\\ObjectMethodCallNode', $call); $this->assertNull($call->getPreviousCall()); }
public function testSetName() { /** @var \Pharborist\Objects\ClassNode $class */ $class = Parser::parseSnippet('class Foo { public function baz() {} }'); /** @var \Pharborist\Objects\ClassMethodNode $method */ $method = $class->getMethod('baz'); $method->setName('bar'); $this->assertEquals('bar', $method->getName()->getText()); $this->assertEquals('public function bar() {}', $method->getText()); }
public function testAppendStatement() { /** @var \Pharborist\ControlStructures\IfNode $ifNode */ $ifNode = Parser::parseSnippet('if (TRUE) { hello(); }'); /** @var StatementBlockNode $statementBlock */ $statementBlock = $ifNode->getThen(); $this->assertInstanceOf('\\Pharborist\\StatementBlockNode', $statementBlock); $this->assertEquals('{ hello(); }', $statementBlock->getText()); $statementBlock->appendStatement(Parser::parseSnippet('world();')); $this->assertEquals('{ hello(); world();}', $statementBlock->getText()); }
public function testGetConstants() { /** @var \Pharborist\Objects\InterfaceNode $interface */ $interface = Parser::parseSnippet('interface Foo { const ANSWER = 42; }'); $constants = $interface->getConstants(); $this->assertCount(1, $constants); /** @var \Pharborist\Constants\ConstantDeclarationNode $constant */ $constant = $constants[0]; $this->assertInstanceOf('\\Pharborist\\Constants\\ConstantDeclarationNode', $constant); $this->assertEquals('ANSWER', $constant->getName()); $this->assertEquals('42', $constant->getValue()->getText()); }
/** * @expectedException \InvalidArgumentException */ public function testInvalid() { $snippet = <<<'EOF' namespace Test { function hello_world() { echo 'hello world!', PHP_EOL; } } EOF; /** @var \Pharborist\Namespaces\NamespaceNode $namespace_node */ $namespace_node = Parser::parseSnippet($snippet); /** @var \Pharborist\Functions\FunctionDeclarationNode $function */ $function = $namespace_node->getBody()->children(Filter::isFunction('hello_world'))[0]; $this->assertTrue($function->inNamespace(new \stdClass())); }
/** * Uncomments the contents of this comment. * * @return Node */ public function uncomment() { /** @var CommentNode|LineCommentBlockNode $this */ return Parser::parseSnippet($this->getCommentText()); }
public function testSetImplementsStringArray() { /** @var \Pharborist\Objects\ClassNode $class */ $class = Parser::parseSnippet('class Foo {}'); $class->setImplements(['\\IteratorAggregate', '\\ArrayAccess']); $implements = $class->getImplementList(); $this->assertInstanceOf('\\Pharborist\\CommaListNode', $implements); $items = $implements->getItems(); $this->assertCount(2, $items); $this->assertEquals('\\IteratorAggregate, \\ArrayAccess', $implements->getText()); }