comparison vendor/nikic/php-parser/test/PhpParser/Builder/FunctionTest.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 5fb285c0d0e3
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
6 use PhpParser\Node; 6 use PhpParser\Node;
7 use PhpParser\Node\Expr\Print_; 7 use PhpParser\Node\Expr\Print_;
8 use PhpParser\Node\Expr\Variable; 8 use PhpParser\Node\Expr\Variable;
9 use PhpParser\Node\Scalar\String_; 9 use PhpParser\Node\Scalar\String_;
10 use PhpParser\Node\Stmt; 10 use PhpParser\Node\Stmt;
11 use PHPUnit\Framework\TestCase;
12 11
13 class FunctionTest extends TestCase 12 class FunctionTest extends \PHPUnit\Framework\TestCase
14 { 13 {
15 public function createFunctionBuilder($name) { 14 public function createFunctionBuilder($name) {
16 return new Function_($name); 15 return new Function_($name);
17 } 16 }
18 17
90 $this->assertEquals(new Stmt\Function_('test', [ 89 $this->assertEquals(new Stmt\Function_('test', [
91 'returnType' => 'void' 90 'returnType' => 'void'
92 ], []), $node); 91 ], []), $node);
93 } 92 }
94 93
95 /**
96 * @expectedException \LogicException
97 * @expectedExceptionMessage void type cannot be nullable
98 */
99 public function testInvalidNullableVoidType() { 94 public function testInvalidNullableVoidType() {
95 $this->expectException(\LogicException::class);
96 $this->expectExceptionMessage('void type cannot be nullable');
100 $this->createFunctionBuilder('test')->setReturnType('?void'); 97 $this->createFunctionBuilder('test')->setReturnType('?void');
101 } 98 }
102 99
103 /**
104 * @expectedException \LogicException
105 * @expectedExceptionMessage Expected parameter node, got "Name"
106 */
107 public function testInvalidParamError() { 100 public function testInvalidParamError() {
101 $this->expectException(\LogicException::class);
102 $this->expectExceptionMessage('Expected parameter node, got "Name"');
108 $this->createFunctionBuilder('test') 103 $this->createFunctionBuilder('test')
109 ->addParam(new Node\Name('foo')) 104 ->addParam(new Node\Name('foo'))
110 ; 105 ;
111 } 106 }
112 107
113 /**
114 * @expectedException \LogicException
115 * @expectedExceptionMessage Expected statement or expression node
116 */
117 public function testAddNonStmt() { 108 public function testAddNonStmt() {
109 $this->expectException(\LogicException::class);
110 $this->expectExceptionMessage('Expected statement or expression node');
118 $this->createFunctionBuilder('test') 111 $this->createFunctionBuilder('test')
119 ->addStmt(new Node\Name('Test')); 112 ->addStmt(new Node\Name('Test'));
120 } 113 }
121 } 114 }