From 25827cdbf9baf6ec365c27f59dcd643571a3ef9e Mon Sep 17 00:00:00 2001 From: Remi Jannel Date: Mon, 30 Nov 2020 15:24:01 -0800 Subject: [PATCH] Improve error message for invalid keys in StripeClient --- lib/BaseStripeClient.php | 5 ++++- tests/Stripe/BaseStripeClientTest.php | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/BaseStripeClient.php b/lib/BaseStripeClient.php index e5482576d..5499fe3a8 100644 --- a/lib/BaseStripeClient.php +++ b/lib/BaseStripeClient.php @@ -260,7 +260,10 @@ private function validateConfig($config) // check absence of extra keys $extraConfigKeys = \array_diff(\array_keys($config), \array_keys($this->getDefaultConfig())); if (!empty($extraConfigKeys)) { - throw new \Stripe\Exception\InvalidArgumentException('Found unknown key(s) in configuration array: ' . \implode(',', $extraConfigKeys)); + // Wrap in single quote to more easily catch trailing spaces errors + $invalidKeys = "'" . \implode("', '", $extraConfigKeys) . "'"; + + throw new \Stripe\Exception\InvalidArgumentException('Found unknown key(s) in configuration array: ' . $invalidKeys); } } } diff --git a/tests/Stripe/BaseStripeClientTest.php b/tests/Stripe/BaseStripeClientTest.php index 044abcc23..a279b4144 100644 --- a/tests/Stripe/BaseStripeClientTest.php +++ b/tests/Stripe/BaseStripeClientTest.php @@ -60,9 +60,9 @@ public function testCtorThrowsIfApiKeyIsUnexpectedType() public function testCtorThrowsIfConfigArrayContainsUnexpectedKey() { $this->expectException(\Stripe\Exception\InvalidArgumentException::class); - $this->expectExceptionMessage('Found unknown key(s) in configuration array: foo'); + $this->expectExceptionMessage('Found unknown key(s) in configuration array: \'foo\', \'foo2\''); - $client = new BaseStripeClient(['foo' => 'bar']); + $client = new BaseStripeClient(['foo' => 'bar', 'foo2' => 'bar2']); } public function testRequestWithClientApiKey()