Skip to content

Commit 73ff793

Browse files
committed
cast booleans to strings on the api request get
1 parent 80d1c52 commit 73ff793

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

Tests/APITest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,4 +194,22 @@ function test_you_can_get_an_individual_group()
194194
$this->assertEquals(1, $group->id);
195195
$this->assertArraySubset(['id'=>1],$group->toArray());
196196
}
197+
198+
function test_boolean_values_are_converted_to_strings_on_get()
199+
{
200+
$mockResponder = new MockResponder;
201+
$mock = new MockHandler([
202+
new Response(200,[],$mockResponder->bulletins()),
203+
]);
204+
$handler = HandlerStack::create($mock);
205+
206+
$server = new API();
207+
$request = new ModelRequest(Bulletin::class,['IsDeleted'=>true,'ZoneID'=>'5']);
208+
$group = $server
209+
->addMockHandler($handler)
210+
->connect('server','username','password')
211+
->get($request);
212+
213+
$this->assertEquals('server/carouselapi/v1/bulletins?IsDeleted=true&ZoneID=5', (string) $mock->getLastRequest()->getUri());
214+
}
197215
}

src/Requests/APIRequest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ public function __construct(Client $client, $handler, $options=[])
1818
}
1919

2020
public function get($path, Array $queryParams=[]){
21+
$queryParams = collect($queryParams)->map(function($param){
22+
if(is_bool($param)){
23+
return ($param)?'true':'false';
24+
}
25+
return $param;
26+
})->toArray();
27+
2128
try{
2229
$options = $this->options;
2330
$options['query'] = $queryParams;

0 commit comments

Comments
 (0)