diff --git a/src/RollbarJsHelper.php b/src/RollbarJsHelper.php index 1a602f4b..2d6ec170 100644 --- a/src/RollbarJsHelper.php +++ b/src/RollbarJsHelper.php @@ -61,7 +61,7 @@ public function addJs($headers = null, $nonce = null, $customJs = "") */ public function configJsTag() { - return "var _rollbarConfig = " . json_encode($this->config, JSON_FORCE_OBJECT) . ";"; + return "var _rollbarConfig = " . json_encode((object)$this->config) . ";"; } /** diff --git a/tests/JsHelperTest.php b/tests/JsHelperTest.php index 6c421689..4c140d24 100644 --- a/tests/JsHelperTest.php +++ b/tests/JsHelperTest.php @@ -226,13 +226,11 @@ public function scriptTagProvider() ); } - public function testConfigJsTag() + /** + * @dataProvider configJsTagProvider + */ + public function testConfigJsTag($config, $expectedJson) { - $config = array( - 'config1' => 'value 1' - ); - - $expectedJson = json_encode($config); $expected = "var _rollbarConfig = $expectedJson;"; $helper = new RollbarJsHelper($config); @@ -241,6 +239,18 @@ public function testConfigJsTag() $this->assertEquals($expected, $result); } + public function configJsTagProvider() + { + return array( + array(array(), '{}'), + array(array('config1' => 'value 1'), '{"config1":"value 1"}'), + array( + array('hostBlackList' => array('example.com', 'badhost.com')), + '{"hostBlackList":["example.com","badhost.com"]}' + ), + ); + } + /** * @dataProvider addJsProvider */