Passed
Push — master ( 784e69...f2d35a )
by Alexander
07:36
created

RandomTest::testRandomStringValidSymbols()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Yiisoft\Security\Tests;
4
5
use PHPUnit\Framework\TestCase;
6
use Yiisoft\Security\Random;
7
8
class RandomTest extends TestCase
9
{
10
    public function testRandomStringRespectsLength(): void
11
    {
12
        $length = 21;
13
        $key = Random::string($length);
14
        $this->assertEquals($length, strlen($key));
15
    }
16
17
    public function testRandomStringValidSymbols(): void
18
    {
19
        $key = Random::string(100);
20
        $this->assertMatchesRegularExpression('/[A-Za-z0-9_-]+/', $key);
21
    }
22
23
    public function testInvalidLength(): void
24
    {
25
        $this->expectException(\InvalidArgumentException::class);
26
        Random::string(0);
27
    }
28
}
29