Skip to content

Commit 13f06eb

Browse files
this fixes #3
added all the necessary test cases.
1 parent 080cc9f commit 13f06eb

File tree

4 files changed

+94
-19
lines changed

4 files changed

+94
-19
lines changed

composer.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"keywords": ["laravel", "formatter", "data","convert","csv", "xml", "yaml"],
66
"homepage": "http://github.com/SoapBox/laravel-formatter",
77
"license": "MIT",
8+
"version": "1.1",
89
"authors": [
910
{
1011
"name": "Graham McCarthy",
@@ -14,7 +15,16 @@
1415
],
1516
"require": {
1617
"php": ">=5.3.0",
17-
"illuminate/support": "4.*"
18+
"illuminate/support": ">=4.0,<4.2",
19+
"illuminate/foundation": ">=4.0,<4.2",
20+
"illuminate/config": ">=4.0,<4.2",
21+
"illuminate/session": ">=4.0,<4.2",
22+
"illuminate/filesystem": ">=4.0,<4.2",
23+
"illuminate/view": ">=4.0,<4.2"
24+
},
25+
"require-dev": {
26+
"orchestra/testbench": "2.1.*",
27+
"mockery/mockery": "dev-master"
1828
},
1929
"autoload": {
2030
"psr-0": {
@@ -23,4 +33,4 @@
2333
}
2434
},
2535
"minimum-stability": "dev"
26-
}
36+
}

src/SoapBox/Formatter/Formatter.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
//namespace Formatter;
2020
namespace SoapBox\Formatter;
2121

22-
use Config, Lang;
22+
//use Config, Lang;
23+
use Illuminate\Support\Facades\Config;
24+
use Illuminate\Support\Facades\Lang;
2325

2426
/**
2527
* The Formatter Class
@@ -55,7 +57,6 @@ public static function make($data = null, $from_type = null, $attributes = array
5557
return new self($data, $from_type, $attributes);
5658
}
5759

58-
5960
/**
6061
* Should not be called directly. You should be using Formatter::make()
6162
*

src/lang/en/formatter.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
*/
1515

1616
return array(
17-
1817
'no_data' => 'No data to convert',
1918
'from_type_not_supported' => ':from_type is not a supported type to convert from.',
20-
'more_data' => 'The line :line_number contains more data fields than the heading.',
21-
'less_data' => 'The line :line_number contains less data fields than the heading.'
19+
'more_data' => 'The line :line_number contains more data fields than the heading.',
20+
'less_data' => 'The line :line_number contains less data fields than the heading.'
2221
);

tests/FormatterTest.php

Lines changed: 77 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,92 @@
11
<?php
22

3-
use SoapBox\Formatter\LaravelHtmlMinifyCompiler;
3+
use SoapBox\Formatter\Formatter;
4+
//use Mockery as m;
45

6+
class FormatterTest extends Orchestra\Testbench\TestCase {
57

6-
class FormatterTest extends PHPUnit_Framework_TestCase {
8+
public function setUp() {
9+
parent::setUp();
10+
11+
//$app = m::mock('AppMock');
12+
//$app->shouldReceive('instance')->once()->andReturn($app);
13+
14+
//Illuminate\Support\Facades\Facade::setFacadeApplication($app);
15+
//Illuminate\Support\Facades\Config::swap($config = m::mock('ConfigMock'));
16+
//Illuminate\Support\Facades\Lang::swap($lang = m::mock('ConfigLang'));
17+
18+
//$config->shouldReceive('get')->once()->with('logviewer::log_dirs')->andReturn(array('app' => 'app/storage/logs'));
19+
//$this->logviewer = new Logviewer('app', 'cgi-fcgi', '2013-06-01');
20+
}
21+
/**
22+
* A basic functional test for JSON to Array conversion
23+
*
24+
* @return void
25+
*/
26+
public function testJsonToArray() {
27+
$data = '{"foo":"bar","bar":"foo"}';
28+
$result = Formatter::make($data, 'json')->to_array();
29+
$expected = array('foo'=>'bar', 'bar'=>'foo');
30+
$this->assertEquals($expected, $result);
31+
}
732

833
/**
9-
* A basic functional test example.
34+
* A basic functional test for Array to JSON conversion
1035
*
1136
* @return void
1237
*/
13-
public function testBasicExample() {
14-
$this->assertTrue(true);
38+
public function testArrayToJson() {
39+
$data = array('foo'=>'bar', 'bar'=>'foo');
40+
41+
$result = Formatter::make($data)->to_json();
42+
$expected = '{"foo":"bar","bar":"foo"}';
43+
$this->assertEquals($expected, $result);
1544
}
1645

17-
/*
18-
public function testFormatter() {
19-
//$formatted = SoapBox\Formatter::make('hello')=>array();
20-
//var_dump($formatted);
46+
/**
47+
* A basic functional test for testJSONToXMLToArrayToJsonToArray data to array
48+
*
49+
* @return void
50+
*/
51+
public function testJSONToXMLToArrayToJsonToArray() {
52+
$data = '{"foo":"bar","bar":"foo"}';
53+
54+
$result = Formatter::make($data, 'json')->to_xml();
55+
$result = Formatter::make($result, 'xml')->to_array();
56+
$result = Formatter::make($result, 'array')->to_json();
57+
$result = Formatter::make($result, 'json')->to_array();
58+
59+
$expected = array('foo'=>'bar', 'bar'=>'foo');
60+
61+
$this->assertEquals($expected, $result);
62+
}
2163

22-
//$expected = array('hello');
23-
//$this->assertEquals($expected, $formatted);
64+
/**
65+
* A basic functional test for CSV data to array
66+
*
67+
* @return void
68+
*/
69+
public function testCSVToArray() {
70+
$data = "foo,bar,bing,bam,boom";
71+
$result = Formatter::make($data, 'csv')->to_array();
72+
$expected = array('foo'=>'bar', 'bar'=>'foo');
73+
var_dump($result);
74+
var_dump($expected);
75+
die('dead');
76+
$this->assertEquals($expected, $result);
2477
}
25-
*/
2678

79+
/**
80+
* A basic functional test for CSV data to array
81+
*
82+
* @return void
83+
*/
84+
public function testArrayToCSV() {
85+
$expected = array('foo'=>'bar', 'bar'=>'foo');
86+
$result = Formatter::make($data, 'array')->to_csv();
87+
var_dump($result);
88+
89+
$expected = "foo,bar,bing,bam,boom";
90+
$this->assertEquals($expected, $result);
91+
}
2792
}

0 commit comments

Comments
 (0)