Files
solidtime/tests/Unit/Model/TaskModelTest.php
T
2024-04-17 12:39:23 +02:00

60 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Unit\Model;
use App\Models\Organization;
use App\Models\Project;
use App\Models\Task;
use App\Models\TimeEntry;
class TaskModelTest extends ModelTestAbstract
{
public function test_it_belongs_to_a_organization(): void
{
// Arrange
$organization = Organization::factory()->create();
$task = Task::factory()->forOrganization($organization)->create();
// Act
$task->refresh();
$organizationRel = $task->organization;
// Assert
$this->assertNotNull($organizationRel);
$this->assertTrue($organizationRel->is($organization));
}
public function test_it_belongs_to_a_project(): void
{
// Arrange
$project = Project::factory()->create();
$task = Task::factory()->forProject($project)->create();
// Act
$task->refresh();
$projectRel = $task->project;
// Assert
$this->assertNotNull($projectRel);
$this->assertTrue($projectRel->is($project));
}
public function test_it_has_many_time_entries(): void
{
// Arrange
$otherTask = Task::factory()->create();
$task = Task::factory()->create();
$timeEntries = TimeEntry::factory()->forTask($task)->count(3)->create();
$otherTimeEntries = TimeEntry::factory()->forTask($otherTask)->count(2)->create();
// Act
$task->refresh();
$timeEntries = $task->timeEntries;
// Assert
$this->assertCount(3, $timeEntries);
}
}