NormGroupServiceTest.php
1 <?php 2 3 namespace Tests\Services; 4 5 use App\Http\Resources\NormGroupResource; 6 use App\Http\Services\NormGroupService; 7 use App\Models\NormGroup; 8 use Illuminate\Http\Resources\Json\AnonymousResourceCollection; 9 use Tests\TestCase; 10 11 class NormGroupServiceTest extends TestCase 12 { 13 public NormGroup $group; 14 15 public function setUp(): void 16 { 17 parent::setUp(); 18 $this->group = NormGroup::factory()->create(); 19 } 20 21 public function test_index() 22 { 23 NormGroup::factory()->count(11)->create(); 24 25 $got = NormGroupService::index(); 26 $this->assertInstanceOf(AnonymousResourceCollection::class, $got); 27 $this->assertCount(10, $got->resource); 28 } 29 30 public function test_create() 31 { 32 $data = NormGroup::factory()->make()->toArray(); 33 $created = NormGroupService::create($data); 34 35 $this->assertTrue($created); 36 $this->assertDatabaseHas('norm_groups', $data); 37 } 38 39 public function test_remove() 40 { 41 $removed = NormGroupService::remove($this->group->id); 42 $this->assertTrue($removed); 43 $this->assertSoftDeleted($this->group); 44 } 45 46 public function test_update() 47 { 48 $data = NormGroup::factory()->make()->toArray(); 49 $updated = NormGroupService::update($data, $this->group->id); 50 $this->assertTrue($updated); 51 $this->assertDatabaseHas('norm_groups', $data); 52 $this->assertDatabaseMissing('norm_groups', $this->group->toArray()); 53 } 54 55 public function test_find() 56 { 57 $group = NormGroup::factory()->create(); 58 59 $found = NormGroupService::find($group->id); 60 $this->assertNotNull($found); 61 $this->assertInstanceOf(NormGroupResource::class, $found); 62 } 63 64 public function test_get_norm_groups() 65 { 66 $got = NormGroupService::getNormGroups(); 67 $this->assertNotNull($got); 68 $this->assertCount(NormGroup::count(), $got); 69 } 70 }