<?php
use PHPUnit\Framework\TestCase;
class ConsecutiveTest extends TestCase
{
public function testCounterCall() : void
{
$counter = $this->createMock(Counter::CLASS);
$counter->expects($this->atLeastOnce())
->method('increment')
->willReturnOnConsecutiveCalls(1, 2, 3);
$this->assertEquals(1, $counter->increment());
$this->assertEquals(2, $counter->increment());
$this->assertEquals(3, $counter->increment());
// Any further invocation returns null
$this->assertEquals(null, $counter->increment());
}
}
class Counter
{
private $count = 0;
public function increment()
{
return ++$this->count;
}
}