From 9b9dd1397154e6ec0218ecc94c40500d4e402998 Mon Sep 17 00:00:00 2001 From: Jesse Rosalia Date: Mon, 13 Jan 2025 15:22:11 -0800 Subject: [PATCH] made v2 event class concrete, and changed convertToStripeObject to use it if we cannot find the identified event subclass added generated test testCoreEventsGet --- lib/Util/Util.php | 2 +- lib/V2/Event.php | 7 ++++++- tests/Stripe/GeneratedExamplesTest.php | 14 ++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/Util/Util.php b/lib/Util/Util.php index f0ba9bb8f..b8f888642 100644 --- a/lib/Util/Util.php +++ b/lib/Util/Util.php @@ -64,7 +64,7 @@ public static function convertToStripeObject($resp, $opts, $apiMode = 'v1') if (\array_key_exists('type', $resp) && \array_key_exists($resp['type'], $eventTypes)) { $class = $eventTypes[$resp['type']]; } else { - $class = \Stripe\StripeObject::class; + $class = \Stripe\V2\Event::class; } } } elseif (\array_key_exists('data', $resp) && \array_key_exists('next_page_url', $resp)) { diff --git a/lib/V2/Event.php b/lib/V2/Event.php index a8ac4dbb5..9b87f294a 100644 --- a/lib/V2/Event.php +++ b/lib/V2/Event.php @@ -3,6 +3,11 @@ namespace Stripe\V2; /** + * Base class for V2 events. + * + * This is concrete for use in our generated tests. Events returned from the \Stripe\V2\Core\EventService + * will be a subtype of \Stripe\V2\Event. + * * @property string $id Unique identifier for the event. * @property string $object String representing the object's type. Objects of the same type share the same value of the object field. * @property int $created Time at which the object was created. @@ -10,7 +15,7 @@ * @property string $type The type of the event. * @property null|string $context The Stripe account of the event */ -abstract class Event extends \Stripe\ApiResource +class Event extends \Stripe\ApiResource { const OBJECT_NAME = 'v2.core.event'; } diff --git a/tests/Stripe/GeneratedExamplesTest.php b/tests/Stripe/GeneratedExamplesTest.php index 1392fbc29..2badfd65f 100644 --- a/tests/Stripe/GeneratedExamplesTest.php +++ b/tests/Stripe/GeneratedExamplesTest.php @@ -577,6 +577,20 @@ public function testCheckoutSessionsPost2() static::assertInstanceOf(\Stripe\Checkout\Session::class, $result); } + public function testCoreEventsGet() + { + $this->stubRequest( + 'get', + '/v2/core/events/ll_123', + [], + [], + false, + ['object' => \Stripe\V2\Event::OBJECT_NAME] + ); + $result = $this->client->v2->core->events->retrieve('ll_123', []); + static::assertInstanceOf(\Stripe\V2\Event::class, $result); + } + public function testCountrySpecsGet() { $this->expectsRequest('get', '/v1/country_specs');