Mercurial > hg > isophonics-drupal-site
diff vendor/nikic/php-parser/test/PhpParser/NodeAbstractTest.php @ 13:5fb285c0d0e3
Update Drupal core to 8.4.7 via Composer. Security update; I *think* we've
been lucky to get away with this so far, as we don't support self-registration
which seems to be used by the so-called "drupalgeddon 2" attack that 8.4.5
was vulnerable to.
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:33:26 +0100 |
parents | 4c8ae668cc8c |
children | 129ea1e6d783 |
line wrap: on
line diff
--- a/vendor/nikic/php-parser/test/PhpParser/NodeAbstractTest.php Fri Feb 23 15:52:07 2018 +0000 +++ b/vendor/nikic/php-parser/test/PhpParser/NodeAbstractTest.php Mon Apr 23 09:33:26 2018 +0100 @@ -1,8 +1,11 @@ -<?php +<?php declare(strict_types=1); namespace PhpParser; -class DummyNode extends NodeAbstract { +use PHPUnit\Framework\TestCase; + +class DummyNode extends NodeAbstract +{ public $subNode1; public $subNode2; @@ -12,33 +15,38 @@ $this->subNode2 = $subNode2; } - public function getSubNodeNames() { - return array('subNode1', 'subNode2'); + public function getSubNodeNames() : array { + return ['subNode1', 'subNode2']; } // This method is only overwritten because the node is located in an unusual namespace - public function getType() { + public function getType() : string { return 'Dummy'; } } -class NodeAbstractTest extends \PHPUnit_Framework_TestCase +class NodeAbstractTest extends TestCase { public function provideNodes() { - $attributes = array( + $attributes = [ 'startLine' => 10, - 'comments' => array( + 'endLine' => 11, + 'startTokenPos' => 12, + 'endTokenPos' => 13, + 'startFilePos' => 14, + 'endFilePos' => 15, + 'comments' => [ new Comment('// Comment' . "\n"), new Comment\Doc('/** doc comment */'), - ), - ); + ], + ]; $node = new DummyNode('value1', 'value2', $attributes); $node->notSubNode = 'value3'; - return array( - array($attributes, $node), - ); + return [ + [$attributes, $node], + ]; } /** @@ -46,15 +54,22 @@ */ public function testConstruct(array $attributes, Node $node) { $this->assertSame('Dummy', $node->getType()); - $this->assertSame(array('subNode1', 'subNode2'), $node->getSubNodeNames()); + $this->assertSame(['subNode1', 'subNode2'], $node->getSubNodeNames()); $this->assertSame(10, $node->getLine()); + $this->assertSame(10, $node->getStartLine()); + $this->assertSame(11, $node->getEndLine()); + $this->assertSame(12, $node->getStartTokenPos()); + $this->assertSame(13, $node->getEndTokenPos()); + $this->assertSame(14, $node->getStartFilePos()); + $this->assertSame(15, $node->getEndFilePos()); $this->assertSame('/** doc comment */', $node->getDocComment()->getText()); $this->assertSame('value1', $node->subNode1); $this->assertSame('value2', $node->subNode2); - $this->assertTrue(isset($node->subNode1)); - $this->assertTrue(isset($node->subNode2)); - $this->assertFalse(isset($node->subNode3)); + $this->assertObjectHasAttribute('subNode1', $node); + $this->assertObjectHasAttribute('subNode2', $node); + $this->assertObjectNotHasAttribute('subNode3', $node); $this->assertSame($attributes, $node->getAttributes()); + $this->assertSame($attributes['comments'], $node->getComments()); return $node; } @@ -64,9 +79,14 @@ */ public function testGetDocComment(array $attributes, Node $node) { $this->assertSame('/** doc comment */', $node->getDocComment()->getText()); - array_pop($node->getAttribute('comments')); // remove doc comment + $comments = $node->getComments(); + + array_pop($comments); // remove doc comment + $node->setAttribute('comments', $comments); $this->assertNull($node->getDocComment()); - array_pop($node->getAttribute('comments')); // remove comment + + array_pop($comments); // remove comment + $node->setAttribute('comments', $comments); $this->assertNull($node->getDocComment()); } @@ -96,10 +116,6 @@ * @dataProvider provideNodes */ public function testChange(array $attributes, Node $node) { - // change of line - $node->setLine(15); - $this->assertSame(15, $node->getLine()); - // direct modification $node->subNode = 'newValue'; $this->assertSame('newValue', $node->subNode); @@ -111,7 +127,7 @@ // removal unset($node->subNode); - $this->assertFalse(isset($node->subNode)); + $this->assertObjectNotHasAttribute('subNode', $node); } /** @@ -125,10 +141,10 @@ if ($i === 0) { $this->assertSame('subNode1', $key); $this->assertSame('value1', $value); - } else if ($i === 1) { + } elseif ($i === 1) { $this->assertSame('subNode2', $key); $this->assertSame('value2', $value); - } else if ($i === 2) { + } elseif ($i === 2) { $this->assertSame('notSubNode', $key); $this->assertSame('value3', $value); } else { @@ -141,7 +157,7 @@ public function testAttributes() { /** @var $node Node */ - $node = $this->getMockForAbstractClass('PhpParser\NodeAbstract'); + $node = $this->getMockForAbstractClass(NodeAbstract::class); $this->assertEmpty($node->getAttributes()); @@ -159,10 +175,24 @@ $this->assertNull($node->getAttribute('null', 'default')); $this->assertSame( - array( + [ 'key' => 'value', 'null' => null, - ), + ], + $node->getAttributes() + ); + + $node->setAttributes( + [ + 'a' => 'b', + 'c' => null, + ] + ); + $this->assertSame( + [ + 'a' => 'b', + 'c' => null, + ], $node->getAttributes() ); } @@ -181,14 +211,28 @@ { "nodeType": "Stmt_Function", "byRef": false, - "name": "functionName", + "name": { + "nodeType": "Identifier", + "name": "functionName", + "attributes": { + "startLine": 4, + "endLine": 4 + } + }, "params": [ { "nodeType": "Param", "type": null, "byRef": true, "variadic": false, - "name": "a", + "var": { + "nodeType": "Expr_Variable", + "name": "a", + "attributes": { + "startLine": 4, + "endLine": 4 + } + }, "default": { "nodeType": "Scalar_LNumber", "value": 0, @@ -208,7 +252,14 @@ "type": null, "byRef": false, "variadic": false, - "name": "b", + "var": { + "nodeType": "Expr_Variable", + "name": "b", + "attributes": { + "startLine": 4, + "endLine": 4 + } + }, "default": { "nodeType": "Scalar_DNumber", "value": 1, @@ -251,13 +302,15 @@ "nodeType": "Comment", "text": "\/\/ comment\n", "line": 2, - "filePos": 6 + "filePos": 6, + "tokenPos": 1 }, { "nodeType": "Comment_Doc", "text": "\/** doc comment *\/", "line": 3, - "filePos": 17 + "filePos": 17, + "tokenPos": 2 } ], "endLine": 6