PHP code example of mnapoli / mockup

1. Go to this page and download the library: Download mnapoli/mockup library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mnapoli / mockup example snippets


$mock = mock(Foo::class, [
    'foo' => 'Hello',
]);

$mock = $this->getMock(Foo::class, [], [], '', false);
$mock->expect($this->any())
    ->method('foo')
    ->willReturn('Hello');

$prophet = new \Prophecy\Prophet();
$mock = $prophet->prophesize(Foo::class);
$mock->foo()->willReturn('Hello');
$mock = $mock->reveal();

$mock = Mockery::mock(Foo::class);
$mock->shouldReceive('foo')
    ->andReturn('Hello');

// The mock method was called once
$this->assertEquals(1, inspect($mock)->foo()->invokationCount());

use function Mockup\mock;

interface Foo
{
    public function foo($bar);
}

$mock = mock(Foo::class);
$mock->foo();

$mock = mock(Foo::class, [
    'foo' => 'hello',
]);

$mock->foo('john'); // hello

$mock = mock(Foo::class, [
    'foo' => function ($bar) {
        return strtoupper('hello ' . $bar);
    }
]);

$mock->foo('john'); // HELLO JOHN

use function Mockup\{spy, inspect};

$spy = spy($cache);
$foo->doSomething($spy);

inspect($spy)->set()->invokationCount(); // number of calls to $spy->set()
inspect($spy)->set()->parameters(0); // parameters provided to the first call to $spy->set()
inspect($spy)->set()->returnValue(0); // value returned by the first call to $spy->set()

use function Mockup\{mock, inspect};

$mock = mock(CacheInterface::class);
$foo->doSomething($mock);

inspect($spy)->set()->invokationCount();
inspect($spy)->set()->parameters(0);
inspect($spy)->set()->returnValue(0);