|
8 | 8 | class ObjectDriverTest extends TestCase |
9 | 9 | { |
10 | 10 | /** @test */ |
11 | | - public function it_can_serialize_an_object() |
| 11 | + public function it_can_serialize_a_string() |
| 12 | + { |
| 13 | + $driver = new ObjectDriver(); |
| 14 | + |
| 15 | + $this->assertEquals('"foo"', $driver->serialize('foo')); |
| 16 | + } |
| 17 | + |
| 18 | + /** @test */ |
| 19 | + public function it_can_serialize_an_integer() |
| 20 | + { |
| 21 | + $driver = new ObjectDriver(); |
| 22 | + |
| 23 | + $this->assertEquals('1', $driver->serialize(1)); |
| 24 | + } |
| 25 | + |
| 26 | + /** @test */ |
| 27 | + public function it_can_serialize_a_float() |
| 28 | + { |
| 29 | + $driver = new ObjectDriver(); |
| 30 | + |
| 31 | + $this->assertEquals('1.5', $driver->serialize(1.5)); |
| 32 | + } |
| 33 | + |
| 34 | + /** @test */ |
| 35 | + public function it_can_serialize_an_associative_array() |
| 36 | + { |
| 37 | + $driver = new ObjectDriver(); |
| 38 | + |
| 39 | + $expected = <<<'JSON' |
| 40 | +{ |
| 41 | + "foo": { |
| 42 | + "bar": "baz" |
| 43 | + } |
| 44 | +} |
| 45 | +JSON; |
| 46 | + |
| 47 | + $this->assertEquals($expected, $driver->serialize(['foo' => ['bar' => 'baz']])); |
| 48 | + } |
| 49 | + |
| 50 | + /** @test */ |
| 51 | + public function it_can_serialize_an_indexed_array_without_keys() |
| 52 | + { |
| 53 | + $driver = new ObjectDriver(); |
| 54 | + |
| 55 | + $expected = <<<'JSON' |
| 56 | +[ |
| 57 | + "foo", |
| 58 | + "bar" |
| 59 | +] |
| 60 | +JSON; |
| 61 | + |
| 62 | + $this->assertEquals($expected, $driver->serialize(['foo', 'bar'])); |
| 63 | + } |
| 64 | + |
| 65 | + /** @test */ |
| 66 | + public function it_can_serialize_a_simple_object() |
| 67 | + { |
| 68 | + $driver = new ObjectDriver(); |
| 69 | + |
| 70 | + $expected = <<<'JSON' |
| 71 | +{ |
| 72 | + "foo": "bar" |
| 73 | +} |
| 74 | +JSON; |
| 75 | + |
| 76 | + $this->assertEquals($expected, $driver->serialize((object) ['foo' => 'bar'])); |
| 77 | + } |
| 78 | + |
| 79 | + /** @test */ |
| 80 | + public function it_can_serialize_a_class_instance() |
12 | 81 | { |
13 | 82 | $driver = new ObjectDriver(); |
14 | 83 |
|
|
0 commit comments