Documentation Index
Fetch the complete documentation index at: https://kawax.biz/llms.txt
Use this file to discover all available pages before exploring further.
Laravel lets you write tests like this.
Copilot::fake()
Copilot::fake() mocks behavior exposed through the Copilot facade. It does not mock every internal component.
use Revolution\Copilot\Facades\Copilot;
Copilot::fake('2'); // Mock that always returns "2"
$response = Copilot::run(prompt: '1 + 1'); // Copilot CLI is not called
// Pest
expect($response->content())->toBe('2');
// PHPUnit
$this->assertEquals('2', $response->content());
For multiple calls in Copilot::start():
use Revolution\Copilot\Facades\Copilot;
use Revolution\Copilot\Contracts\CopilotSession;
Copilot::fake([
'*' => Copilot::sequence()
->push(Copilot::response('2'))
->push(Copilot::response('4')),
]);
Copilot::start(function (CopilotSession $session) use (&$response1, &$response2) {
$response1 = $session->sendAndWait(prompt: '1 + 1'); // Returns "2"
$response2 = $session->sendAndWait(prompt: '2 + 2'); // Returns "4"
});
expect($response1->content())->toBe('2');
Assertions
Verify a specific prompt was called:
Copilot::assertPrompt('1 + *');
Verify a prompt was not called:
Copilot::assertNotPrompt('1 + *');
Verify call count:
Copilot::assertPromptCount(3);
Verify nothing was sent:
Copilot::assertNothingSent();
Prevent stray requests
Block all JSON-RPC requests. If a request is sent, Revolution\Copilot\Exceptions\StrayRequestException is thrown.
Copilot::preventStrayRequests();
Allow only specific commands:
Copilot::preventStrayRequests(allow: ['ping']);
Disable prevention:
Copilot::preventStrayRequests(false);
Only JSON-RPC requests are blocked. Client::start() is not blocked.
Cases that may not work as expected
When you use Copilot inside an Artisan command, fake() works, but assertions such as assertPrompt() may not always behave as expected.
use Revolution\Copilot\Facades\Copilot;
Copilot::fake('Hello');
$this->artisan('copilot:hi');
Copilot::assertPrompt('Hi');
shouldReceive() / expects()
You can also use familiar Mockery-style methods such as shouldReceive() and expects() via the facade.