ToeCategoryServiceTest.php
1 <?php 2 3 namespace Tests\Services; 4 5 use App\Http\Services\ToeCategoryService; 6 use App\Models\TOEType; 7 use Illuminate\Pagination\LengthAwarePaginator; 8 use Tests\TestCase; 9 10 class ToeCategoryServiceTest extends TestCase 11 { 12 public function testIndex() 13 { 14 $this->assertInstanceOf(LengthAwarePaginator::class, ToeCategoryService::index()); 15 } 16 17 /** 18 * @throws \Throwable 19 */ 20 public function testCreate() 21 { 22 $data = $this->exampleDataArray(); 23 $created = ToeCategoryService::create($data); 24 $this->assertTrue($created); 25 } 26 27 /** 28 * @throws \Throwable 29 */ 30 public function testUpdate() 31 { 32 $toeType = TOEType::factory()->create(); 33 $newData = $this->exampleDataArray(); 34 $updated = ToeCategoryService::update($newData, $toeType->id); 35 $this->assertTrue($updated); 36 } 37 38 /** 39 * @throws \Throwable 40 */ 41 public function testRemove() 42 { 43 $toeType = TOEType::factory()->create(); 44 ToeCategoryService::remove($toeType->id); 45 $this->assertSoftDeleted($toeType->getTable(), ['id' => $toeType->id]); 46 } 47 48 public function testFind() 49 { 50 $toeType = TOEType::factory()->create(); 51 $this->assertInstanceOf(TOEType::class, ToeCategoryService::find($toeType->id)); 52 } 53 54 private function exampleDataArray() : array 55 { 56 return [ 57 'name' => 'New Name', 58 'code' => 1, 59 ]; 60 } 61 }