I'm new to Mockery. I'm trying to figure it out with the GitHub API by using a Laravel Package as a wrapper. How can I mock GitHub::repo()->show('symfony', 'demo');
without hiting the actual API? Is there something weird with Facades? I'm getting an error here:
In EvalLoader.php(34) : eval()'d code line 993:
Cannot redeclare Mockery_0_GrahamCampbell_GitHub_Facades_GitHub::shouldReceive()
Code:
use Mockery;
use Tests\TestCase;
use GrahamCampbell\GitHub\Facades\GitHub;
public function testExample()
{
$this->mockGitHubWith([
'id' => 1,
'name' => 'demo',
'full_name' => 'symfony/demo',
]);
$repo = GitHub::repo()->show('symfony', 'demo');
dd($repo);
}
protected function mockGitHubWith($expectations)
{
$github = Mockery::mock(GitHub::class, $expectations);
$github->shouldReceive('api')->andReturn($github);
app()->instance(GitHub::class, $github);
}
also tried:
use GrahamCampbell\GitHub\Facades\GitHub;
public function testExample()
{
Github::shouldReceive('api')->once()->andReturn(['id' => 1]);
$repo = Github::repo()->show('symfony', 'demo');
dd($repo);
}
Returns: Mockery\Exception\BadMethodCallException: Method Mockery_0::repo() does not exist on this mock object
Just to confirm, if I remove the GitHub::shouldReceive...
line, it's successful but actually hits the GitHub API.