Completed
Push — master ( 67e465...aa77c9 )
by Alejandro
13s queued 10s
created

StringUtilsTraitTest::generatesUuidV4()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace ShlinkioTest\Shlink\Common\Util;
5
6
use PHPUnit\Framework\TestCase;
7
use Shlinkio\Shlink\Common\Util\StringUtilsTrait;
8
use function strlen;
9
10
class StringUtilsTraitTest extends TestCase
11
{
12
    use StringUtilsTrait;
13
14
    /**
15
     * @test
16
     * @dataProvider provideLengths
17
     */
18
    public function generateRandomStringGeneratesStringOfProvidedLength(int $length)
19
    {
20
        $this->assertEquals($length, strlen($this->generateRandomString($length)));
21
    }
22
23
    public function provideLengths(): array
24
    {
25
        return [
26
            [1],
27
            [10],
28
            [15],
29
        ];
30
    }
31
32
    /**
33
     * @test
34
     */
35
    public function generatesUuidV4()
36
    {
37
        $uuidPattern = '/[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}/';
38
39
        $this->assertRegExp($uuidPattern, $this->generateV4Uuid());
40
        $this->assertRegExp($uuidPattern, $this->generateV4Uuid());
41
        $this->assertRegExp($uuidPattern, $this->generateV4Uuid());
42
        $this->assertRegExp($uuidPattern, $this->generateV4Uuid());
43
        $this->assertRegExp($uuidPattern, $this->generateV4Uuid());
44
    }
45
}
46