So I am new to phpunit/codeception. With that said, I am attempting to test a method that is in a command. This command extends another base command. In the base command, there is a method that sets a gateway. This gateway has a method, pullGroup, which pulls a group via api from another server.
The method I want to test, calls upon the gateway like so:
$response = $this->gateway->pullGroup($foreign_id);
I am not sure how to mock that call. What I would prefer to do and what I think is the correct way, is to mock it in a way to use some sort of stub data to return but not sure how to do this. From what I see, something like this should be done:
$mockPullGroup = \Mockery::mock('TestSite\Library\Gateway\FellowshipOneGateway');
$mockPullGroup->shouldReceive('pullGroup')->once()->andReturn(true); // Need to add some data here to test with?
Then, not sure how to inject that into the method I am testing, as the call for that is as follows:
$return = $this->command->updateRecord($foreign_id,$record); // Need to inject it here?
$this->assertInternalType('array',$return);
Probably need to do a little more DI but think it should be good enough to mock already? Maybe I am wrong. Here is how the gateway is setup in the base command:
public function setGateway(Test $test)
{
$this->gateway = new TestSite\Library\Gateway\TestGateway($test);
return true;
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community