Это моя команда (соответствующий код):
Код: Выделить всё
class CommandToTest extends Command
{
//constants, setup handle and other stuff
//other methods
protected function methodToMock()
{
//method with the call to external web service that should be mocked
}
//other methods
}
Код: Выделить всё
class TestForCommand extends TestCase
{
//constants etc
public function testCommandToTest()
{
$commandMock = Mockery::mock(CommandToTest::class)->makePartial();
$commandMock->shouldAllowMockingProtectedMethods()->shouldReceive('methodToMock')
->andReturn([
'Test01' => 'T01',
'Test02' => 'T02',
'Test03' => 'T03'
]);
$this->app->instance(CommandToTest::class, $commandMock);
//other stuff
$this->artisan('tools:commandtotest', [//params])
->expectsConfirmation(//params ok)
->assertOk();
}
//assertions
}
Подробнее здесь: https://stackoverflow.com/questions/787 ... g-php-unit
Мобильная версия