Passed
Push — master ( b649b5...b34030 )
by Sebastian
04:07
created

JsonTest::testReadAssoc()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
/**
3
 * This file is part of CaptainHook.
4
 *
5
 * (c) Sebastian Feldmann <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace CaptainHook\Storage\File;
11
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