@@ -32,6 +32,7 @@ protected function defineEnvironment($app)
3232 $ app ['config ' ]->set ('settings.fillable ' , []);
3333 $ app ['config ' ]->set ('settings.cache ' , true );
3434 $ app ['config ' ]->set ('settings.hidden ' , []);
35+ $ app ['config ' ]->set ('settings.cast ' , []);
3536 }
3637
3738 /**
@@ -283,7 +284,6 @@ public function it_can_return_default_string_settings()
283284 $ settings = Settings::get ('baz ' , 'test ' );
284285
285286 $ this ->assertEquals ('test ' , $ settings , json_encode ($ settings ));
286-
287287 }
288288
289289 /** @test */
@@ -299,7 +299,6 @@ public function it_can_return_default_array_settings()
299299 $ settings = Settings::get (['foo ' , 'bar ' , 'not_set ' ], ['not_set ' => 'test ' ]);
300300
301301 $ this ->assertEquals ('test ' , $ settings ['not_set ' ], json_encode ($ settings ));
302-
303302 }
304303
305304 /** @test */
@@ -308,18 +307,31 @@ public function it_can_return_default_all_settings()
308307 $ settings = Settings::get (['not_set ' ], ['not_set ' => 'test ' ]);
309308
310309 $ this ->assertEquals ('test ' , $ settings ['not_set ' ], json_encode ($ settings ));
311-
312310 }
313311
314312 /** @test */
315- public function it_encodes_arrays_to_json ()
313+ public function it_casts_arrays ()
316314 {
317315 $ this ->app ['config ' ]->set ('settings.fillable ' , ['* ' ]);
316+ $ this ->app ['config ' ]->set ('settings.cast ' , ['array ' => 'json ' ]);
318317
319318 Settings::set (['array ' => ['test ' , 'one ' , 'two ' ]]);
320319
321- $ settings = json_decode (Settings::get ('array ' ));
320+ $ settings = Settings::get ('array ' );
321+
322+ $ this ->assertIsArray ($ settings );
323+ }
324+
325+ /** @test */
326+ public function it_casts_booleans ()
327+ {
328+ $ this ->app ['config ' ]->set ('settings.fillable ' , ['* ' ]);
329+ $ this ->app ['config ' ]->set ('settings.cast ' , ['boolean ' => 'boolean ' ]);
330+
331+ Settings::set (['boolean ' => true ]);
332+
333+ $ settings = Settings::get ('boolean ' );
322334
323- $ this ->assertIsArray ($ settings , json_encode ( $ settings ) );
335+ $ this ->assertEquals ($ settings , true );
324336 }
325337}
0 commit comments