WorkBookServiceTest.php
1 <?php 2 3 namespace Tests\Services; 4 5 use App\Http\Services\WorkbookService; 6 use App\Models\Norm; 7 use App\Models\Workbook; 8 use Illuminate\Support\Collection; 9 use Tests\TestCase; 10 11 class WorkBookServiceTest extends TestCase 12 { 13 public function testIndex() 14 { 15 $normId = Norm::first()->id; 16 $this->assertInstanceOf( 17 \Illuminate\Http\Resources\Json\AnonymousResourceCollection::class, 18 WorkbookService::index($normId) 19 ); 20 } 21 22 /** 23 * @throws \Throwable 24 */ 25 public function testCreate() 26 { 27 $data = $this->exampleDataArray(); 28 $created = WorkbookService::create($data['workBook'], $data['normScope']); 29 $this->assertTrue($created); 30 } 31 32 /** 33 * @throws \Throwable 34 */ 35 public function testRemove() 36 { 37 $data = $this->exampleDataArray(); 38 WorkbookService::create($data['workBook'], $data['normScope']); 39 $workBook = WorkBook::first(); 40 WorkbookService::remove($workBook->id); 41 $this->assertSoftDeleted($workBook->getTable(), ['id' => $workBook->id]); 42 } 43 44 /** 45 * @throws \Throwable 46 */ 47 public function testUpdate() 48 { 49 $data = $this->exampleDataArray(); 50 WorkbookService::create($data['workBook'], $data['normScope']); 51 $workBook = WorkBook::first(); 52 $data['workBook']['name'] = "Other Name"; 53 $data['normScope'] = [1]; 54 $updated = WorkbookService::update( 55 $data['workBook'], 56 $workBook->id, 57 $data['normScope'] 58 ); 59 $this->assertTrue($updated); 60 } 61 62 private function exampleDataArray() : array 63 { 64 return [ 65 'workBook' => [ 66 'name' => 'New Name', 67 'norm_id' => 1, 68 ], 69 'normScope' => [] 70 ]; 71 } 72 }