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

JsonHashTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 20
c 1
b 1
f 0
dl 0
loc 29
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testHash() 0 11 1
A testHashRearrange() 0 14 1
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
}