-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PHPC-274: Fix zval_to_bson() encoding of BSON\Serializable objects
Previously, only BSON\Persistable objects were handled.
- Loading branch information
Showing
3 changed files
with
163 additions
and
48 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,42 @@ | ||
--TEST-- | ||
BSON encoding error when bsonSerialize() for root document does not return an array | ||
--SKIPIF-- | ||
<?php require __DIR__ . "/../utils/basic-skipif.inc"?> | ||
--FILE-- | ||
<?php | ||
require_once __DIR__ . "/../utils/basic.inc"; | ||
|
||
class MyClass implements BSON\Serializable | ||
{ | ||
private $value; | ||
|
||
public function __construct($value) | ||
{ | ||
$this->value = $value; | ||
} | ||
|
||
public function bsonSerialize() | ||
{ | ||
return $this->value; | ||
} | ||
} | ||
|
||
$invalidValues = array(new stdClass, 'foo', 1, true); | ||
|
||
foreach ($invalidValues as $invalidValue) { | ||
try { | ||
BSON\fromArray(new MyClass($invalidValue)); | ||
} catch (MongoDB\Driver\Exception\RuntimeException $e) { | ||
echo $e->getMessage(), "\n"; | ||
} | ||
} | ||
|
||
?> | ||
===DONE=== | ||
<?php exit(0); ?> | ||
--EXPECT-- | ||
Expected bsonSerialize() to return an array, object given | ||
Expected bsonSerialize() to return an array, string given | ||
Expected bsonSerialize() to return an array, integer given | ||
Expected bsonSerialize() to return an array, boolean given | ||
===DONE=== |