-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat/add-support-for-checking-emails (#19)
* Add tests. * Update `README.md`. * Add support for validating emails. * Add "zero-to-prod/validate-email" dep. --------- Co-authored-by: david_smith <[email protected]>
- Loading branch information
1 parent
1aa3e93
commit 3713df8
Showing
21 changed files
with
398 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tests/Unit/IsEmail/Callable/InvalidEmail/BadEmailException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\IsEmail\Callable\InvalidEmail; | ||
|
||
use RuntimeException; | ||
|
||
class BadEmailException extends RuntimeException | ||
{ | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
tests/Unit/IsEmail/Callable/InvalidEmail/InvalidEmailTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\IsEmail\Callable\InvalidEmail; | ||
|
||
use PHPUnit\Framework\Attributes\Test; | ||
use Tests\TestCase; | ||
|
||
class InvalidEmailTest extends TestCase | ||
{ | ||
#[Test] public function invalid_email(): void | ||
{ | ||
$this->expectException(BadEmailException::class); | ||
User::from([ | ||
User::email => 'invalid email', | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\IsEmail\Callable\InvalidEmail; | ||
|
||
use Zerotoprod\DataModel\DataModel; | ||
use Zerotoprod\DataModel\Describe; | ||
use Zerotoprod\DataModelHelper\DataModelHelper; | ||
|
||
class User | ||
{ | ||
use DataModel; | ||
use DataModelHelper; | ||
|
||
public const email = 'email'; | ||
|
||
#[Describe([ | ||
'cast' => [self::class, 'isEmail'], | ||
'on_fail' => [self::class, 'failed'], | ||
])] | ||
public string $email; | ||
|
||
public static function failed(): string | ||
{ | ||
throw new BadEmailException(); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
tests/Unit/IsEmail/Callable/NotString/BadEmailException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\IsEmail\Callable\NotString; | ||
|
||
use RuntimeException; | ||
|
||
class BadEmailException extends RuntimeException | ||
{ | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
tests/Unit/IsEmail/Callable/NotString/NotEmailStringTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\IsEmail\Callable\NotString; | ||
|
||
use PHPUnit\Framework\Attributes\Test; | ||
use Tests\TestCase; | ||
|
||
class NotEmailStringTest extends TestCase | ||
{ | ||
#[Test] public function invalid_email(): void | ||
{ | ||
$this->expectException(BadEmailException::class); | ||
User::from([ | ||
User::email => 1, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\IsEmail\Callable\NotString; | ||
|
||
use Zerotoprod\DataModel\DataModel; | ||
use Zerotoprod\DataModel\Describe; | ||
use Zerotoprod\DataModelHelper\DataModelHelper; | ||
|
||
class User | ||
{ | ||
use DataModel; | ||
use DataModelHelper; | ||
|
||
public const email = 'email'; | ||
|
||
#[Describe([ | ||
'cast' => [self::class, 'isEmail'], | ||
'on_fail' => [self::class, 'failed'], | ||
])] | ||
public string $email; | ||
|
||
public static function failed(): string | ||
{ | ||
throw new BadEmailException(); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
tests/Unit/IsEmail/Exception/InvalidUrl/BadEmailException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\IsEmail\Exception\InvalidUrl; | ||
|
||
use RuntimeException; | ||
|
||
class BadEmailException extends RuntimeException | ||
{ | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
tests/Unit/IsEmail/Exception/InvalidUrl/CustomExceptionTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\IsEmail\Exception\InvalidUrl; | ||
|
||
use PHPUnit\Framework\Attributes\Test; | ||
use Tests\TestCase; | ||
|
||
class CustomExceptionTest extends TestCase | ||
{ | ||
#[Test] public function invalid_email(): void | ||
{ | ||
$this->expectException(BadEmailException::class); | ||
User::from([ | ||
User::email => 'invalid email', | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\IsEmail\Exception\InvalidUrl; | ||
|
||
use Zerotoprod\DataModel\DataModel; | ||
use Zerotoprod\DataModel\Describe; | ||
use Zerotoprod\DataModelHelper\DataModelHelper; | ||
|
||
class User | ||
{ | ||
use DataModel; | ||
use DataModelHelper; | ||
|
||
public const email = 'email'; | ||
|
||
#[Describe([ | ||
'cast' => [self::class, 'isEmail'], | ||
'exception' => BadEmailException::class | ||
])] | ||
public string $email; | ||
} |
10 changes: 10 additions & 0 deletions
10
tests/Unit/IsEmail/Exception/NotString/BadEmailException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\IsEmail\Exception\NotString; | ||
|
||
use RuntimeException; | ||
|
||
class BadEmailException extends RuntimeException | ||
{ | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
tests/Unit/IsEmail/Exception/NotString/NotStringEmailCustomExceptionTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\IsEmail\Exception\NotString; | ||
|
||
use PHPUnit\Framework\Attributes\Test; | ||
use Tests\TestCase; | ||
|
||
class NotStringEmailCustomExceptionTest extends TestCase | ||
{ | ||
#[Test] public function not_string(): void | ||
{ | ||
$this->expectException(BadEmailException::class); | ||
User::from([ | ||
User::email => 1, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\IsEmail\Exception\NotString; | ||
|
||
use Zerotoprod\DataModel\DataModel; | ||
use Zerotoprod\DataModel\Describe; | ||
use Zerotoprod\DataModelHelper\DataModelHelper; | ||
|
||
class User | ||
{ | ||
use DataModel; | ||
use DataModelHelper; | ||
|
||
public const email = 'email'; | ||
|
||
#[Describe([ | ||
'cast' => [self::class, 'isEmail'], | ||
'exception' => BadEmailException::class | ||
])] | ||
public string $email; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\IsEmail\NullUrl; | ||
|
||
use PHPUnit\Framework\Attributes\Test; | ||
use Tests\TestCase; | ||
|
||
class NullUrlTest extends TestCase | ||
{ | ||
#[Test] public function null_email(): void | ||
{ | ||
$User = User::from(); | ||
|
||
self::assertNull($User->email); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\IsEmail\NullUrl; | ||
|
||
use Zerotoprod\DataModel\DataModel; | ||
use Zerotoprod\DataModel\Describe; | ||
use Zerotoprod\DataModelHelper\DataModelHelper; | ||
|
||
class User | ||
{ | ||
use DataModel; | ||
use DataModelHelper; | ||
|
||
public const email = 'email'; | ||
|
||
#[Describe([ | ||
'cast' => [self::class, 'isEmail'] | ||
])] | ||
public ?string $email; | ||
} |
Oops, something went wrong.