Passed
Pull Request — master (#42)
by Viacheslav
02:53 queued 10s
created

Issue9Test::testPatchApply()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 13
rs 9.9332
1
<?php
2
3
namespace Swaggest\JsonDiff\Tests\Issues;
4
5
use Swaggest\JsonDiff\Exception;
6
use Swaggest\JsonDiff\JsonDiff;
7
use Swaggest\JsonDiff\JsonPatch;
8
9
/**
10
 * @see https://github.com/swaggest/json-diff/issues/9
11
 */
12
class Issue9Test extends \PHPUnit_Framework_TestCase
13
{
14
    public function testPatchApply()
15
    {
16
        $old = json_decode(json_encode(["emptyObject" => []]));
17
        $new = json_decode(json_encode(["emptyObject" => ["notEmpty"=>"value"]]));
18
        $diff = new JsonDiff($old, $new);
19
        $patch = $diff->getPatch();
20
        $this->assertNotEquals($new, $old);
21
        $patch->apply($old);
22
        $this->assertEquals($new, $old);
23
24
        $old = json_decode(json_encode(["emptyObject" => []]));
25
        $this->setExpectedException(get_class(new Exception()), 'Invalid key for array operation');
26
        $patch->setFlags(JsonPatch::STRICT_MODE)->apply($old);
27
    }
28
} 
29