-
-
Save karptonite/4972230 to your computer and use it in GitHub Desktop.
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 | |
class PostsTest extends TestCase { | |
public function testShow() | |
{ | |
$testpost = ['text' => 'Test post', 'id' => 1]; | |
$this->instanceMock('PostRepositoryInterface')->shouldReceive('find')->with(1)->once()->andReturn($testpost); | |
} | |
} |
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 | |
use Mockery as m; | |
class TestCase extends Illuminate\Foundation\Testing\TestCase { | |
//Other test case functions removed | |
//$mockargs can be a string or an array of arguments to pass into m::mock() | |
public function instanceMock($mockargs, $instanceName=null) | |
{ | |
if(is_array( $mockargs)) | |
{ | |
$mockable = $mockargs[0]; | |
$mock = call_user_func_array('m::mock', $mockargs); | |
} | |
else | |
{ | |
$mockable = $mockargs; | |
$mock = m::mock($mockable); | |
} | |
$instanceName = $instanceName ?: $mockable; | |
App::instance($instanceName, $mock); | |
return $mock; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Perhaps if the arguments were passed as an array in a second argument?