File tree Expand file tree Collapse file tree 3 files changed +92
-1
lines changed Expand file tree Collapse file tree 3 files changed +92
-1
lines changed Original file line number Diff line number Diff line change 20
20
"phpunit/phpunit" : " ^9.1"
21
21
},
22
22
"require-dev" : {
23
+ "egulias/email-validator" : " ^2.1 || ^3.0" ,
23
24
"giggsey/libphonenumber-for-php" : " ^8.12" ,
24
25
"hashids/hashids" : " ^4.0" ,
25
26
"league/iso3166" : " ^2.1 || ^3.0" ,
28
29
"vinkla/hashids" : " ^9.0"
29
30
},
30
31
"suggest" : {
32
+ "egulias/email-validator" : " \\ Astrotomic\\ PhpunitAssertions\\ EmailAssertions (^2.1 || ^3.0)" ,
31
33
"giggsey/libphonenumber-for-php" : " \\ Astrotomic\\ PhpunitAssertions\\ PhoneNumberAssertions (^8.12)" ,
32
34
"hashids/hashids" : " \\ Astrotomic\\ PhpunitAssertions\\ HashidAssertions (^4.0)" ,
33
35
"league/iso3166" : " \\ Astrotomic\\ PhpunitAssertions\\ CountryAssertions (^2.1 || ^3.0)" ,
48
50
}
49
51
},
50
52
"minimum-stability" : " dev" ,
51
- "prefer-stable" : true
53
+ "prefer-stable" : true ,
54
+ "scripts" : {
55
+ "post-autoload-dump" : [
56
+ " @composer validate --strict --ansi --no-interaction --quiet" ,
57
+ " @composer normalize --ansi --no-interaction --quiet" ,
58
+ " @composer thanks --ansi --no-interaction --quiet"
59
+ ]
60
+ }
52
61
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Astrotomic \PhpunitAssertions ;
4
+
5
+ use Egulias \EmailValidator \EmailValidator ;
6
+ use Egulias \EmailValidator \Validation \RFCValidation ;
7
+ use PHPUnit \Framework \Assert as PHPUnit ;
8
+
9
+ trait EmailAssertions
10
+ {
11
+ public static function assertValidLoose ($ actual ): void
12
+ {
13
+ PHPUnit::assertIsString ($ actual );
14
+ PHPUnit::assertNotFalse (filter_var ($ actual , FILTER_VALIDATE_EMAIL ));
15
+ }
16
+
17
+ public static function assertValidStrict ($ actual ): void
18
+ {
19
+ PHPUnit::assertIsString ($ actual );
20
+ PHPUnit::assertTrue ((new EmailValidator ())->isValid ($ actual , new RFCValidation ()));
21
+ }
22
+
23
+ public static function assertSameDomain (string $ expected , $ actual ): void
24
+ {
25
+ PHPUnit::assertIsString ($ actual );
26
+ [, $ domain ] = explode ('@ ' , $ actual , 2 );
27
+ PHPUnit::assertSame ($ expected , $ domain );
28
+ }
29
+
30
+ public static function assertSameLocalPart (string $ expected , $ actual ): void
31
+ {
32
+ PHPUnit::assertIsString ($ actual );
33
+ [$ localPart ] = explode ('@ ' , $ actual , 2 );
34
+ PHPUnit::assertSame ($ expected , $ localPart );
35
+ }
36
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Astrotomic \PhpunitAssertions \Tests ;
4
+
5
+ use Astrotomic \PhpunitAssertions \EmailAssertions ;
6
+
7
+ final class EmailAssertionsTest extends TestCase
8
+ {
9
+ /**
10
+ * @test
11
+ * @dataProvider hundredTimes
12
+ */
13
+ public static function it_can_validate_loose (): void
14
+ {
15
+ EmailAssertions::assertValidLoose (self ::randomString ().'@email.com ' );
16
+ }
17
+
18
+ /**
19
+ * @test
20
+ * @dataProvider hundredTimes
21
+ */
22
+ public static function it_can_validate_strict (): void
23
+ {
24
+ EmailAssertions::assertValidStrict (self ::randomString ().'@email.com ' );
25
+ }
26
+
27
+ /**
28
+ * @test
29
+ * @dataProvider hundredTimes
30
+ */
31
+ public static function it_can_validate_same_domain (): void
32
+ {
33
+ EmailAssertions::assertSameDomain ('email.com ' , self ::randomString ().'@email.com ' );
34
+ }
35
+
36
+ /**
37
+ * @test
38
+ * @dataProvider hundredTimes
39
+ */
40
+ public static function it_can_validate_same_local_part (): void
41
+ {
42
+ $ localPart = self ::randomString ();
43
+
44
+ EmailAssertions::assertSameLocalPart ($ localPart , $ localPart .'@email.com ' );
45
+ }
46
+ }
You can’t perform that action at this time.
0 commit comments