tmarsteel/mockery-callable-mock

Mockery Callable Mock

v2.1.0 2017-09-15 13:22 UTC

This package is not auto-updated.

Last update: 2024-09-18 15:17:33 UTC


README

<?php

use Akamon\MockeryCallableMock\MockeryCallableMock;

// creating a mockery function/callable
$mock = new MockeryCallableMock();

// call it normally
$mock('foo', 'bar');
call_user_func($mock, 'foo', 'bar');

// add it expectations
$mock->shouldBeCalled(); // returns a mockery expectation, so you can use it normally

$mock->shouldBeCalled()->with('foo')->once();
$mock('foo');

$mock->shouldBeCalled()->withNoArgs()->twice();
$mock();
$mock();

// returned values
$mock->shouldBeCalled()->andReturn('foo');
$retval = $mock();

// creating stubs
$stub = new MockeryCallableMock();

$stub->canBeCalled()->with('foo')->andReturn('bar');

// verifying calls
$mock = new MockeryCallableMock();
$mock('bar');

$mock->shouldHaveBeenCalled()->with('bar');
$mock->shouldNotHaveBeenCalled('foo');

// spying
$realAction = function($arg1, $arg2) { /* ... */ }; // or
$realAction = [$this, 'methodToInvoke'];

$callableSpy = new MockeryCallableMock($realAction);

$callableSpy(); // $realAction gets invoked
$callableSpy()->shouldHaveBeenCalled();

需求

PHP 7.0+

作者

许可证

Akamon Mockery Callable Mock 使用 MIT 许可证授权。有关详细信息,请参阅 LICENSE 文件。