I'm Trying to test the following method:
/* ConfigurationService.php*/
public function checkConfigs()
{
$configurations = $this->getConfigurations();
return $configurations['configExample'] === '1';
}
Considering that the getConfigurations()
method calls other methods outside this file, inside ConfigurationRepository.php
, I've tried to mock only its return and execute the method that I wanna test(checkConfigs()
): (some code ommited)
/* ConfigurationServiceTest.php */
$configurationRepoMock = \Mockery::mock(ConfigurationRepository::class);
$configurationRepoMock
->shouldReceive('getConfigurations')
->once()
->andReturn(['configExample' => '1']);
$configurationServiceMock = \Mockery::mock(ConfigurationService::class);
$this->app->instance('App\Services\ConfigurationService', $configurationServiceMock);
$configurationServiceInstance = new ConfigurationService($configurationRepoMock);
$response = $configService->checkConfigs();
The PROBLEM is, instead of returning the mocked result(['configExample' => '1']
), the method getConfigurations()
executes, failing due to other method calls inside of it, returning the error:
Mockery\Exception\BadMethodCallException: Received Mockery_1_App_Repositories_API_ConfigurationRepository::methodInsideGetConfigurations(), but no expectations were specified
Summing up, andReturn()
is not working. Any ideas?
Aucun commentaire:
Enregistrer un commentaire