Passed
Pull Request — master (#36)
by
unknown
03:02
created

ToJsonTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validateJsonWithoutHexing() 0 15 1
A validateJsonWithHexing() 0 15 1
1
<?php
2
3
namespace MaksimM\CompositePrimaryKeys\Tests;
4
5
use MaksimM\CompositePrimaryKeys\Tests\Stubs\TestBinaryUser;
6
use MaksimM\CompositePrimaryKeys\Tests\Stubs\TestBinaryUserHex;
7
8
class ToJsonTest extends CompositeKeyBaseUnit
9
{
10
    /** @test */
11
    public function validateJsonWithoutHexing()
12
    {
13
        $userId = md5(20000, true);
14
        /**
15
         * @var $model TestBinaryUser
16
         */
17
        $model = TestBinaryUser::find([
18
            'user_id'         => $userId,
19
            'organization_id' => 100,
20
        ]);
21
        $this->assertNotNull($model);
22
        $this->assertInstanceOf(TestBinaryUser::class, $model);
23
        $json = $model->toJson();
24
        $array = json_decode($json, true);
25
        $this->assertEquals(bin2hex($userId), $array['user_id']);
26
    }
27
28
    /** @test */
29
    public function validateJsonWithHexing()
30
    {
31
        $userId = md5(20000);
32
        /**
33
         * @var $model TestBinaryUserHex
34
         */
35
        $model = TestBinaryUserHex::find([
36
            'user_id'         => $userId,
37
            'organization_id' => 100,
38
        ]);
39
        $this->assertNotNull($model);
40
        $this->assertInstanceOf(TestBinaryUserHex::class, $model);
41
        $json = $model->toJson();
42
        $array = json_decode($json, true);
43
        $this->assertEquals(strtoupper($userId), $array['user_id']);
44
    }
45
}
46