Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

clockobot/clockobot

46 stars
1 code files
View clockobot/clockobot on GitHub

tests/Feature/ProjectTest.php

Open in GitHub
use 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);
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.