FindByNameTest.php 892 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace Tests\Services\CityService\FindByNameTest;
  3. use App\City;
  4. use App\Services\CityService;
  5. use Illuminate\Foundation\Testing\RefreshDatabase;
  6. use Illuminate\Foundation\Testing\WithFaker;
  7. use Tests\TestCase;
  8. class FindByNameTest extends TestCase
  9. {
  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. }