|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Sylius package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Paweł Jędrzejewski |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace spec\Sylius\Component\Resource\Generator; |
|
15
|
|
|
|
|
16
|
|
|
use PhpSpec\ObjectBehavior; |
|
17
|
|
|
use Sylius\Component\Resource\Generator\RandomnessGenerator; |
|
18
|
|
|
use Sylius\Component\Resource\Generator\RandomnessGeneratorInterface; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @author Jan Góralski <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
|
final class RandomnessGeneratorSpec extends ObjectBehavior |
|
24
|
|
|
{ |
|
25
|
|
|
function it_implements_randomness_generator_interface(): void |
|
26
|
|
|
{ |
|
27
|
|
|
$this->shouldImplement(RandomnessGeneratorInterface::class); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
function it_generates_random_uri_safe_string_of_length(): void |
|
31
|
|
|
{ |
|
32
|
|
|
$length = 9; |
|
33
|
|
|
|
|
34
|
|
|
$this->generateUriSafeString($length)->shouldBeString(); |
|
35
|
|
|
$this->generateUriSafeString($length)->shouldHaveLength($length); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
function it_generates_random_numeric_string_of_length(): void |
|
39
|
|
|
{ |
|
40
|
|
|
$length = 12; |
|
41
|
|
|
|
|
42
|
|
|
$this->generateNumeric($length)->shouldBeString(); |
|
43
|
|
|
$this->generateNumeric($length)->shouldBeNumeric(); |
|
44
|
|
|
$this->generateNumeric($length)->shouldHaveLength($length); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
function it_generates_random_int_in_range(): void |
|
48
|
|
|
{ |
|
49
|
|
|
$min = 12; |
|
50
|
|
|
$max = 2000000; |
|
51
|
|
|
|
|
52
|
|
|
$this->generateInt($min, $max)->shouldBeInt(); |
|
53
|
|
|
$this->generateInt($min, $max)->shouldBeInRange($min, $max); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* {@inheritdoc} |
|
58
|
|
|
*/ |
|
59
|
|
|
public function getMatchers(): array |
|
60
|
|
|
{ |
|
61
|
|
|
return [ |
|
62
|
|
|
'haveLength' => function($subject, $length) { |
|
63
|
|
|
return $length === strlen($subject); |
|
64
|
|
|
}, |
|
65
|
|
|
'beInRange' => function($subject, $min, $max) { |
|
66
|
|
|
return $subject >= $min && $subject <= $max; |
|
67
|
|
|
} |
|
68
|
|
|
]; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|