<?php
//Filename: MockeryABetterWayOfMockingTest.php
require_once '../vendor/autoload.php';
class MockeryVersusPHPUnitGetMockTest extends PHPUnit_Framework_TestCase {
protected function tearDown() {
\Mockery::close();
}
function testExpectOnce() {
$someObject = new SomeClass();
// With PHPUnit
$phpunitMock = $this->getMock('AClassToBeMocked');
$phpunitMock->expects($this->once())->method('someMethod');
// Exercise for PHPUnit
$someObject->doSomething($phpunitMock);
// With Mockery
$mockeryMock = \Mockery::mock('AnInexistentClass');
$mockeryMock->shouldReceive('someMethod')->once();
// Exercise for Mockery
$someObject->doSomething($mockeryMock);
}
}
class AClassToBeMocked {
function someMethod() {}
}
class SomeClass {
function doSomething($anotherObject) {
$anotherObject->someMethod();
}
}