Skip to content

Commit

Permalink
Remove last uses of MockBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Aug 8, 2020
1 parent 1bf073a commit f6bf041
Showing 1 changed file with 36 additions and 41 deletions.
77 changes: 36 additions & 41 deletions test/PhpParser/NodeTraverserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,59 +306,54 @@ public function testNoCloneNodes() {
/**
* @dataProvider provideTestInvalidReturn
*/
public function testInvalidReturn($visitor, $message) {
public function testInvalidReturn($stmts, $visitor, $message) {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage($message);

$stmts = [new Node\Stmt\Expression(new Node\Scalar\LNumber(42))];

$traverser = new NodeTraverser();
$traverser->addVisitor($visitor);
$traverser->traverse($stmts);
}

public function provideTestInvalidReturn() {
$visitor1 = $this->getMockBuilder(NodeVisitor::class)->getMock();
$visitor1->expects($this->at(1))->method('enterNode')
->willReturn('foobar');

$visitor2 = $this->getMockBuilder(NodeVisitor::class)->getMock();
$visitor2->expects($this->at(2))->method('enterNode')
->willReturn('foobar');

$visitor3 = $this->getMockBuilder(NodeVisitor::class)->getMock();
$visitor3->expects($this->at(3))->method('leaveNode')
->willReturn('foobar');

$visitor4 = $this->getMockBuilder(NodeVisitor::class)->getMock();
$visitor4->expects($this->at(4))->method('leaveNode')
->willReturn('foobar');

$visitor5 = $this->getMockBuilder(NodeVisitor::class)->getMock();
$visitor5->expects($this->at(3))->method('leaveNode')
->willReturn([new Node\Scalar\DNumber(42.0)]);
$num = new Node\Scalar\LNumber(42);
$expr = new Node\Stmt\Expression($num);
$stmts = [$expr];

$visitor6 = $this->getMockBuilder(NodeVisitor::class)->getMock();
$visitor6->expects($this->at(4))->method('leaveNode')
->willReturn(false);

$visitor7 = $this->getMockBuilder(NodeVisitor::class)->getMock();
$visitor7->expects($this->at(1))->method('enterNode')
->willReturn(new Node\Scalar\LNumber(42));

$visitor8 = $this->getMockBuilder(NodeVisitor::class)->getMock();
$visitor8->expects($this->at(2))->method('enterNode')
->willReturn(new Node\Stmt\Return_());
$visitor1 = new NodeVisitorForTesting([
['enterNode', $expr, 'foobar'],
]);
$visitor2 = new NodeVisitorForTesting([
['enterNode', $num, 'foobar'],
]);
$visitor3 = new NodeVisitorForTesting([
['leaveNode', $num, 'foobar'],
]);
$visitor4 = new NodeVisitorForTesting([
['leaveNode', $expr, 'foobar'],
]);
$visitor5 = new NodeVisitorForTesting([
['leaveNode', $num, [new Node\Scalar\DNumber(42.0)]],
]);
$visitor6 = new NodeVisitorForTesting([
['leaveNode', $expr, false],
]);
$visitor7 = new NodeVisitorForTesting([
['enterNode', $expr, new Node\Scalar\LNumber(42)],
]);
$visitor8 = new NodeVisitorForTesting([
['enterNode', $num, new Node\Stmt\Return_()],
]);

return [
[$visitor1, 'enterNode() returned invalid value of type string'],
[$visitor2, 'enterNode() returned invalid value of type string'],
[$visitor3, 'leaveNode() returned invalid value of type string'],
[$visitor4, 'leaveNode() returned invalid value of type string'],
[$visitor5, 'leaveNode() may only return an array if the parent structure is an array'],
[$visitor6, 'bool(false) return from leaveNode() no longer supported. Return NodeTraverser::REMOVE_NODE instead'],
[$visitor7, 'Trying to replace statement (Stmt_Expression) with expression (Scalar_LNumber). Are you missing a Stmt_Expression wrapper?'],
[$visitor8, 'Trying to replace expression (Scalar_LNumber) with statement (Stmt_Return)'],
[$stmts, $visitor1, 'enterNode() returned invalid value of type string'],
[$stmts, $visitor2, 'enterNode() returned invalid value of type string'],
[$stmts, $visitor3, 'leaveNode() returned invalid value of type string'],
[$stmts, $visitor4, 'leaveNode() returned invalid value of type string'],
[$stmts, $visitor5, 'leaveNode() may only return an array if the parent structure is an array'],
[$stmts, $visitor6, 'bool(false) return from leaveNode() no longer supported. Return NodeTraverser::REMOVE_NODE instead'],
[$stmts, $visitor7, 'Trying to replace statement (Stmt_Expression) with expression (Scalar_LNumber). Are you missing a Stmt_Expression wrapper?'],
[$stmts, $visitor8, 'Trying to replace expression (Scalar_LNumber) with statement (Stmt_Return)'],
];
}
}

0 comments on commit f6bf041

Please sign in to comment.