Last active
December 23, 2015 10:38
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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