Skip to content

Instantly share code, notes, and snippets.

@cburgmer
Last active December 23, 2015 10:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cburgmer/6622425 to your computer and use it in GitHub Desktop.
Save cburgmer/6622425 to your computer and use it in GitHub Desktop.
Work around for Mockery to test for a specific call parameter setting when several calls are made to the same method
<?php
require_once 'Mockery/Loader.php';
require_once 'Hamcrest/Hamcrest.php';
require_once 'PHPUnit/Framework/TestCase.php';
$loader = new \Mockery\Loader;
$loader->register();
use Mockery as m;
class EventSender {
public function sendEvent($msg) {}
}
class ObjectUnderTest {
public function __construct(EventSender $instance) {
$this->instance = $instance;
}
public function doit() {
$this->instance->sendEvent("msg1");
$this->instance->sendEvent("msg2");
$this->instance->sendEvent("msg3");
}
}
class MockeryIssue extends PHPUnit_Framework_TestCase {
public function testIssue() {
$instanceMock = m::mock('EventSender');
$instanceUnderTest = new ObjectUnderTest($instanceMock);
$instanceMock->shouldReceive("sendEvent")->with("msg2")->once();
// Magic line needed
$instanceMock->shouldReceive("sendEvent");
$instanceUnderTest->doit();
}
public function tearDown() {
\Mockery::close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment