TaxonomyServiceTest.php
1 <?php 2 3 namespace Tests\Services; 4 5 use App\Http\Services\TaxonomyService; 6 use App\Models\Taxonomy; 7 use Tests\TestCase; 8 9 class TaxonomyServiceTest extends TestCase 10 { 11 public function testSearch() 12 { 13 $query = TaxonomyService::search('', 'id', 'asc', []); 14 15 $this->assertInstanceOf(\Illuminate\Database\Eloquent\Builder::class, $query); 16 } 17 18 /** 19 * @throws \Throwable 20 */ 21 public function testCreate() 22 { 23 $taxonomy = $this->exampleDataArray(); 24 $created = TaxonomyService::create($taxonomy); 25 $this->assertTrue($created); 26 } 27 28 /** 29 * @throws \Throwable 30 */ 31 public function testUpdate() 32 { 33 $taxonomy = Taxonomy::factory()->create(); 34 $newData = $this->exampleDataArray(); 35 36 $updated = TaxonomyService::update($taxonomy->id, $newData); 37 38 $this->assertTrue($updated); 39 } 40 41 /** 42 * @throws \Throwable 43 */ 44 public function testRemove() 45 { 46 $taxonomy = Taxonomy::factory()->create(); 47 TaxonomyService::delete($taxonomy->id); 48 $this->assertSoftDeleted($taxonomy->getTable(), ['id' => $taxonomy->id]); 49 } 50 51 public function testRestore() 52 { 53 $taxonomy = Taxonomy::factory()->create(); 54 $taxonomy->delete(); 55 $this->assertSoftDeleted($taxonomy->getTable(), $taxonomy->getAttributes()); 56 $restore = TaxonomyService::restore($taxonomy->id); 57 $this->assertTrue($restore); 58 } 59 60 private function exampleDataArray() : array 61 { 62 return [ 63 'name' => 'hi', 64 'mode' => 1, 65 ]; 66 } 67 }