-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes an issue with decoding
null
values using the Json Value object.
Additional changes: - Moved the JsonValue object to the appropriate namespace. - Added unit tests for the Json Value object. - Added unit tests for the Uuid Value object.
- Loading branch information
1 parent
6a693c3
commit 1426613
Showing
12 changed files
with
91 additions
and
10 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
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
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
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,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Application\Domain\ValueObjects; | ||
|
||
use App\Application\Domain\ValueObjects\Json; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class JsonTest extends TestCase | ||
{ | ||
public static function jsonDataProvider(): iterable | ||
{ | ||
yield 'null' => [ | ||
'null', | ||
[], | ||
]; | ||
|
||
yield 'empty-string' => [ | ||
'', | ||
[], | ||
]; | ||
|
||
yield 'empty' => [ | ||
'{}', | ||
[], | ||
]; | ||
|
||
yield 'simple' => [ | ||
'{"key": "value"}', | ||
['key' => 'value'], | ||
]; | ||
} | ||
|
||
#[DataProvider('jsonDataProvider')] | ||
public function testDecode(string $json, mixed $expected): void | ||
{ | ||
$object = Json::typecast($json); | ||
|
||
$this->assertEquals($expected, $object->jsonSerialize()); | ||
} | ||
} |
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,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Application\Domain\ValueObjects; | ||
|
||
use App\Application\Domain\ValueObjects\Uuid; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class UuidTest extends TestCase | ||
{ | ||
public function testGenerate(): void | ||
{ | ||
$uuid1 = Uuid::generate(); | ||
$uuid2 = Uuid::generate(); | ||
|
||
$this->assertNotEquals((string) $uuid1, (string) $uuid2); | ||
} | ||
|
||
public function testEquals(): void | ||
{ | ||
$uuid1 = Uuid::generate(); | ||
$uuid2 = Uuid::generate(); | ||
|
||
$this->assertTrue($uuid1->equals($uuid1)); | ||
$this->assertFalse($uuid1->equals($uuid2)); | ||
} | ||
|
||
public function testFromString(): void | ||
{ | ||
$uuid = Uuid::fromString($string = 'f47ac10b-58cc-4372-a567-0e02b2c3d479'); | ||
|
||
$this->assertEquals($string, (string) $uuid); | ||
} | ||
} |