|
1 | 1 | <?php namespace SoapBox\Formatter\Test\Parsers; |
2 | 2 |
|
3 | | -use stdClass; |
4 | | -use SoapBox\Formatter\Test\TestCase; |
5 | | -use SoapBox\Formatter\Parsers\Parser; |
6 | 3 | use SoapBox\Formatter\Parsers\ArrayParser; |
| 4 | +use SoapBox\Formatter\Parsers\Parser; |
| 5 | +use SoapBox\Formatter\Test\TestCase; |
| 6 | +use stdClass; |
7 | 7 |
|
8 | | -class ArrayParserTest extends TestCase { |
| 8 | +class ArrayParserTest extends TestCase |
| 9 | +{ |
9 | 10 |
|
10 | | - public function testArrayParserIsInstanceOfParserInterface() { |
11 | | - $parser = new ArrayParser(new \stdClass); |
12 | | - $this->assertTrue($parser instanceof Parser); |
13 | | - } |
| 11 | + public function testArrayParserIsInstanceOfParserInterface() |
| 12 | + { |
| 13 | + $parser = new ArrayParser(new \stdClass); |
| 14 | + $this->assertTrue($parser instanceof Parser); |
| 15 | + } |
14 | 16 |
|
15 | | - public function testConstructorAcceptsSerializedArray() { |
16 | | - $expected = [0, 1, 2]; |
17 | | - $parser = new ArrayParser(serialize($expected)); |
18 | | - $this->assertEquals($expected, $parser->toArray()); |
19 | | - } |
| 17 | + public function testConstructorAcceptsSerializedArray() |
| 18 | + { |
| 19 | + $expected = [0, 1, 2]; |
| 20 | + $parser = new ArrayParser(serialize($expected)); |
| 21 | + $this->assertEquals($expected, $parser->toArray()); |
| 22 | + } |
20 | 23 |
|
21 | | - public function testConstructorAcceptsObject() { |
22 | | - $expected = ['foo' => 'bar']; |
23 | | - $input = new stdClass; |
24 | | - $input->foo = 'bar'; |
25 | | - $parser = new ArrayParser($input); |
26 | | - $this->assertEquals($expected, $parser->toArray()); |
27 | | - } |
| 24 | + public function testConstructorAcceptsObject() |
| 25 | + { |
| 26 | + $expected = ['foo' => 'bar']; |
| 27 | + $input = new stdClass; |
| 28 | + $input->foo = 'bar'; |
| 29 | + $parser = new ArrayParser($input); |
| 30 | + $this->assertEquals($expected, $parser->toArray()); |
| 31 | + } |
28 | 32 |
|
29 | 33 | /** |
30 | 34 | * @expectedException InvalidArgumentException |
31 | 35 | */ |
32 | | - public function testArrayParserThrowsExceptionWithInvalidInputOfEmptyString() { |
33 | | - $parser = new ArrayParser(''); |
34 | | - } |
35 | | - |
36 | | - public function testtoArrayReturnsArray() { |
37 | | - $parser = new ArrayParser(serialize([0, 1, 2])); |
38 | | - $this->assertTrue(is_array($parser->toArray())); |
39 | | - } |
40 | | - |
41 | | - public function testtoJsonReturnsJsonRepresentationOfArray() { |
42 | | - $expected = '[0,1,2]'; |
43 | | - $parser = new ArrayParser([0, 1, 2]); |
44 | | - $this->assertEquals($expected, $parser->toJson()); |
45 | | - } |
46 | | - |
47 | | - public function testtoJsonReturnsJsonRepresentationOfNamedArray() { |
48 | | - $expected = '{"foo":"bar"}'; |
49 | | - $parser = new ArrayParser(['foo' => 'bar']); |
50 | | - $this->assertEquals($expected, $parser->toJson()); |
51 | | - } |
52 | | - |
53 | | - public function testtoCSVFromArrayContainingContentWithCommasWorks() { |
54 | | - $expected = "\"0\",\"1\",\"2\",\"3\"\n\"a\",\"b\",\"c,e\",\"d\""; |
55 | | - $parser = new ArrayParser(['a','b','c,e','d']); |
56 | | - $this->assertEquals($expected, $parser->toCsv()); |
57 | | - } |
| 36 | + public function testArrayParserThrowsExceptionWithInvalidInputOfEmptyString() |
| 37 | + { |
| 38 | + $parser = new ArrayParser(''); |
| 39 | + } |
| 40 | + |
| 41 | + public function testtoArrayReturnsArray() |
| 42 | + { |
| 43 | + $parser = new ArrayParser(serialize([0, 1, 2])); |
| 44 | + $this->assertTrue(is_array($parser->toArray())); |
| 45 | + } |
| 46 | + |
| 47 | + public function testtoJsonReturnsJsonRepresentationOfArray() |
| 48 | + { |
| 49 | + $expected = '[0,1,2]'; |
| 50 | + $parser = new ArrayParser([0, 1, 2]); |
| 51 | + $this->assertEquals($expected, $parser->toJson()); |
| 52 | + } |
| 53 | + |
| 54 | + public function testtoJsonReturnsJsonRepresentationOfNamedArray() |
| 55 | + { |
| 56 | + $expected = '{"foo":"bar"}'; |
| 57 | + $parser = new ArrayParser(['foo' => 'bar']); |
| 58 | + $this->assertEquals($expected, $parser->toJson()); |
| 59 | + } |
| 60 | + |
| 61 | + public function testtoCSVFromArrayContainingContentWithCommasWorks() |
| 62 | + { |
| 63 | + $expected = "\"0\",\"1\",\"2\",\"3\"\n\"a\",\"b\",\"c,e\",\"d\""; |
| 64 | + $parser = new ArrayParser(['a', 'b', 'c,e', 'd']); |
| 65 | + $this->assertEquals($expected, $parser->toCsv()); |
| 66 | + } |
58 | 67 | } |
0 commit comments