Skip to content

Instantly share code, notes, and snippets.

@brianium
Created March 14, 2012 17:40
Show Gist options
  • Save brianium/2038141 to your computer and use it in GitHub Desktop.
Save brianium/2038141 to your computer and use it in GitHub Desktop.
mocking interfaces in php
<?php
namespace Test\Unit\Domain\Repositories;
use Domain\Repositories;
use Domain\Entities\InputConfig;
use Infrastructure\Reflection\Reflection;
class IInputConfigRepositoryTest extends \PHPUnit_Framework_TestCase
{
public function setUp() {
$this->mock = $this->getMockBuilder('Domain\Repositories\IInputConfigRepository')
->disableOriginalConstructor()
->getMock();
}
public function tearDown() {
$this->mock = null;
}
public function testFindMethod() {
$return = new InputConfig();
Reflection::setProtectedVar($return,'input_num',1);
$this->mock->expects($this->any())
->method('find')
->with($this->equalTo(1))
->will($this->returnValue($return));
$this->assertEquals(1,$this->mock->find(1)->getInputNum());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment