-
tests/Feature/ProjectTest.php
Open in GitHubuse App\Models\Client; use App\Models\Project; use App\Models\TimeEntry; use App\Models\WorkType; use Mockery; use PHPUnit\Framework\Attributes\Group; use Tests\TestCase; class ProjectTest extends TestCase { // ... #[Group('projects')] public function test_users_can_export_time_entries(): void { $this->createLoggedUser(); $client = Client::factory()->create(); $project = Project::factory()->create(['client_id' => $client]); WorkType::factory()->create(); TimeEntry::factory()->count(2)->create(['project_id' => $project->id]); $this->mockFunction('export_time_entries', function ($timeEntries) { $this->assertCount(2, $timeEntries); return 'exported_data'; }); $response = $this->get(route('projects.export', $project->id)); $response->assertStatus(200); $response->assertHeader('Content-Disposition', 'attachment; filename=report.xlsx'); $response->assertHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); } protected function mockFunction($function, $callback) { $mock = Mockery::mock('alias:'.$function); $mock->shouldReceive('__invoke')->andReturnUsing($callback); $this->app->instance($function, $mock); } }