Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly handle case where a metadata key is called 'metadata' #607

Merged
merged 1 commit into from
Mar 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/StripeObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public function updateAttributes($values, $opts = null, $dirty = true)
// This is necessary in case metadata is empty, as PHP arrays do
// not differentiate between lists and hashes, and we consider
// empty arrays to be lists.
if ($k === "metadata") {
if (($k === "metadata") && (is_array($v))) {
$this->_values[$k] = StripeObject::constructFrom($v, $opts);
} else {
$this->_values[$k] = Util\Util::convertToStripeObject($v, $opts);
Expand Down
19 changes: 19 additions & 0 deletions tests/Stripe/StripeObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -473,4 +473,23 @@ public function testIsDeleted()
$obj = StripeObject::constructFrom(['deleted' => true]);
$this->assertTrue($obj->isDeleted());
}

public function testDeserializeEmptyMetadata()
{
$obj = StripeObject::constructFrom([
'metadata' => [],
]);

$this->assertInstanceOf("Stripe\\StripeObject", $obj->metadata);
}

public function testDeserializeMetadataWithKeyNamedMetadata()
{
$obj = StripeObject::constructFrom([
'metadata' => ['metadata' => 'value'],
]);

$this->assertInstanceOf("Stripe\\StripeObject", $obj->metadata);
$this->assertEquals("value", $obj->metadata->metadata);
}
}