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