| Conditions | 1 |
| Paths | 1 |
| Total Lines | 28 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 17 | public function test_json_failed_encoding() |
||
| 18 | { |
||
| 19 | $stdClass = new \stdClass; |
||
| 20 | $stdClass->hello = 'there'; |
||
| 21 | |||
| 22 | $args = [ |
||
| 23 | 'integer' => 123, |
||
| 24 | 'float' => 0.17, |
||
| 25 | 'string' => 'fubar', |
||
| 26 | 'bool' => true, |
||
| 27 | 'null' => null, |
||
| 28 | 'array' => ['foo' => 'bar'], |
||
| 29 | 'stdClass' => $stdClass |
||
| 30 | ]; |
||
| 31 | |||
| 32 | $SUT = new Immutable($args); |
||
| 33 | |||
| 34 | $json = $SUT->toJSON(); |
||
| 35 | $this->assertSame('{"integer":123,"float":0.17,"string":"fubar","bool":true,"null":null,"array":{"foo":"bar"},"stdClass":{"hello":"there"}}', $json); |
||
| 36 | |||
| 37 | $expected = $args; |
||
| 38 | $expected['array'] = (object)['foo' => 'bar']; |
||
| 39 | $this->assertEquals((object)$expected, json_decode($json), 'The arrays are lost after json_decode($, false)'); |
||
| 40 | |||
| 41 | $expected['array'] = $args['array']; |
||
| 42 | $expected['stdClass'] = (array)$args['stdClass']; |
||
| 43 | |||
| 44 | $this->assertEquals($expected, json_decode($json, true), 'The objects are lost after json_decode($, true)'); |
||
| 45 | } |
||
| 47 |