public function testMethod() { // Check if everything is ok $original_array = array('test', 'test2'); $xml = Format::factory($original_array)->to_json(); $this->assertEquals('["test","test2"]', $xml); }
/** * Test for Format::factory($foo)->to_csv() * * @test */ public function test_to_csv() { $csv = 'field1,field2,field3 "Value 1","35","123123" "Value 1","Value line 2","Value 3"'; $this->assertEquals($csv, Format::factory(static::$data)->to_csv()); }
/** * Response * * Takes pure data and optionally a status code, then creates the response * * @param array * @param int */ protected function response($data = array(), $http_code = 200) { if (empty($data)) { $this->response->status = 404; return; } $this->response->status = $http_code; // If the format method exists, call and return the output in that format if (method_exists('Format', 'to_' . $this->request->format)) { // Set the correct format header $this->response->set_header('Content-Type', $this->_supported_formats[$this->request->format]); $this->response->body(Format::factory($data)->{'to_' . $this->request->format}()); } else { $this->response->body((string) $data); } }
/** * Test for Format::factory($foo)->to_csv() * * @test * @dataProvider array_provider */ public function test_to_csv($array, $csv) { $this->assertEquals($csv, Format::factory($array)->to_csv()); }