1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace MinepicTests\Helpers; |
6
|
|
|
|
7
|
|
|
use Minepic\Helpers\UserDataValidator; |
8
|
|
|
use MinepicTests\TestCase; |
9
|
|
|
|
10
|
|
|
class UserDataValidatorTest extends TestCase |
11
|
|
|
{ |
12
|
|
|
public function shouldValidateUsernameDataProvider(): array |
13
|
|
|
{ |
14
|
|
|
return [ |
15
|
|
|
['ZioPino'], |
16
|
|
|
['Elon_Musk'], |
17
|
|
|
['AVeryLongUsername'], |
18
|
|
|
]; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @dataProvider shouldValidateUsernameDataProvider |
23
|
|
|
*/ |
24
|
|
|
public function testShouldValidateUsername(string $value): void |
25
|
|
|
{ |
26
|
|
|
$this->assertTrue( |
27
|
|
|
UserDataValidator::isValidUsername($value) |
28
|
|
|
); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function shouldNotValidateUsernameDataProvider(): array |
32
|
|
|
{ |
33
|
|
|
return [ |
34
|
|
|
['!LOL'], |
35
|
|
|
['EB&ACA'], |
36
|
|
|
['Invalid@Username'], |
37
|
|
|
]; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @dataProvider shouldNotValidateUsernameDataProvider |
42
|
|
|
*/ |
43
|
|
|
public function testShouldNotValidateUsername(string $value): void |
44
|
|
|
{ |
45
|
|
|
$this->assertFalse( |
46
|
|
|
UserDataValidator::isValidUsername($value) |
47
|
|
|
); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function shouldValidateUuidDataProvider(): array |
51
|
|
|
{ |
52
|
|
|
return [ |
53
|
|
|
['6257a83ef36c4ba29115f4213869d5fb'], |
54
|
|
|
['45f50155c09f4fdcb5cee30af2ebd1f0'], |
55
|
|
|
['f498513ce8c84773be26ecfc7ed5185d'], |
56
|
|
|
]; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @dataProvider shouldValidateUuidDataProvider |
61
|
|
|
*/ |
62
|
|
|
public function testShouldValidateUuid(string $value): void |
63
|
|
|
{ |
64
|
|
|
$this->assertTrue( |
65
|
|
|
UserDataValidator::isValidUuid($value) |
66
|
|
|
); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function shouldNotValidateUuidDataProvider(): array |
70
|
|
|
{ |
71
|
|
|
return [ |
72
|
|
|
['____a83ef36c4ba29115f4213869d5fb'], |
73
|
|
|
['45f50155c09f4fdcb5cee30af2e!!!!'], |
74
|
|
|
['f498513🤬84773be26ecfc7ed5185d'], |
75
|
|
|
]; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @dataProvider shouldNotValidateUuidDataProvider |
80
|
|
|
* @param mixed $value |
81
|
|
|
*/ |
82
|
|
|
public function testShouldNotValidateUuid(string $value): void |
83
|
|
|
{ |
84
|
|
|
$this->assertFalse( |
85
|
|
|
UserDataValidator::isValidUuid($value) |
86
|
|
|
); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function shouldValidateEmailDataProvider(): array |
90
|
|
|
{ |
91
|
|
|
return [ |
92
|
|
|
['[email protected]'], |
93
|
|
|
['[email protected]'], |
94
|
|
|
['[email protected]'], |
95
|
|
|
]; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @dataProvider shouldValidateEmailDataProvider |
100
|
|
|
*/ |
101
|
|
|
public function testShouldValidateEmail(string $email): void |
102
|
|
|
{ |
103
|
|
|
$this->assertTrue( |
104
|
|
|
UserDataValidator::isValidEmail($email) |
105
|
|
|
); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function shouldNotValidateEmailDataProvider(): array |
109
|
|
|
{ |
110
|
|
|
return [ |
111
|
|
|
['@[email protected]'], |
112
|
|
|
['user.test+lole_xample.com'], |
113
|
|
|
['[email protected]@lol'], |
114
|
|
|
]; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @dataProvider shouldNotValidateEmailDataProvider |
119
|
|
|
*/ |
120
|
|
|
public function testShouldNotValidateEmail(string $email): void |
121
|
|
|
{ |
122
|
|
|
$this->assertFalse( |
123
|
|
|
UserDataValidator::isValidEmail($email) |
124
|
|
|
); |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|