FindByNameTest.php 858 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. namespace Tests\Services\CityService;
  3. use App\City;
  4. use App\Services\CityService;
  5. use Illuminate\Foundation\Testing\RefreshDatabase;
  6. use Tests\TestCase;
  7. class FindByNameTest extends TestCase
  8. {
  9. use RefreshDatabase;
  10. /** @var CityService $cityService */
  11. public $cityService;
  12. public function setUp(): void
  13. {
  14. parent::setUp(); // TODO: Change the autogenerated stub
  15. $this->cityService = app(CityService::class);
  16. if(!City::query()->where('name','南京')->exists())
  17. factory(City::class)->create(['name'=>'南京']);
  18. }
  19. /**
  20. * @test
  21. */
  22. public function findByName()
  23. {
  24. /** @var City $city */
  25. $city = $this->cityService->findByName('南京市');
  26. $_city =City::query()->where('name','南京')->first();
  27. $this->assertEquals($city,$_city);
  28. }
  29. }