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

JsonHashTest::testHashRearrange()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 11
c 1
b 1
f 0
nc 1
nop 0
dl 0
loc 14
rs 9.9
1
<?php
2
3
namespace Swaggest\JsonDiff\Tests;
4
5
use Swaggest\JsonDiff\JsonDiff;
6
use Swaggest\JsonDiff\JsonHash;
7
8
class JsonHashTest extends \PHPUnit_Framework_TestCase
9
{
10
    public function testHash()
11
    {
12
        $h1 = (new JsonHash())->xorHash(json_decode('{"data": [{"A": 1},{"B": 2}]}'));
13
        $h2 = (new JsonHash())->xorHash(json_decode('{"data": [{"B": 2},{"A": 1}]}'));
14
        $h3 = (new JsonHash())->xorHash(json_decode('{"data": [{"B": 3},{"A": 2}]}'));
15
16
        $this->assertNotEmpty($h1);
17
        $this->assertNotEmpty($h2);
18
        $this->assertNotEmpty($h3);
19
        $this->assertNotEquals($h1, $h2);
20
        $this->assertNotEquals($h1, $h3);
21
    }
22
23
    public function testHashRearrange()
24
    {
25
        $h1 = (new JsonHash(JsonDiff::REARRANGE_ARRAYS))
26
            ->xorHash(json_decode('{"data": [{"A": 1},{"B": 2}]}'));
27
        $h2 = (new JsonHash(JsonDiff::REARRANGE_ARRAYS))
28
            ->xorHash(json_decode('{"data": [{"B": 2},{"A": 1}]}'));
29
        $h3 = (new JsonHash(JsonDiff::REARRANGE_ARRAYS))
30
            ->xorHash(json_decode('{"data": [{"B": 3},{"A": 2}]}'));
31
32
        $this->assertNotEmpty($h1);
33
        $this->assertNotEmpty($h2);
34
        $this->assertNotEmpty($h3);
35
        $this->assertEquals($h1, $h2);
36
        $this->assertNotEquals($h1, $h3);
37
    }
38
}