BrandUnitTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace Tests\Unit\Brands;
  3. use App\Shop\Brands\Brand;
  4. use App\Shop\Brands\Repositories\BrandRepository;
  5. use Illuminate\Support\Collection;
  6. use Tests\TestCase;
  7. class BrandUnitTest extends TestCase
  8. {
  9. /** @test */
  10. public function it_can_show_all_the_brands()
  11. {
  12. factory(Brand::class, 3)->create();
  13. $brandRepo = new BrandRepository(new Brand);
  14. $list = $brandRepo->listBrands();
  15. $this->assertInstanceOf(Collection::class, $list);
  16. $this->assertCount(3, $list->all());
  17. }
  18. /** @test */
  19. public function it_can_delete_the_brand()
  20. {
  21. $brand = factory(Brand::class)->create();
  22. $brandRepo = new BrandRepository($brand);
  23. $deleted = $brandRepo->deleteBrand($brand->id);
  24. $this->assertTrue($deleted);
  25. }
  26. /** @test */
  27. public function it_can_update_the_brand()
  28. {
  29. $brand = factory(Brand::class)->create();
  30. $data = ['name' => 'Argentina'];
  31. $brandRepo = new BrandRepository($brand);
  32. $updated = $brandRepo->updateBrand($data);
  33. $found = $brandRepo->findBrandById($brand->id);
  34. $this->assertTrue($updated);
  35. $this->assertEquals($data['name'], $found->name);
  36. }
  37. /** @test */
  38. public function it_can_show_the_brand()
  39. {
  40. $brand = factory(Brand::class)->create();
  41. $brandRepo = new BrandRepository(new Brand);
  42. $found = $brandRepo->findBrandById($brand->id);
  43. $this->assertInstanceOf(Brand::class, $found);
  44. $this->assertEquals($brand->name, $found->name);
  45. }
  46. /** @test */
  47. public function it_can_create_a_brand()
  48. {
  49. $data = ['name' => $this->faker->company];
  50. $brandRepo = new BrandRepository(new Brand);
  51. $brand = $brandRepo->createBrand($data);
  52. $this->assertInstanceOf(Brand::class, $brand);
  53. $this->assertEquals($data['name'], $brand->name);
  54. }
  55. }