forked from studiofrenetic/laravel-formatter
-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
240 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,67 @@ | ||
<?php namespace SoapBox\Formatter\Test\Parsers; | ||
|
||
use stdClass; | ||
use SoapBox\Formatter\Test\TestCase; | ||
use SoapBox\Formatter\Parsers\Parser; | ||
use SoapBox\Formatter\Parsers\ArrayParser; | ||
use SoapBox\Formatter\Parsers\Parser; | ||
use SoapBox\Formatter\Test\TestCase; | ||
use stdClass; | ||
|
||
class ArrayParserTest extends TestCase { | ||
class ArrayParserTest extends TestCase | ||
{ | ||
|
||
public function testArrayParserIsInstanceOfParserInterface() { | ||
$parser = new ArrayParser(new \stdClass); | ||
$this->assertTrue($parser instanceof Parser); | ||
} | ||
public function testArrayParserIsInstanceOfParserInterface() | ||
{ | ||
$parser = new ArrayParser(new \stdClass); | ||
$this->assertTrue($parser instanceof Parser); | ||
} | ||
|
||
public function testConstructorAcceptsSerializedArray() { | ||
$expected = [0, 1, 2]; | ||
$parser = new ArrayParser(serialize($expected)); | ||
$this->assertEquals($expected, $parser->toArray()); | ||
} | ||
public function testConstructorAcceptsSerializedArray() | ||
{ | ||
$expected = [0, 1, 2]; | ||
$parser = new ArrayParser(serialize($expected)); | ||
$this->assertEquals($expected, $parser->toArray()); | ||
} | ||
|
||
public function testConstructorAcceptsObject() { | ||
$expected = ['foo' => 'bar']; | ||
$input = new stdClass; | ||
$input->foo = 'bar'; | ||
$parser = new ArrayParser($input); | ||
$this->assertEquals($expected, $parser->toArray()); | ||
} | ||
public function testConstructorAcceptsObject() | ||
{ | ||
$expected = ['foo' => 'bar']; | ||
$input = new stdClass; | ||
$input->foo = 'bar'; | ||
$parser = new ArrayParser($input); | ||
$this->assertEquals($expected, $parser->toArray()); | ||
} | ||
|
||
/** | ||
* @expectedException InvalidArgumentException | ||
*/ | ||
public function testArrayParserThrowsExceptionWithInvalidInputOfEmptyString() { | ||
$parser = new ArrayParser(''); | ||
} | ||
|
||
public function testtoArrayReturnsArray() { | ||
$parser = new ArrayParser(serialize([0, 1, 2])); | ||
$this->assertTrue(is_array($parser->toArray())); | ||
} | ||
|
||
public function testtoJsonReturnsJsonRepresentationOfArray() { | ||
$expected = '[0,1,2]'; | ||
$parser = new ArrayParser([0, 1, 2]); | ||
$this->assertEquals($expected, $parser->toJson()); | ||
} | ||
|
||
public function testtoJsonReturnsJsonRepresentationOfNamedArray() { | ||
$expected = '{"foo":"bar"}'; | ||
$parser = new ArrayParser(['foo' => 'bar']); | ||
$this->assertEquals($expected, $parser->toJson()); | ||
} | ||
|
||
public function testtoCSVFromArrayContainingContentWithCommasWorks() { | ||
$expected = "\"0\",\"1\",\"2\",\"3\"\n\"a\",\"b\",\"c,e\",\"d\""; | ||
$parser = new ArrayParser(['a','b','c,e','d']); | ||
$this->assertEquals($expected, $parser->toCsv()); | ||
} | ||
public function testArrayParserThrowsExceptionWithInvalidInputOfEmptyString() | ||
{ | ||
$parser = new ArrayParser(''); | ||
} | ||
|
||
public function testtoArrayReturnsArray() | ||
{ | ||
$parser = new ArrayParser(serialize([0, 1, 2])); | ||
$this->assertTrue(is_array($parser->toArray())); | ||
} | ||
|
||
public function testtoJsonReturnsJsonRepresentationOfArray() | ||
{ | ||
$expected = '[0,1,2]'; | ||
$parser = new ArrayParser([0, 1, 2]); | ||
$this->assertEquals($expected, $parser->toJson()); | ||
} | ||
|
||
public function testtoJsonReturnsJsonRepresentationOfNamedArray() | ||
{ | ||
$expected = '{"foo":"bar"}'; | ||
$parser = new ArrayParser(['foo' => 'bar']); | ||
$this->assertEquals($expected, $parser->toJson()); | ||
} | ||
|
||
public function testtoCSVFromArrayContainingContentWithCommasWorks() | ||
{ | ||
$expected = "\"0\",\"1\",\"2\",\"3\"\n\"a\",\"b\",\"c,e\",\"d\""; | ||
$parser = new ArrayParser(['a', 'b', 'c,e', 'd']); | ||
$this->assertEquals($expected, $parser->toCsv()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php namespace SoapBox\Formatter\Test\Parsers; | ||
|
||
use SoapBox\Formatter\Parsers\CsvParser; | ||
use SoapBox\Formatter\Parsers\Parser; | ||
use SoapBox\Formatter\Test\TestCase; | ||
|
||
class CsvParserDelemiterTest extends TestCase | ||
{ | ||
|
||
private $simpleCsv = 'foo;boo | ||
bar;far'; | ||
|
||
public function testCsvParserIsInstanceOfParserInterface() | ||
{ | ||
$parser = new CsvParser('', ';'); | ||
$this->assertTrue($parser instanceof Parser); | ||
} | ||
|
||
/** | ||
* @expectedException InvalidArgumentException | ||
*/ | ||
public function testConstructorThrowsInvalidExecptionWhenArrayDataIsProvided() | ||
{ | ||
$parser = new CsvParser([0, 1, 3], ';'); | ||
} | ||
|
||
public function testtoArrayReturnsCsvArrayRepresentation() | ||
{ | ||
$expected = [['foo' => 'bar', 'boo' => 'far']]; | ||
$parser = new CsvParser($this->simpleCsv, ';'); | ||
$this->assertEquals($expected, $parser->toArray()); | ||
} | ||
|
||
public function testtoJsonReturnsJsonRepresentationOfNamedArray() | ||
{ | ||
$expected = '[{"foo":"bar","boo":"far"}]'; | ||
$parser = new CsvParser($this->simpleCsv, ';'); | ||
$this->assertEquals($expected, $parser->toJson()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,41 @@ | ||
<?php namespace SoapBox\Formatter\Test\Parsers; | ||
|
||
use SoapBox\Formatter\Test\TestCase; | ||
use SoapBox\Formatter\Parsers\Parser; | ||
use SoapBox\Formatter\Parsers\CsvParser; | ||
use SoapBox\Formatter\Parsers\Parser; | ||
use SoapBox\Formatter\Test\TestCase; | ||
|
||
class CsvParserTest extends TestCase { | ||
class CsvParserTest extends TestCase | ||
{ | ||
|
||
private $simpleCsv = 'foo,boo | ||
private $simpleCsv = 'foo,boo | ||
bar,far'; | ||
|
||
public function testCsvParserIsInstanceOfParserInterface() { | ||
$parser = new CsvParser(''); | ||
$this->assertTrue($parser instanceof Parser); | ||
} | ||
public function testCsvParserIsInstanceOfParserInterface() | ||
{ | ||
$parser = new CsvParser(''); | ||
$this->assertTrue($parser instanceof Parser); | ||
} | ||
|
||
/** | ||
* @expectedException InvalidArgumentException | ||
*/ | ||
public function testConstructorThrowsInvalidExecptionWhenArrayDataIsProvided() { | ||
$parser = new CsvParser([0, 1, 3]); | ||
} | ||
|
||
public function testtoArrayReturnsCsvArrayRepresentation() { | ||
$expected = [['foo' => 'bar', 'boo' => 'far']]; | ||
$parser = new CsvParser($this->simpleCsv); | ||
$this->assertEquals($expected, $parser->toArray()); | ||
} | ||
|
||
public function testtoJsonReturnsJsonRepresentationOfNamedArray() { | ||
$expected = '[{"foo":"bar","boo":"far"}]'; | ||
$parser = new CsvParser($this->simpleCsv); | ||
$this->assertEquals($expected, $parser->toJson()); | ||
} | ||
public function testConstructorThrowsInvalidExecptionWhenArrayDataIsProvided() | ||
{ | ||
$parser = new CsvParser([0, 1, 3]); | ||
} | ||
|
||
public function testtoArrayReturnsCsvArrayRepresentation() | ||
{ | ||
$expected = [['foo' => 'bar', 'boo' => 'far']]; | ||
$parser = new CsvParser($this->simpleCsv); | ||
$this->assertEquals($expected, $parser->toArray()); | ||
} | ||
|
||
public function testtoJsonReturnsJsonRepresentationOfNamedArray() | ||
{ | ||
$expected = '[{"foo":"bar","boo":"far"}]'; | ||
$parser = new CsvParser($this->simpleCsv); | ||
$this->assertEquals($expected, $parser->toJson()); | ||
} | ||
|
||
} |
Oops, something went wrong.