JsonFileTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 45
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testFailureRead() 0 5 1
A testJsonError() 0 5 1
A testSuccessfulRead() 0 6 1
A testFailureWrite() 0 5 1
A testSuccessfulWrite() 0 8 1
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