CityUnitTest.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace Tests\Unit\Cities;
  3. use App\Shop\Cities\Exceptions\CityNotFoundException;
  4. use App\Shop\Cities\Repositories\CityRepository;
  5. use App\Shop\Cities\City;
  6. use Tests\TestCase;
  7. class CityUnitTest extends TestCase
  8. {
  9. /** @test */
  10. public function it_can_list_all_the_cities()
  11. {
  12. $city = factory(City::class)->create();
  13. $cityRepo = new CityRepository($city);
  14. $this->assertCount(1, $cityRepo->listCities());
  15. }
  16. /** @test */
  17. public function it_can_update_the_city()
  18. {
  19. $city = factory(City::class)->create();
  20. $cityRepo = new CityRepository($city);
  21. $update = ['name' => 'Manila'];
  22. $updated = $cityRepo->updateCity($update);
  23. $this->assertTrue($updated);
  24. }
  25. /** @test */
  26. public function it_will_error_when_city_is_not_found()
  27. {
  28. $this->expectException(CityNotFoundException::class);
  29. $cityRepo = new CityRepository(new City);
  30. $cityRepo->findCityByName('unknown');
  31. }
  32. /** @test */
  33. public function it_can_find_the_city()
  34. {
  35. $city = factory(City::class)->create();
  36. $cityRepo = new CityRepository(new City);
  37. $found = $cityRepo->findCityByName($city->name);
  38. $this->assertEquals($city->name, $found->name);
  39. }
  40. }