annotate vendor/nikic/php-parser/test/PhpParser/Builder/PropertyTest.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
rev   line source
Chris@13 1 <?php declare(strict_types=1);
Chris@0 2
Chris@0 3 namespace PhpParser\Builder;
Chris@0 4
Chris@0 5 use PhpParser\Comment;
Chris@0 6 use PhpParser\Node\Expr;
Chris@0 7 use PhpParser\Node\Name;
Chris@0 8 use PhpParser\Node\Scalar;
Chris@0 9 use PhpParser\Node\Stmt;
Chris@13 10 use PHPUnit\Framework\TestCase;
Chris@0 11
Chris@13 12 class PropertyTest extends TestCase
Chris@0 13 {
Chris@0 14 public function createPropertyBuilder($name) {
Chris@0 15 return new Property($name);
Chris@0 16 }
Chris@0 17
Chris@0 18 public function testModifiers() {
Chris@0 19 $node = $this->createPropertyBuilder('test')
Chris@0 20 ->makePrivate()
Chris@0 21 ->makeStatic()
Chris@0 22 ->getNode()
Chris@0 23 ;
Chris@0 24
Chris@0 25 $this->assertEquals(
Chris@0 26 new Stmt\Property(
Chris@0 27 Stmt\Class_::MODIFIER_PRIVATE
Chris@0 28 | Stmt\Class_::MODIFIER_STATIC,
Chris@13 29 [
Chris@0 30 new Stmt\PropertyProperty('test')
Chris@13 31 ]
Chris@0 32 ),
Chris@0 33 $node
Chris@0 34 );
Chris@0 35
Chris@0 36 $node = $this->createPropertyBuilder('test')
Chris@0 37 ->makeProtected()
Chris@0 38 ->getNode()
Chris@0 39 ;
Chris@0 40
Chris@0 41 $this->assertEquals(
Chris@0 42 new Stmt\Property(
Chris@0 43 Stmt\Class_::MODIFIER_PROTECTED,
Chris@13 44 [
Chris@0 45 new Stmt\PropertyProperty('test')
Chris@13 46 ]
Chris@0 47 ),
Chris@0 48 $node
Chris@0 49 );
Chris@0 50
Chris@0 51 $node = $this->createPropertyBuilder('test')
Chris@0 52 ->makePublic()
Chris@0 53 ->getNode()
Chris@0 54 ;
Chris@0 55
Chris@0 56 $this->assertEquals(
Chris@0 57 new Stmt\Property(
Chris@0 58 Stmt\Class_::MODIFIER_PUBLIC,
Chris@13 59 [
Chris@0 60 new Stmt\PropertyProperty('test')
Chris@13 61 ]
Chris@0 62 ),
Chris@0 63 $node
Chris@0 64 );
Chris@0 65 }
Chris@0 66
Chris@0 67 public function testDocComment() {
Chris@0 68 $node = $this->createPropertyBuilder('test')
Chris@0 69 ->setDocComment('/** Test */')
Chris@0 70 ->getNode();
Chris@0 71
Chris@0 72 $this->assertEquals(new Stmt\Property(
Chris@0 73 Stmt\Class_::MODIFIER_PUBLIC,
Chris@13 74 [
Chris@0 75 new Stmt\PropertyProperty('test')
Chris@13 76 ],
Chris@13 77 [
Chris@13 78 'comments' => [new Comment\Doc('/** Test */')]
Chris@13 79 ]
Chris@0 80 ), $node);
Chris@0 81 }
Chris@0 82
Chris@0 83 /**
Chris@0 84 * @dataProvider provideTestDefaultValues
Chris@0 85 */
Chris@0 86 public function testDefaultValues($value, $expectedValueNode) {
Chris@0 87 $node = $this->createPropertyBuilder('test')
Chris@0 88 ->setDefault($value)
Chris@0 89 ->getNode()
Chris@0 90 ;
Chris@0 91
Chris@0 92 $this->assertEquals($expectedValueNode, $node->props[0]->default);
Chris@0 93 }
Chris@0 94
Chris@0 95 public function provideTestDefaultValues() {
Chris@13 96 return [
Chris@13 97 [
Chris@0 98 null,
Chris@0 99 new Expr\ConstFetch(new Name('null'))
Chris@13 100 ],
Chris@13 101 [
Chris@0 102 true,
Chris@0 103 new Expr\ConstFetch(new Name('true'))
Chris@13 104 ],
Chris@13 105 [
Chris@0 106 false,
Chris@0 107 new Expr\ConstFetch(new Name('false'))
Chris@13 108 ],
Chris@13 109 [
Chris@0 110 31415,
Chris@0 111 new Scalar\LNumber(31415)
Chris@13 112 ],
Chris@13 113 [
Chris@0 114 3.1415,
Chris@0 115 new Scalar\DNumber(3.1415)
Chris@13 116 ],
Chris@13 117 [
Chris@0 118 'Hallo World',
Chris@0 119 new Scalar\String_('Hallo World')
Chris@13 120 ],
Chris@13 121 [
Chris@13 122 [1, 2, 3],
Chris@13 123 new Expr\Array_([
Chris@0 124 new Expr\ArrayItem(new Scalar\LNumber(1)),
Chris@0 125 new Expr\ArrayItem(new Scalar\LNumber(2)),
Chris@0 126 new Expr\ArrayItem(new Scalar\LNumber(3)),
Chris@13 127 ])
Chris@13 128 ],
Chris@13 129 [
Chris@13 130 ['foo' => 'bar', 'bar' => 'foo'],
Chris@13 131 new Expr\Array_([
Chris@0 132 new Expr\ArrayItem(
Chris@0 133 new Scalar\String_('bar'),
Chris@0 134 new Scalar\String_('foo')
Chris@0 135 ),
Chris@0 136 new Expr\ArrayItem(
Chris@0 137 new Scalar\String_('foo'),
Chris@0 138 new Scalar\String_('bar')
Chris@0 139 ),
Chris@13 140 ])
Chris@13 141 ],
Chris@13 142 [
Chris@0 143 new Scalar\MagicConst\Dir,
Chris@0 144 new Scalar\MagicConst\Dir
Chris@13 145 ]
Chris@13 146 ];
Chris@0 147 }
Chris@0 148 }