Skip to content

Commit 9484baf

Browse files
committed
Make compatible with PhpUnit 8
1 parent aad0e28 commit 9484baf

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"ext-tokenizer": "*"
1818
},
1919
"require-dev": {
20-
"phpunit/phpunit": "^6.5 || ^7.0"
20+
"phpunit/phpunit": "^6.5 || ^7.0 || ^8.0"
2121
},
2222
"extra": {
2323
"branch-alias": {

test/PhpParser/Builder/InterfaceTest.php

+11-13
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@
99

1010
class InterfaceTest extends \PHPUnit\Framework\TestCase
1111
{
12-
/** @var Interface_ */
13-
protected $builder;
14-
15-
protected function setUp() {
16-
$this->builder = new Interface_('Contract');
12+
protected function createInterfaceBuilder() {
13+
return new Interface_('Contract');
1714
}
1815

1916
private function dump($node) {
@@ -22,13 +19,14 @@ private function dump($node) {
2219
}
2320

2421
public function testEmpty() {
25-
$contract = $this->builder->getNode();
22+
$contract = $this->createInterfaceBuilder()->getNode();
2623
$this->assertInstanceOf(Stmt\Interface_::class, $contract);
2724
$this->assertEquals(new Node\Identifier('Contract'), $contract->name);
2825
}
2926

3027
public function testExtending() {
31-
$contract = $this->builder->extend('Space\Root1', 'Root2')->getNode();
28+
$contract = $this->createInterfaceBuilder()
29+
->extend('Space\Root1', 'Root2')->getNode();
3230
$this->assertEquals(
3331
new Stmt\Interface_('Contract', [
3432
'extends' => [
@@ -41,15 +39,15 @@ public function testExtending() {
4139

4240
public function testAddMethod() {
4341
$method = new Stmt\ClassMethod('doSomething');
44-
$contract = $this->builder->addStmt($method)->getNode();
42+
$contract = $this->createInterfaceBuilder()->addStmt($method)->getNode();
4543
$this->assertSame([$method], $contract->stmts);
4644
}
4745

4846
public function testAddConst() {
4947
$const = new Stmt\ClassConst([
5048
new Node\Const_('SPEED_OF_LIGHT', new DNumber(299792458.0))
5149
]);
52-
$contract = $this->builder->addStmt($const)->getNode();
50+
$contract = $this->createInterfaceBuilder()->addStmt($const)->getNode();
5351
$this->assertSame(299792458.0, $contract->stmts[0]->consts[0]->value->value);
5452
}
5553

@@ -58,7 +56,7 @@ public function testOrder() {
5856
new Node\Const_('SPEED_OF_LIGHT', new DNumber(299792458))
5957
]);
6058
$method = new Stmt\ClassMethod('doSomething');
61-
$contract = $this->builder
59+
$contract = $this->createInterfaceBuilder()
6260
->addStmt($method)
6361
->addStmt($const)
6462
->getNode()
@@ -69,7 +67,7 @@ public function testOrder() {
6967
}
7068

7169
public function testDocComment() {
72-
$node = $this->builder
70+
$node = $this->createInterfaceBuilder()
7371
->setDocComment('/** Test */')
7472
->getNode();
7573

@@ -81,15 +79,15 @@ public function testDocComment() {
8179
public function testInvalidStmtError() {
8280
$this->expectException(\LogicException::class);
8381
$this->expectExceptionMessage('Unexpected node of type "Stmt_PropertyProperty"');
84-
$this->builder->addStmt(new Stmt\PropertyProperty('invalid'));
82+
$this->createInterfaceBuilder()->addStmt(new Stmt\PropertyProperty('invalid'));
8583
}
8684

8785
public function testFullFunctional() {
8886
$const = new Stmt\ClassConst([
8987
new Node\Const_('SPEED_OF_LIGHT', new DNumber(299792458))
9088
]);
9189
$method = new Stmt\ClassMethod('doSomething');
92-
$contract = $this->builder
90+
$contract = $this->createInterfaceBuilder()
9391
->addStmt($method)
9492
->addStmt($const)
9593
->getNode()

test/PhpParser/NodeTraverserTest.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,17 @@ public function testRemovingVisitor() {
266266
$traverser->addVisitor($visitor2);
267267
$traverser->addVisitor($visitor3);
268268

269+
$getVisitors = (function () {
270+
return $this->visitors;
271+
})->bindTo($traverser, NodeTraverser::class);
272+
269273
$preExpected = [$visitor1, $visitor2, $visitor3];
270-
$this->assertAttributeSame($preExpected, 'visitors', $traverser, 'The appropriate visitors have not been added');
274+
$this->assertSame($preExpected, $getVisitors());
271275

272276
$traverser->removeVisitor($visitor2);
273277

274278
$postExpected = [0 => $visitor1, 2 => $visitor3];
275-
$this->assertAttributeSame($postExpected, 'visitors', $traverser, 'The appropriate visitors are not present after removal');
279+
$this->assertSame($postExpected, $getVisitors());
276280
}
277281

278282
public function testNoCloneNodes() {

0 commit comments

Comments
 (0)