-
-
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-pregMatch (#18)
* Add support for `pregMatch()`. * Update `README.md`. * Add tests. * Add tests. * Update tests. * Update DockBlock in `DataModelHelper.php`. --------- Co-authored-by: david_smith <[email protected]>
- Loading branch information
1 parent
f9c4336
commit 1aa3e93
Showing
4 changed files
with
142 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\PregMatch; | ||
|
||
use PHPUnit\Framework\Attributes\Test; | ||
use Tests\TestCase; | ||
|
||
class PregMatchTest extends TestCase | ||
{ | ||
#[Test] public function pattern(): void | ||
{ | ||
$User = User::from([ | ||
User::name => 'stop', | ||
User::s => 'stop', | ||
User::as_null => 'top', | ||
User::offset => 'stop', | ||
]); | ||
|
||
self::assertEquals(['s'], $User->name); | ||
self::assertEquals('s', $User->s); | ||
self::assertNull($User->as_null); | ||
self::assertEquals([], $User->offset); | ||
} | ||
|
||
#[Test] public function allowsNull(): void | ||
{ | ||
$User = User::from(); | ||
|
||
self::assertNull($User->name); | ||
} | ||
} |
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,46 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\PregMatch; | ||
|
||
use Zerotoprod\DataModel\DataModel; | ||
use Zerotoprod\DataModel\Describe; | ||
use Zerotoprod\DataModelHelper\DataModelHelper; | ||
|
||
class User | ||
{ | ||
use DataModel; | ||
use DataModelHelper; | ||
|
||
public const name = 'name'; | ||
public const s = 's'; | ||
public const as_null = 'as_null'; | ||
public const offset = 'offset'; | ||
|
||
#[Describe([ | ||
'cast' => [self::class, 'pregMatch'], | ||
'pattern' => '/s/', | ||
])] | ||
public ?array $name; | ||
|
||
#[Describe([ | ||
'cast' => [self::class, 'pregMatch'], | ||
'pattern' => '/s/', | ||
'match_on' => 0 | ||
])] | ||
public ?string $s; | ||
|
||
#[Describe([ | ||
'cast' => [self::class, 'pregMatch'], | ||
'pattern' => '/s/', | ||
'match_on' => 0, | ||
'flags' => PREG_UNMATCHED_AS_NULL | ||
])] | ||
public ?string $as_null; | ||
|
||
#[Describe([ | ||
'cast' => [self::class, 'pregMatch'], | ||
'pattern' => '/s/', | ||
'offset' => 1 | ||
])] | ||
public ?array $offset; | ||
} |