Check if a method is invoked X times in PHPUnit

Code
<?php

class ExactlyTest extends PHPUnit_Framework_TestCase
{
    public function 
testCounterCall()
    {
        
$counter $this->getMockBuilder(Counter::CLASS)
            ->
enableProxyingToOriginalMethods()
            ->
getMock();
        
$counter->expects($this->exactly(3))
            ->
method('increment');
        
        
$this->assertEquals(1$counter->increment());
        
$this->assertEquals(2$counter->increment());
        
$this->assertEquals(3$counter->increment());
        
// a 4th call of increment() is not allowed by this test
        
$this->assertEquals(4$counter->increment());
    }
}

class 
Counter
{
    private 
$count 0;
    
    public function 
increment()
    {
        return ++
$this->count;
    }
}
Result
Time: 269 ms, Memory: 10.00MB

There was 1 failure:

1) ExactlyTest::testCounterCall
Counter::increment() was not expected to be called more than 3 times.

ExactlyTest.php:17

FAILURES!
Tests: 1, Assertions: 0, Failures: 1.