Using spies in PHPUnit

Code
<?php

use PHPUnit\Framework\TestCase;

/**
 * This code snippet shows how to create spies
 * with PHPUnit's mock object as shown by
 *
 * Anna Filina - https://twitter.com/afilina
 
 * in her video
 * https://www.youtube.com/watch?v=_LeCyU1X5bY
 */
class SpyPhpUnitTest extends TestCase
{
    public function 
testSpyOnBar()
    {
        
$bar $this->getMockBuilder(Bar::class)
            ->
enableProxyingToOriginalMethods()
            ->
getMock();
        
        
// Creating spies
        
$bar->expects($spy1 $this->any())
            ->
method('first');
        
$bar->expects($spy2 $this->any())
            ->
method('second');
        
        
$val = (new Foo())->doStuff($bar);
        
        
self::assertSame(1$val);
        
        
self::assertSame(1$spy1->getInvocationCount());
        
$invocation $spy1->getInvocations()[0];
        
self::assertSame([1], $invocation->getParameters());
        
        
self::assertSame(0$spy2->getInvocationCount());
    }
}

class 
Foo
{
    public function 
doStuff(Bar $bar) : int
    
{
        return 
$bar->first(1);
    }
}

class 
Bar
{
    public function 
first(int $val) : int
    
{
        return 
$val;
    }
    
    public function 
second() : int
    
{
        return 
2;
    }
}
Result
Time: 213 ms, Memory: 2.00MB

OK (1 test, 0 assertions)
Used Versions
PHP 7.2, Zend 3.0, Symfony 4.0, Laravel 5.6, PHPUnit 6.5, Doctrine 2.8