Skip to content

Instantly share code, notes, and snippets.

@guiled
guiled / calledoncemock.php
Created August 16, 2012 09:34
Atoum, test if a mocked method is called only once
$this->assert
->if($mock = new \mock\MyClassToMock())
->if($test = myTestedClass($mock))
->and($myCounter = 0)
->and($mock->getMockController()->mockedMethod = function () use(&$myCounter) {doWhatever();$myCounter++;})
->and($test->myMethodThatUsesMockedMethod())
->number($myCounter)
->isEqualTo(1);
@guiled
guiled / testMultiMock
Created July 3, 2012 21:59
atoum and mock power! how to pass the same mocked method to different mocked classes
// code sample to instantiate a mock with the same method mocks from an other mocked class
function testMultiMock() {
$this
->if($test = new \mock\author\project\class)
->and($controller = $test->getMockController())
->and($test->getMockController()->instantiate = function () use ($controller) {
$instance = new \mock\author\project\class;
$instance->setMockController($controller);
return $instance;