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

Event::constructFrom with empty data->previous_attributes creates array instead of StripeObject #1785

Open
msbit opened this issue Nov 11, 2024 · 1 comment
Labels

Comments

@msbit
Copy link

msbit commented Nov 11, 2024

Describe the bug

Passing an event payload like so:

[
    'data' => [
        'previous_attributes' => [],
    ],  
    'object' => 'event',
]

to Event::constructFrom will create an Event whose event->data->previous_attributes member is an array, whereas passing an event payload like so:

[
    'data' => [
        'previous_attributes' => [
            'foo' => 'bar',
        ],
    ],  
    'object' => 'event',
]

will create an Event whose event->data->previous_attributes member is a StripeObject.

It feels like this should be consistent, with this member being a StripeObject in both cases.

To Reproduce

assert(Stripe\Event::constructFrom(['data'=>['previous_attributes'=>[]],'object'=>'event'])->data->previous_attributes instanceof Stripe\StripeObject);

Expected behavior

The assertion to be upheld.

Code snippets

<?php

use PHPUnit\Framework\TestCase;

use Stripe\Event;
use Stripe\StripeObject;

class Test extends TestCase
{
    /** 
     * @dataProvider previousAttributesProvider
     */
    function test_constructFrom(array $previousAttributes): void
    {   
        $event = Event::constructFrom([
            'data' => [
                'previous_attributes' => $previousAttributes,
            ],  
            'object' => 'event',
        ]); 

        $this->assertInstanceOf(
            StripeObject::class,
            $event->data->previous_attributes,
        );  
    }   

    function previousAttributesProvider(): iterable
    {   
        yield [['foo' => 'bar']];
        yield [[]];
    }   
}

OS

macOS

PHP version

8.3

Library version

v7.128.0

API version

na

Additional context

No response

@msbit msbit added the bug label Nov 11, 2024
@xavdid-stripe
Copy link
Member

Thanks for the report! We've filed this internally as DEVSDK-2297 and will take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants