예제 #1
0
 /**
  * Search venues.
  *
  * @param Search $options The search options.
  *
  * @return Venue[]
  */
 public function search(Search $options)
 {
     $url = $this->getUrl('venues/search', $options->toArray());
     $response = $this->httpClient->get($url, $this->getDefaultHeaders());
     $description = $this->parseResponse($response);
     if (!isset($description->response->venues)) {
         throw InvalidResponseException::invalidResponseBody($response, 'response.venues');
     }
     return array_map(function (\stdClass $venueDescription) {
         return $this->venueFactory->create($venueDescription);
     }, $description->response->venues);
 }
 /**
  * Provides options.
  *
  * @return array
  */
 public function optionsProvider()
 {
     return [[Search::createWithPlace('Chicago, IL')->setLimit(1)->setRadius(500), ['near' => 'Chicago, IL', 'limit' => 1, 'radius' => 500]], [Search::createWithCoordinates(new Coordinates(40.12, 50.12))->setLimit(40)->setRadius(10), ['ll' => new Coordinates(40.12, 50.12), 'limit' => 40, 'radius' => 10]], [Search::createWithCoordinates(new Coordinates(40.12, 50.12))->setRadius(10), ['ll' => new Coordinates(40.12, 50.12), 'radius' => 10]]];
 }
 /**
  * Test searching for venues.
  */
 public function testSearchVenues()
 {
     $body = '{"meta": {"code": 200, "requestId": "234234"},"response": {"venues": [{"id": "430d0a00f964a5203e271fe3", "name": "Brooklyn Bridge Park"}, {"id": "430d0a00f964a5203e271fe3", "name": "Brooklyn Bridge Park"}]}}';
     $venue = $this->getMockBuilder(Venue::class)->disableOriginalConstructor()->getMock();
     $venueFactory = $this->getMockVenueFactory();
     $venueFactory->expects($this->exactly(2))->method('create')->willReturn($venue);
     $client = $this->getClient($this->getMockResponse($body), $venueFactory);
     $venues = $client->search(Search::createWithPlace('Chicago, IL'));
     $this->assertCount(2, $venues);
     $this::assertEquals([$venue, $venue], $venues);
     $this->expectException(InvalidResponseException::class);
     $client = $this->getClient($this->getMockResponse('{"meta": {"invalid": "content"}}'));
     $client->search(Search::createWithPlace('Chicago, IL'));
 }