|
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
|
|
|
} |