/ tests / Services / EntityServiceTest.php
EntityServiceTest.php
 1  <?php
 2  
 3  namespace Tests\Services;
 4  
 5  use App\Enums\EntityTypeEnum;
 6  use App\Http\Services\EntityService;
 7  use App\Models\ContactInfo;
 8  use App\Models\Entity;
 9  use Illuminate\Pagination\LengthAwarePaginator;
10  use Illuminate\Support\Collection;
11  
12  class EntityServiceTest extends \Tests\TestCase
13  {
14      public Entity $entity;
15  
16      public function setUp(): void
17      {
18          parent::setUp();
19          $this->entity = Entity::factory()->create();
20      }
21  
22      /**
23       * @throws \Throwable
24       */
25      public function testRemove()
26      {
27          EntityService::remove($this->entity->id);
28          $this->assertSoftDeleted($this->entity);
29      }
30  
31      public function testSearch()
32      {
33          $query = EntityService::search('', 'id', 'asc', []);
34          $this->assertInstanceOf(\Illuminate\Database\Eloquent\Builder::class, $query);
35      }
36  
37      public function testGetEntityCompanies()
38      {
39          $this->assertInstanceOf(Collection::class, EntityService::getEntityLaboratories());
40      }
41  
42      public function testFind()
43      {
44          $this->assertInstanceOf(Entity::class, EntityService::find(1));
45      }
46  
47      /**
48       * @throws \Throwable
49       */
50      public function testCreate()
51      {
52          $entityData = Entity::factory()->make()->toArray();
53          $contactInfoData = ContactInfo::factory()->make()->toArray();
54          $created = EntityService::create($entityData, $contactInfoData);
55          $this->assertTrue($created);
56          $this->assertDatabaseHas('entities', $entityData);
57          $this->assertDatabaseHas('contact_infos', $contactInfoData);
58      }
59  
60      public function testRestore()
61      {
62          $this->entity->delete();
63          $this->assertSoftDeleted($this->entity);
64          $this->assertTrue(EntityService::restore($this->entity->id));
65      }
66  
67      public function testGetEntityLaboratories()
68      {
69          $this->assertInstanceOf(Collection::class, EntityService::getEntityLaboratories());
70      }
71  
72      public function testIndex()
73      {
74          $this->assertInstanceOf(LengthAwarePaginator::class, EntityService::index());
75      }
76  
77      public function testUpdate()
78      {
79          $oldName = $this->entity->name;
80          $contactInfoData = ContactInfo::factory()->make()->toArray();
81  
82          $this->assertTrue(EntityService::update(['name' => uniqid()], $contactInfoData, $this->entity->id));
83          $this->entity->refresh();
84  
85          $this->assertNotEquals($this->entity->name, $oldName);
86      }
87  }