Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save awei01/9278119 to your computer and use it in GitHub Desktop.
Save awei01/9278119 to your computer and use it in GitHub Desktop.
Also posted here (http://stackoverflow.com/questions/22104314/php-mockery-throwing-unexpected-must-implement-interface-exception-when-functi). I'm using Mockery to unit test an admittedly edge case. It's failing and I don't think it should fail, so there could be a bug within Mockery. Consider an object that has a method. The method has an argum…
<?php
use PHPUnit_Framework_TestCase;
use Mockery;
class SomeTest extends PHPUnit_Framework_TestCase {
function testRealFooObject_BarImplementation_NotThrowingException()
{
$foo = new FooObject;
$bar = new BarImplemention;
$baz = 'baz';
$result = $foo->barFunction($bar, $baz);
$this->assertEquals($bar, $result);
}
function testRealFooObject_Null_NotThrowingException()
{
$foo = new FooObject;
$bar = null;
$baz = 'baz';
$result = $foo->barFunction(null, $baz);
$this->assertNull($result);
}
function testMockedFooObject_BarImplementation_NotThrowingException()
{
$mockFoo = Mockery::mock('FooObject')->shouldIgnoreMissing();
$bar = new BarImplemention;
$baz = 'baz';
$result = $mockFoo->barFunction($bar, $baz);
$this->assertNull($result);
}
function testMockedFooObject_Null_IsThrowingExceptionButShouldnt()
{
$mockFoo = Mockery::mock('FooObject')->shouldIgnoreMissing();
$bar = null;
$baz = 'baz';
$result = $mockFoo->barFunction($bar, $baz);
$this->assertNull($result);
}
function testMockedPooObject_Null_NotThrowingExceptionBecauseSecondParamHasDefault()
{
$mockPoo = Mockery::mock('PooObject')->shouldIgnoreMissing();
$bar = null;
$baz = 'baz';
$result = $mockPoo->barFunction($bar, $baz);
$this->assertNull($result);
}
}
class BarImplemention {
}
class FooObject {
public function barFunction(BarImplemention $bar = null, $baz)
{
return $bar;
}
}
class PooObject {
public function barFunction(BarImplemention $bar = null, $baz = null)
{
return $bar;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment