-
-
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.
Co-authored-by: david_smith <[email protected]>
- Loading branch information
1 parent
ecab046
commit 076e226
Showing
10 changed files
with
247 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,27 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\When\Eval; | ||
|
||
use PHPUnit\Framework\Attributes\Test; | ||
use Tests\TestCase; | ||
|
||
class EvalTest extends TestCase | ||
{ | ||
#[Test] public function true(): void | ||
{ | ||
$User = User::from([ | ||
User::value => 100, | ||
]); | ||
|
||
self::assertEquals(1, $User->value); | ||
} | ||
|
||
#[Test] public function false(): void | ||
{ | ||
$User = User::from([ | ||
User::value => 2, | ||
]); | ||
|
||
self::assertEquals(0, $User->value); | ||
} | ||
} |
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,32 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\When\Eval; | ||
|
||
use Zerotoprod\DataModel\DataModel; | ||
use Zerotoprod\DataModel\Describe; | ||
use Zerotoprod\DataModelHelper\DataModelHelper; | ||
|
||
class User | ||
{ | ||
use DataModel; | ||
use DataModelHelper; | ||
|
||
public const value = 'value'; | ||
|
||
#[Describe([ | ||
'cast' => [self::class, 'when'], | ||
'eval' => '$value >= 10', | ||
'true' => [self::class, 'true'], | ||
'false' => [self::class, 'false'], | ||
])] | ||
public int $value; | ||
|
||
public static function true(): int | ||
{ | ||
return 1; | ||
} | ||
public static function false(): int | ||
{ | ||
return 0; | ||
} | ||
} |
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,18 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\When\Nullable; | ||
|
||
use PHPUnit\Framework\Attributes\Test; | ||
use Tests\TestCase; | ||
|
||
class NullTest extends TestCase | ||
{ | ||
#[Test] public function valid(): void | ||
{ | ||
$User = User::from([ | ||
User::value => null, | ||
]); | ||
|
||
self::assertNull($User->value); | ||
} | ||
} |
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,25 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\When\Nullable; | ||
|
||
use Zerotoprod\DataModel\DataModel; | ||
use Zerotoprod\DataModel\Describe; | ||
use Zerotoprod\DataModelHelper\DataModelHelper; | ||
|
||
class User | ||
{ | ||
use DataModel; | ||
use DataModelHelper; | ||
|
||
public const value = 'value'; | ||
|
||
#[Describe([ | ||
'cast' => [self::class, 'when'], | ||
])] | ||
public ?int $value; | ||
|
||
public static function false(): int | ||
{ | ||
return 0; | ||
} | ||
} |
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\When\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); | ||
$this->expectExceptionMessage('Property `$value` is required.'); | ||
User::from(); | ||
} | ||
} |
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\When\Required; | ||
|
||
use Zerotoprod\DataModel\DataModel; | ||
use Zerotoprod\DataModel\Describe; | ||
use Zerotoprod\DataModelHelper\DataModelHelper; | ||
|
||
class User | ||
{ | ||
use DataModel; | ||
use DataModelHelper; | ||
|
||
public const value = 'value'; | ||
|
||
#[Describe([ | ||
'cast' => [self::class, 'when'], | ||
'required' | ||
])] | ||
public string $value; | ||
} |
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\When\Value; | ||
|
||
use Zerotoprod\DataModel\DataModel; | ||
use Zerotoprod\DataModel\Describe; | ||
use Zerotoprod\DataModelHelper\DataModelHelper; | ||
|
||
class User | ||
{ | ||
use DataModel; | ||
use DataModelHelper; | ||
|
||
public const value = 'value'; | ||
|
||
#[Describe([ | ||
'cast' => [self::class, 'when'], | ||
'eval' => '$value >= 10', | ||
'false' => [self::class, 'false'], | ||
])] | ||
public int $value; | ||
|
||
public static function true(): int | ||
{ | ||
return 1; | ||
} | ||
public static function false(): int | ||
{ | ||
return 0; | ||
} | ||
} |
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,18 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\When\Value; | ||
|
||
use PHPUnit\Framework\Attributes\Test; | ||
use Tests\TestCase; | ||
|
||
class ValueTest extends TestCase | ||
{ | ||
#[Test] public function value(): void | ||
{ | ||
$User = User::from([ | ||
User::value => 100, | ||
]); | ||
|
||
self::assertEquals(100, $User->value); | ||
} | ||
} |