-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
68 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
namespace Orchestra\Support\TestCase; | ||
|
||
use Orchestra\Support\Fluent; | ||
use PHPUnit\Framework\TestCase; | ||
use Orchestra\Support\Serializer; | ||
use Illuminate\Support\Collection; | ||
|
||
class SerializerTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_can_serialize_single_dataset() | ||
{ | ||
$dataset = new Fluent([ | ||
'fullname' => 'Mior Muhammad Zaki', 'email' => '[email protected]', | ||
]); | ||
|
||
$serializer = new class() extends Serializer { | ||
protected $key = 'user'; | ||
}; | ||
|
||
$this->assertSame([ | ||
'user' => [ | ||
'fullname' => 'Mior Muhammad Zaki', | ||
'email' => '[email protected]', | ||
], | ||
], $serializer($dataset)); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_serialize_dataset_collection() | ||
{ | ||
$dataset = new Collection( | ||
[ | ||
new Fluent([ | ||
'fullname' => 'Mior Muhammad Zaki', 'email' => '[email protected]', | ||
]), | ||
new Fluent([ | ||
'fullname' => 'Miki', 'email' => '[email protected]', | ||
]) | ||
] | ||
); | ||
|
||
$serializer = new class() extends Serializer { | ||
protected $key = 'user'; | ||
}; | ||
|
||
$this->assertSame([ | ||
'users' => [ | ||
[ | ||
'fullname' => 'Mior Muhammad Zaki', | ||
'email' => '[email protected]', | ||
], | ||
[ | ||
'fullname' => 'Miki', | ||
'email' => '[email protected]', | ||
], | ||
], | ||
], $serializer($dataset)); | ||
} | ||
} |