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