JsonFileTest::testJsonError()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace Modera\UpgradeBundle\Tests\Unit\Entity;
4
5
use Modera\UpgradeBundle\Json\JsonFile;
6
7
/**
8
 * @author    Sergei Vizel <[email protected]>
9
 * @copyright 2014 Modera Foundation
10
 */
11
class JsonFileTest extends \PHPUnit_Framework_TestCase
12
{
13
    /**
14
     * @expectedException RuntimeException
15
     */
16
    public function testFailureRead()
17
    {
18
        $jsonFile = new JsonFile(__DIR__.'/undefined.json');
19
        $jsonFile->read();
20
    }
21
22
    /**
23
     * @expectedException RuntimeException
24
     */
25
    public function testJsonError()
26
    {
27
        $jsonFile = new JsonFile(__DIR__.'/test_error.json');
28
        $jsonFile->read();
29
    }
30
31
    public function testSuccessfulRead()
32
    {
33
        $jsonFile = new JsonFile(__DIR__.'/test_read.json');
34
        $data = $jsonFile->read();
35
        $this->assertEquals(array('test' => 'test'), $data);
36
    }
37
38
    /**
39
     * @expectedException RuntimeException
40
     */
41
    public function testFailureWrite()
42
    {
43
        $jsonFile = new JsonFile(__DIR__.'/undefined/test2.json');
44
        $jsonFile->write(array('failure' => 'failure'));
45
    }
46
47
    public function testSuccessfulWrite()
48
    {
49
        $jsonFile = new JsonFile(__DIR__.'/test_write.json');
50
        $data = array('test' => 'test');
51
        $jsonFile->write($data);
52
        $this->assertEquals($data, $jsonFile->read());
53
        unlink(__DIR__.'/test_write.json');
54
    }
55
}
56