File tree Expand file tree Collapse file tree 4 files changed +103
-0
lines changed Expand file tree Collapse file tree 4 files changed +103
-0
lines changed Original file line number Diff line number Diff line change @@ -177,4 +177,20 @@ public function getAllData(): array
177177 {
178178 return $ this ->data ;
179179 }
180+
181+ /**
182+ * String for logging. This is also a unique key for the query
183+ *
184+ * @return string
185+ */
186+ public function __toString ()
187+ {
188+ return sprintf ('GeocodeQuery: %s ' , json_encode ([
189+ 'text ' => $ this ->getText (),
190+ 'bounds ' => $ this ->getBounds () ? $ this ->getBounds ()->toArray () : 'null ' ,
191+ 'locale ' => $ this ->getLocale (),
192+ 'limit ' => $ this ->getLimit (),
193+ 'data ' => $ this ->getAllData (),
194+ ]));
195+ }
180196}
Original file line number Diff line number Diff line change @@ -155,4 +155,20 @@ public function getAllData(): array
155155 {
156156 return $ this ->data ;
157157 }
158+
159+ /**
160+ * String for logging. This is also a unique key for the query
161+ *
162+ * @return string
163+ */
164+ public function __toString ()
165+ {
166+ return sprintf ('ReverseQuery: %s ' , json_encode ([
167+ 'lat ' => $ this ->getCoordinates ()->getLatitude (),
168+ 'lng ' => $ this ->getCoordinates ()->getLongitude (),
169+ 'locale ' => $ this ->getLocale (),
170+ 'limit ' => $ this ->getLimit (),
171+ 'data ' => $ this ->getAllData (),
172+ ]));
173+ }
158174}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /*
4+ * This file is part of the Geocoder package.
5+ * For the full copyright and license information, please view the LICENSE
6+ * file that was distributed with this source code.
7+ *
8+ * @license MIT License
9+ */
10+
11+ namespace Geocoder \Tests ;
12+
13+ use Geocoder \Query \GeocodeQuery ;
14+ use PHPUnit \Framework \TestCase ;
15+
16+ /**
17+ * @author Tobias Nyholm <tobias.nyholm@gmail.com>
18+ */
19+ class GeocodeQueryTest extends TestCase
20+ {
21+ public function testToString ()
22+ {
23+ $ query = GeocodeQuery::create ('foo ' );
24+ $ query = $ query ->withLocale ('en ' );
25+ $ query = $ query ->withLimit (3 );
26+ $ query = $ query ->withData ('name ' , 'value ' );
27+
28+ $ string = $ query ->__toString ();
29+ $ this ->assertContains ('GeocodeQuery ' , $ string );
30+ $ this ->assertContains ('"text":"foo" ' , $ string );
31+ $ this ->assertContains ('"locale":"en" ' , $ string );
32+ $ this ->assertContains ('"limit":3 ' , $ string );
33+ $ this ->assertContains ('"name":"value" ' , $ string );
34+ }
35+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /*
4+ * This file is part of the Geocoder package.
5+ * For the full copyright and license information, please view the LICENSE
6+ * file that was distributed with this source code.
7+ *
8+ * @license MIT License
9+ */
10+
11+ namespace Geocoder \Tests ;
12+
13+ use Geocoder \Query \ReverseQuery ;
14+ use PHPUnit \Framework \TestCase ;
15+
16+ /**
17+ * @author Tobias Nyholm <tobias.nyholm@gmail.com>
18+ */
19+ class ReverseQueryTest extends TestCase
20+ {
21+ public function testToString ()
22+ {
23+ $ query = ReverseQuery::fromCoordinates (1 , 2 );
24+ $ query = $ query ->withLocale ('en ' );
25+ $ query = $ query ->withLimit (3 );
26+ $ query = $ query ->withData ('name ' , 'value ' );
27+
28+ $ string = $ query ->__toString ();
29+ $ this ->assertContains ('ReverseQuery ' , $ string );
30+ $ this ->assertContains ('"lat":1 ' , $ string );
31+ $ this ->assertContains ('"lng":2 ' , $ string );
32+ $ this ->assertContains ('"locale":"en" ' , $ string );
33+ $ this ->assertContains ('"limit":3 ' , $ string );
34+ $ this ->assertContains ('"name":"value" ' , $ string );
35+ }
36+ }
You can’t perform that action at this time.
0 commit comments