comparison vendor/nikic/php-parser/test/PhpParser/Builder/MethodTest.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 MethodTest extends TestCase 12 class MethodTest extends \PHPUnit\Framework\TestCase
14 { 13 {
15 public function createMethodBuilder($name) { 14 public function createMethodBuilder($name) {
16 return new Method($name); 15 return new Method($name);
17 } 16 }
18 17
133 $this->assertEquals(new Stmt\ClassMethod('test', [ 132 $this->assertEquals(new Stmt\ClassMethod('test', [
134 'returnType' => 'bool' 133 'returnType' => 'bool'
135 ], []), $node); 134 ], []), $node);
136 } 135 }
137 136
138 /**
139 * @expectedException \LogicException
140 * @expectedExceptionMessage Cannot add statements to an abstract method
141 */
142 public function testAddStmtToAbstractMethodError() { 137 public function testAddStmtToAbstractMethodError() {
138 $this->expectException(\LogicException::class);
139 $this->expectExceptionMessage('Cannot add statements to an abstract method');
143 $this->createMethodBuilder('test') 140 $this->createMethodBuilder('test')
144 ->makeAbstract() 141 ->makeAbstract()
145 ->addStmt(new Print_(new String_('test'))) 142 ->addStmt(new Print_(new String_('test')))
146 ; 143 ;
147 } 144 }
148 145
149 /**
150 * @expectedException \LogicException
151 * @expectedExceptionMessage Cannot make method with statements abstract
152 */
153 public function testMakeMethodWithStmtsAbstractError() { 146 public function testMakeMethodWithStmtsAbstractError() {
147 $this->expectException(\LogicException::class);
148 $this->expectExceptionMessage('Cannot make method with statements abstract');
154 $this->createMethodBuilder('test') 149 $this->createMethodBuilder('test')
155 ->addStmt(new Print_(new String_('test'))) 150 ->addStmt(new Print_(new String_('test')))
156 ->makeAbstract() 151 ->makeAbstract()
157 ; 152 ;
158 } 153 }
159 154
160 /**
161 * @expectedException \LogicException
162 * @expectedExceptionMessage Expected parameter node, got "Name"
163 */
164 public function testInvalidParamError() { 155 public function testInvalidParamError() {
156 $this->expectException(\LogicException::class);
157 $this->expectExceptionMessage('Expected parameter node, got "Name"');
165 $this->createMethodBuilder('test') 158 $this->createMethodBuilder('test')
166 ->addParam(new Node\Name('foo')) 159 ->addParam(new Node\Name('foo'))
167 ; 160 ;
168 } 161 }
169 } 162 }