From 039578c18855c65c41eb32032cd12ee72b8ea389 Mon Sep 17 00:00:00 2001 From: SamRemis Date: Tue, 25 Jul 2023 16:25:16 -0400 Subject: [PATCH] Remove need to specify version, defaulting to latest --- .../nextrelease/feature-default-version.json | 7 +++++ src/ClientResolver.php | 29 +----------------- tests/ClientResolverTest.php | 30 +++++++++---------- 3 files changed, 22 insertions(+), 44 deletions(-) create mode 100644 .changes/nextrelease/feature-default-version.json diff --git a/.changes/nextrelease/feature-default-version.json b/.changes/nextrelease/feature-default-version.json new file mode 100644 index 0000000000..65fd7f52c0 --- /dev/null +++ b/.changes/nextrelease/feature-default-version.json @@ -0,0 +1,7 @@ +[ + { + "type": "feature", + "category": "", + "description": "Removes validation of supplying the `version` configuration option to client constructors, defaulting to 'latest'`" + } +] \ No newline at end of file diff --git a/src/ClientResolver.php b/src/ClientResolver.php index 60b92649e9..34b2172379 100644 --- a/src/ClientResolver.php +++ b/src/ClientResolver.php @@ -98,8 +98,8 @@ class ClientResolver 'version' => [ 'type' => 'value', 'valid' => ['string'], - 'required' => [__CLASS__, '_missing_version'], 'doc' => 'The version of the webservice to utilize (e.g., 2006-03-01).', + 'default' => 'latest', ], 'signature_provider' => [ 'type' => 'value', @@ -1137,33 +1137,6 @@ public static function _default_signing_region(array &$args) : $args['region']; } - public static function _missing_version(array $args) - { - $service = isset($args['service']) ? $args['service'] : ''; - $versions = ApiProvider::defaultProvider()->getVersions($service); - $versions = implode("\n", array_map(function ($v) { - return "* \"$v\""; - }, $versions)) ?: '* (none found)'; - - return <<resolve([], new HandlerList()); } - public function testHasSpecificMessageForMissingVersion() + public function testAppliesLatestAsDefaultVersionWithoutSuppliedVersion() { - $this->expectExceptionMessage("A \"version\" configuration value is required"); - $this->expectException(\InvalidArgumentException::class); - $args = ClientResolver::getDefaultArguments()['version']; - $r = new ClientResolver(['version' => $args]); - $r->resolve(['service' => 'foo'], new HandlerList()); + $r = new ClientResolver(ClientResolver::getDefaultArguments()); + $conf = $r->resolve([ + 'service' => 'ec2', + 'region' => 'us-west-2', + ], new HandlerList()); + self::assertSame('latest', $conf['version']); } - public function testHasSpecificMessageForNullRequiredVersion() + public function testAppliesVersion() { - $this->expectExceptionMessage("A \"version\" configuration value is required"); - $this->expectException(\InvalidArgumentException::class); $r = new ClientResolver(ClientResolver::getDefaultArguments()); - $list = new HandlerList(); - $r->resolve([ - 'service' => 'foo', - 'region' => 'x', - 'credentials' => ['key' => 'a', 'secret' => 'b'], - 'version' => null, - ], $list); + $conf = $r->resolve([ + 'service' => 'ec2', + 'region' => 'us-west-2', + 'version' => '2015-10-01' + ], new HandlerList()); + self::assertSame('2015-10-01', $conf['version']); } public function testHasSpecificMessageForMissingRegion()