Skip to content

Commit f6bf041

Browse files
committed
Remove last uses of MockBuilder
1 parent 1bf073a commit f6bf041

File tree

1 file changed

+36
-41
lines changed

1 file changed

+36
-41
lines changed

test/PhpParser/NodeTraverserTest.php

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -306,59 +306,54 @@ public function testNoCloneNodes() {
306306
/**
307307
* @dataProvider provideTestInvalidReturn
308308
*/
309-
public function testInvalidReturn($visitor, $message) {
309+
public function testInvalidReturn($stmts, $visitor, $message) {
310310
$this->expectException(\LogicException::class);
311311
$this->expectExceptionMessage($message);
312312

313-
$stmts = [new Node\Stmt\Expression(new Node\Scalar\LNumber(42))];
314-
315313
$traverser = new NodeTraverser();
316314
$traverser->addVisitor($visitor);
317315
$traverser->traverse($stmts);
318316
}
319317

320318
public function provideTestInvalidReturn() {
321-
$visitor1 = $this->getMockBuilder(NodeVisitor::class)->getMock();
322-
$visitor1->expects($this->at(1))->method('enterNode')
323-
->willReturn('foobar');
324-
325-
$visitor2 = $this->getMockBuilder(NodeVisitor::class)->getMock();
326-
$visitor2->expects($this->at(2))->method('enterNode')
327-
->willReturn('foobar');
328-
329-
$visitor3 = $this->getMockBuilder(NodeVisitor::class)->getMock();
330-
$visitor3->expects($this->at(3))->method('leaveNode')
331-
->willReturn('foobar');
332-
333-
$visitor4 = $this->getMockBuilder(NodeVisitor::class)->getMock();
334-
$visitor4->expects($this->at(4))->method('leaveNode')
335-
->willReturn('foobar');
336-
337-
$visitor5 = $this->getMockBuilder(NodeVisitor::class)->getMock();
338-
$visitor5->expects($this->at(3))->method('leaveNode')
339-
->willReturn([new Node\Scalar\DNumber(42.0)]);
319+
$num = new Node\Scalar\LNumber(42);
320+
$expr = new Node\Stmt\Expression($num);
321+
$stmts = [$expr];
340322

341-
$visitor6 = $this->getMockBuilder(NodeVisitor::class)->getMock();
342-
$visitor6->expects($this->at(4))->method('leaveNode')
343-
->willReturn(false);
344-
345-
$visitor7 = $this->getMockBuilder(NodeVisitor::class)->getMock();
346-
$visitor7->expects($this->at(1))->method('enterNode')
347-
->willReturn(new Node\Scalar\LNumber(42));
348-
349-
$visitor8 = $this->getMockBuilder(NodeVisitor::class)->getMock();
350-
$visitor8->expects($this->at(2))->method('enterNode')
351-
->willReturn(new Node\Stmt\Return_());
323+
$visitor1 = new NodeVisitorForTesting([
324+
['enterNode', $expr, 'foobar'],
325+
]);
326+
$visitor2 = new NodeVisitorForTesting([
327+
['enterNode', $num, 'foobar'],
328+
]);
329+
$visitor3 = new NodeVisitorForTesting([
330+
['leaveNode', $num, 'foobar'],
331+
]);
332+
$visitor4 = new NodeVisitorForTesting([
333+
['leaveNode', $expr, 'foobar'],
334+
]);
335+
$visitor5 = new NodeVisitorForTesting([
336+
['leaveNode', $num, [new Node\Scalar\DNumber(42.0)]],
337+
]);
338+
$visitor6 = new NodeVisitorForTesting([
339+
['leaveNode', $expr, false],
340+
]);
341+
$visitor7 = new NodeVisitorForTesting([
342+
['enterNode', $expr, new Node\Scalar\LNumber(42)],
343+
]);
344+
$visitor8 = new NodeVisitorForTesting([
345+
['enterNode', $num, new Node\Stmt\Return_()],
346+
]);
352347

353348
return [
354-
[$visitor1, 'enterNode() returned invalid value of type string'],
355-
[$visitor2, 'enterNode() returned invalid value of type string'],
356-
[$visitor3, 'leaveNode() returned invalid value of type string'],
357-
[$visitor4, 'leaveNode() returned invalid value of type string'],
358-
[$visitor5, 'leaveNode() may only return an array if the parent structure is an array'],
359-
[$visitor6, 'bool(false) return from leaveNode() no longer supported. Return NodeTraverser::REMOVE_NODE instead'],
360-
[$visitor7, 'Trying to replace statement (Stmt_Expression) with expression (Scalar_LNumber). Are you missing a Stmt_Expression wrapper?'],
361-
[$visitor8, 'Trying to replace expression (Scalar_LNumber) with statement (Stmt_Return)'],
349+
[$stmts, $visitor1, 'enterNode() returned invalid value of type string'],
350+
[$stmts, $visitor2, 'enterNode() returned invalid value of type string'],
351+
[$stmts, $visitor3, 'leaveNode() returned invalid value of type string'],
352+
[$stmts, $visitor4, 'leaveNode() returned invalid value of type string'],
353+
[$stmts, $visitor5, 'leaveNode() may only return an array if the parent structure is an array'],
354+
[$stmts, $visitor6, 'bool(false) return from leaveNode() no longer supported. Return NodeTraverser::REMOVE_NODE instead'],
355+
[$stmts, $visitor7, 'Trying to replace statement (Stmt_Expression) with expression (Scalar_LNumber). Are you missing a Stmt_Expression wrapper?'],
356+
[$stmts, $visitor8, 'Trying to replace expression (Scalar_LNumber) with statement (Stmt_Return)'],
362357
];
363358
}
364359
}

0 commit comments

Comments
 (0)