-
-
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.
* Add required to `isUrl` in `DataModelHelper.php`. * Add tests. --------- Co-authored-by: david_smith <[email protected]>
- Loading branch information
1 parent
c1195e7
commit f91758d
Showing
3 changed files
with
57 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\IsUrl\Required; | ||
|
||
use PHPUnit\Framework\Attributes\Test; | ||
use Tests\TestCase; | ||
use Zerotoprod\DataModel\PropertyRequiredException; | ||
|
||
class RequiredTest extends TestCase | ||
{ | ||
#[Test] public function required(): void | ||
{ | ||
$this->expectException(PropertyRequiredException::class); | ||
User::from(); | ||
} | ||
|
||
#[Test] public function required_alt(): void | ||
{ | ||
$this->expectException(PropertyRequiredException::class); | ||
User::from([ | ||
User::url => 'https://example.com' | ||
]); | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\IsUrl\Required; | ||
|
||
use Zerotoprod\DataModel\DataModel; | ||
use Zerotoprod\DataModel\Describe; | ||
use Zerotoprod\DataModelHelper\DataModelHelper; | ||
|
||
class User | ||
{ | ||
use DataModel; | ||
use DataModelHelper; | ||
|
||
public const url = 'url'; | ||
|
||
#[Describe([ | ||
'cast' => [self::class, 'isUrl'], | ||
'required' | ||
])] | ||
public string $url; | ||
|
||
#[Describe([ | ||
'cast' => [self::class, 'isUrl'], | ||
'required' | ||
])] | ||
public string $social_url; | ||
} |