Performance: Mocking and faking
LOW IMPACT
Mocking and faking mainly affect test execution speed and resource usage during development, not the live page load or rendering.
<?php
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Event;
public function testUserCreationWithMock() {
Http::fake(['api.example.com/*' => Http::response(['data' => 'fake'], 200)]);
Event::fake();
$user = User::factory()->create();
$this->assertNotNull($user);
$response = Http::get('https://api.example.com/data');
$this->assertEquals(200, $response->status());
}<?php // Test calls real database or API public function testUserCreation() { $user = User::create(['name' => 'Test']); $response = Http::get('https://api.example.com/data'); $this->assertTrue($user->exists); $this->assertEquals(200, $response->status()); }
| Pattern | Test Execution Time | External Calls | Resource Usage | Verdict |
|---|---|---|---|---|
| Real database and API calls | High (slow) | Many (network + DB) | High (DB connections, network) | [X] Bad |
| Using Laravel Http::fake and model factories | Low (fast) | None (all faked) | Low (no real connections) | [OK] Good |