Skip to content

Commit 1721ae1

Browse files
committed
Avoid one use of MockBuilder
We can just use anon classes here and avoid PHPUnits unreliable MockBuilder.
1 parent 54fc023 commit 1721ae1

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

test/PhpParser/Parser/MultipleTest.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
namespace PhpParser\Parser;
44

55
use PhpParser\Error;
6+
use PhpParser\ErrorHandler;
67
use PhpParser\Lexer;
78
use PhpParser\Node\Expr;
89
use PhpParser\Node\Scalar\LNumber;
910
use PhpParser\Node\Stmt;
11+
use PhpParser\ParserAbstract;
1012
use PhpParser\ParserTest;
1113

1214
class MultipleTest extends ParserTest
@@ -80,11 +82,16 @@ public function testThrownError() {
8082
$this->expectException(Error::class);
8183
$this->expectExceptionMessage('FAIL A');
8284

83-
$parserA = $this->getMockBuilder(\PhpParser\Parser::class)->getMock();
84-
$parserA->method('parse')->willThrowException(new Error('FAIL A'));
85-
86-
$parserB = $this->getMockBuilder(\PhpParser\Parser::class)->getMock();
87-
$parserB->method('parse')->willThrowException(new Error('FAIL B'));
85+
$parserA = new class implements \PhpParser\Parser {
86+
public function parse(string $code, ErrorHandler $errorHandler = null) {
87+
throw new Error('FAIL A');
88+
}
89+
};
90+
$parserB = new class implements \PhpParser\Parser {
91+
public function parse(string $code, ErrorHandler $errorHandler = null) {
92+
throw new Error('FAIL B');
93+
}
94+
};
8895

8996
$parser = new Multiple([$parserA, $parserB]);
9097
$parser->parse('dummy');

0 commit comments

Comments
 (0)