FindByNameTest.php 832 B

123456789101112131415161718192021222324252627282930313233
  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. /** @var CityService $cityService */
  10. public $cityService;
  11. public function setUp(): void
  12. {
  13. parent::setUp(); // TODO: Change the autogenerated stub
  14. $this->cityService = app(CityService::class);
  15. if(!City::query()->where('name','南京')->exists())
  16. factory(City::class)->create(['name'=>'南京']);
  17. }
  18. /**
  19. * @test
  20. */
  21. public function findByName()
  22. {
  23. /** @var City $city */
  24. $city = $this->cityService->findByName('南京市');
  25. $_city =City::query()->where('name','南京')->first();
  26. $this->assertEquals($city,$_city);
  27. }
  28. }