1 | <?php |
||
12 | class JsonTest extends \PHPUnit_Framework_TestCase |
||
13 | { |
||
14 | /** |
||
15 | * Tests Json::read |
||
16 | */ |
||
17 | public function testReadAssoc() |
||
18 | { |
||
19 | $path = realpath(__DIR__ . '/../../../files/storage/test.json'); |
||
20 | $json = new Json($path); |
||
21 | $data = $json->readAssoc(); |
||
22 | |||
23 | $this->assertEquals('bar', $data['foo']); |
||
24 | } |
||
25 | |||
26 | /** |
||
27 | * Test Json::write |
||
28 | */ |
||
29 | public function testWrite() |
||
30 | { |
||
31 | $path = tempnam(sys_get_temp_dir(), 'json'); |
||
32 | $json = new Json($path); |
||
33 | $data = ['foo' => 'bar']; |
||
34 | $json->write($data); |
||
35 | |||
36 | $json = file_get_contents($path); |
||
37 | $load = json_decode($json, true); |
||
38 | |||
39 | unlink($path); |
||
40 | $this->assertEquals('bar', $load['foo']); |
||
41 | } |
||
42 | } |
||
43 |