assertEquals('Prague', $this->createService()->getCityNameFromGeoPoint( new GEOPoint(50.073658, 14.418540) )); $this->assertEquals('New York', $this->createService()->getCityNameFromGeoPoint( new GEOPoint(40.730610, -73.935242) )); } public function testGetCityNameFromGeoPointInvalid(): void { $this->assertEquals(null, $this->createService()->getCityNameFromGeoPoint( new GEOPoint(40.730610, -1) )); } public function testGetGeoPointFromCityName(): void { $resolvedGeoPoint = $this->createService()->getGeoPointFromCityName('Prague'); if ($resolvedGeoPoint === null) { $this->fail('Geo point not found'); } $this->assertEquals(50.073658, $resolvedGeoPoint->latitude); $this->assertEquals(14.418540, $resolvedGeoPoint->longitude); $resolvedGeoPoint = $this->createService()->getGeoPointFromCityName('New York'); if ($resolvedGeoPoint === null) { $this->fail('Geo point not found'); } $this->assertEquals(40.730610, $resolvedGeoPoint->latitude); $this->assertEquals(-73.935242, $resolvedGeoPoint->longitude); } public function testGetGeoPointFromCityNameInvalid(): void { $resolvedGeoPoint = $this->createService()->getGeoPointFromCityName('Atlantis'); $this->assertNull($resolvedGeoPoint); } public function createService(): GeoPointResolverService { $geoPointFactory = \Mockery::mock(GEOPointFactory::class); // @phpstan-ignore-next-line method.notFound $geoPointFactory ->shouldReceive('createFromString') ->with('50.073658', '14.418540') ->andReturn(new GEOPoint(50.073658, 14.418540)); // @phpstan-ignore-next-line method.notFound $geoPointFactory ->shouldReceive('createFromString') ->with('40.730610', '-73.935242') ->andReturn(new GEOPoint(40.730610, -73.935242)); return new GeoPointResolverService( [ 'Prague' => [ 'lat' => '50.073658', 'lon' => '14.418540' ], 'New York' => [ 'lat' => '40.730610', 'lon' => '-73.935242' ] ], $geoPointFactory // @phpstan-ignore argument.type ); } }