mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-09 16:52:17 +01:00
Added basic models and factories
This commit is contained in:
72
tests/Unit/Model/ProjectModelTest.php
Normal file
72
tests/Unit/Model/ProjectModelTest.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Model;
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\Project;
|
||||
use App\Models\Task;
|
||||
use App\Models\Team;
|
||||
|
||||
class ProjectModelTest extends ModelTestAbstract
|
||||
{
|
||||
public function test_it_belongs_to_a_organization(): void
|
||||
{
|
||||
// Arrange
|
||||
$organization = Team::factory()->create();
|
||||
$project = Project::factory()->forOrganization($organization)->create();
|
||||
|
||||
// Act
|
||||
$project->refresh();
|
||||
$organizationRel = $project->organization;
|
||||
|
||||
// Assert
|
||||
$this->assertNotNull($organizationRel);
|
||||
$this->assertTrue($organizationRel->is($organization));
|
||||
}
|
||||
|
||||
public function test_it_can_belong_to_a_client(): void
|
||||
{
|
||||
// Arrange
|
||||
$client = Client::factory()->create();
|
||||
$project = Project::factory()->forClient($client)->create();
|
||||
|
||||
// Act
|
||||
$project->refresh();
|
||||
$clientRel = $project->client;
|
||||
|
||||
// Assert
|
||||
$this->assertNotNull($clientRel);
|
||||
$this->assertTrue($clientRel->is($client));
|
||||
}
|
||||
|
||||
public function test_it_can_belong_to_no_client(): void
|
||||
{
|
||||
// Arrange
|
||||
$project = Project::factory()->forClient(null)->create();
|
||||
|
||||
// Act
|
||||
$project->refresh();
|
||||
$clientRel = $project->client;
|
||||
|
||||
// Assert
|
||||
$this->assertNull($clientRel);
|
||||
}
|
||||
|
||||
public function test_it_has_many_tasks(): void
|
||||
{
|
||||
// Arrange
|
||||
$project = Project::factory()->create();
|
||||
$tasks = Task::factory()->forProject($project)->createMany(3);
|
||||
|
||||
// Act
|
||||
$project->refresh();
|
||||
$tasksRel = $project->tasks;
|
||||
|
||||
// Assert
|
||||
$this->assertNotNull($tasksRel);
|
||||
$this->assertCount(3, $tasksRel);
|
||||
$this->assertTrue($tasksRel->first()->is($tasks->first()));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user