create(); Note::factory(5)->create([ 'place_id' => $place->id, ]); $this->assertInstanceOf(Collection::class, $place->notes); $this->assertCount(5, $place->notes); } #[Test] public function near_method_returns_collection(): void { Place::factory()->create([ 'name' => 'The Bridgewater Pub', 'latitude' => 53.4983, 'longitude' => -2.3805, ]); $nearby = Place::near((object) ['latitude' => 53.5, 'longitude' => -2.38])->get(); $this->assertEquals('the-bridgewater-pub', $nearby[0]->slug); } #[Test] public function get_uri(): void { $place = Place::factory()->create([ 'name' => 'The Bridgewater Pub', ]); $this->assertEquals(config('app.url') . '/places/the-bridgewater-pub', $place->uri); } #[Test] public function place_service_returns_existing_place_based_on_external_urls_search(): void { Place::factory(10)->create(); $place = new Place; $place->name = 'Temp Place'; $place->latitude = 37.422009; $place->longitude = -122.084047; $place->external_urls = 'https://www.openstreetmap.org/way/1234'; $place->save(); $service = new PlaceService; $ret = $service->createPlaceFromCheckin([ 'properties' => [ 'url' => ['https://www.openstreetmap.org/way/1234'], ], ]); $this->assertCount(11, Place::all()); } #[Test] public function place_service_requires_name_when_creating_new_place(): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Missing required name'); $service = new PlaceService; $service->createPlaceFromCheckin(['foo' => 'bar']); } #[Test] public function place_service_requires_latitude_when_creating_new_place(): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Missing required longitude/latitude'); $service = new PlaceService; $service->createPlaceFromCheckin(['properties' => ['name' => 'bar']]); } #[Test] public function place_service_can_update_external_urls(): void { $place = Place::factory()->create([ 'name' => 'The Bridgewater Pub', 'latitude' => 53.4983, 'longitude' => -2.3805, 'external_urls' => '', ]); $place->external_urls = 'https://www.openstreetmap.org/way/987654'; $place->external_urls = 'https://foursquare.com/v/123435/the-bridgewater-pub'; $place->save(); $place->external_urls = 'https://bridgewater.pub'; $this->assertEquals(json_encode([ 'default' => 'https://bridgewater.pub', 'osm' => 'https://www.openstreetmap.org/way/987654', 'foursquare' => 'https://foursquare.com/v/123435/the-bridgewater-pub', ]), $place->external_urls); } }