Passed
Push — master ( b0f0bc...e7fcd7 )
by ma
02:00
created

UniqueIdTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
c 1
b 0
f 0
dl 0
loc 42
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testCreateId() 0 8 1
A testIsValidId() 0 10 1
A testParseId() 0 11 1
A setUp() 0 3 1
1
<?php
2
3
use PHPUnit\Framework\TestCase;
4
use tinymeng\tools\UniqueId;
5
6
class UniqueIdTest extends TestCase
7
{
8
    protected $uniqueId;
9
10
    protected function setUp(): void
11
    {
12
        $this->uniqueId = UniqueId::getInstance();
13
    }
14
15
    public function testCreateId()
16
    {
17
        $center = 5;
18
        $node = 10;
19
        $source = "test_source";
20
        $id = $this->uniqueId->createId($center, $node, $source);
21
        $this->assertNotNull($id);
22
        $this->assertTrue(is_int($id));
23
    }
24
25
    public function testParseId()
26
    {
27
        $center = 5;
28
        $node = 10;
29
        $source = "test_source";
30
        $id = $this->uniqueId->createId($center, $node, $source);
31
        $parsedId = $this->uniqueId->parseId($id);
32
        $this->assertEquals($center, $parsedId['center']);
33
        $this->assertEquals($node, $parsedId['node']);
34
        $this->assertTrue(is_numeric($parsedId['time']));
35
        $this->assertTrue(is_numeric($parsedId['rand']));
36
    }
37
38
    public function testIsValidId()
39
    {
40
        $center = 5;
41
        $node = 10;
42
        $source = "test_source";
43
        $id = $this->uniqueId->createId($center, $node, $source);
44
        $this->assertTrue($this->uniqueId->isValidId($id));
45
46
        $invalidId = 1234567890123456789;
47
        $this->assertTrue($this->uniqueId->isValidId($invalidId));
48
    }
49
}
50