-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#14528] - Fixed jsonSerializable for collection and json serializer
- Loading branch information
Showing
3 changed files
with
53 additions
and
4 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 |
---|---|---|
|
@@ -14,8 +14,11 @@ | |
|
||
use Codeception\Example; | ||
use InvalidArgumentException; | ||
use Phalcon\Collection; | ||
use Phalcon\Storage\Serializer\Json; | ||
use UnitTester; | ||
use function json_decode; | ||
use function json_encode; | ||
|
||
class SerializeCest | ||
{ | ||
|
@@ -37,6 +40,35 @@ public function storageSerializerJsonSerialize(UnitTester $I, Example $example) | |
$I->assertEquals($expected, $actual); | ||
} | ||
|
||
/** | ||
* Tests Phalcon\Storage\Serializer\Json :: serialize() - object | ||
* | ||
* @author Phalcon Team <[email protected]> | ||
* @since 2019-11-11 | ||
*/ | ||
public function storageSerializerJsonSerializeObject(UnitTester $I) | ||
{ | ||
$I->wantToTest('Storage\Serializer\Json - serialize() - object'); | ||
|
||
$collection1 = new Collection(); | ||
$collection1->set('one', 'two'); | ||
$collection2 = new Collection(); | ||
$collection2->set('three', 'four'); | ||
$collection2->set('object', $collection1); | ||
|
||
$serializer = new Json($collection2); | ||
|
||
$data = [ | ||
'three' => 'four', | ||
'object' => [ | ||
'one' => 'two', | ||
], | ||
]; | ||
$expected = json_encode($data); | ||
$actual = $serializer->serialize(); | ||
$I->assertEquals($expected, $actual); | ||
} | ||
|
||
/** | ||
* Tests Phalcon\Storage\Serializer\Json :: serialize() - error | ||
* | ||
|
@@ -49,7 +81,7 @@ public function storageSerializerJsonSerializeError(UnitTester $I) | |
|
||
$I->expectThrowable( | ||
new InvalidArgumentException( | ||
'Data for JSON serializer cannot be of type object' | ||
'Data for JSON serializer cannot be of type object without implementing JsonSerializable' | ||
), | ||
function () { | ||
$example = new \stdClass(); | ||
|
@@ -61,6 +93,9 @@ function () { | |
); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
private function getExamples(): array | ||
{ | ||
return [ | ||
|