public function testEncode() { $iniString = file_get_contents(dirname(__FILE__) . '/ini/output.ini'); $input = $this->getData(); $ini = Encode::toIni($input); $this->assertEquals($iniString, $ini->load()); }
/** * @expectedException InvalidArgumentException */ public function testCallbackEvent() { $input = $this->generageArray(); $json = Encode::toJsonp('foo|bar', $input)->on(\Serializers\Events::JSONP_VALID_CALLBACK, function ($callback) { return false; }); $json->load(true); }
public function testSerialize() { $input = $this->generageArray(); $json = Encode::toJson($input)->on(\Serializers\Events::JSON_SERIALIZE, function ($input) { $input['a'] = 'foo'; $input['g'] = 'bar'; return $input; }); json_decode($json->load()); $this->assertEquals(json_last_error(), JSON_ERROR_NONE); }
/** * Transform to INI * * @return \Serializers\Encoders\Ini * * @since 1.0 */ public function toIni() { $ini = Encode::toIni($this->toArray()); return $ini; }
/** * Transform to YAML * * @param array $config - additional configuration * * @return \Serializers\Encoders\Yaml * * @since 1.0 */ public function toYaml(array $config = array()) { $yaml = Encode::toYaml($this->toArray(), $config); return $yaml; }
/** * Parse to JSON and return instance of JSON Encoder * * @param array $config - configuration * * @return \Serializers\Encoders\Json * * @since 1.0 */ public function toJSON(array $config = array()) { $json = Encode::toJson($this->data, $config); return $json; }
/** * Tests bad element name, e.g numeric indexes in array * * @expectedException RuntimeException */ public function testEncodeBadInput() { $input = array_values($this->generageArray()); $xml = Encode::toXml('root', $input); $xml->load(); }