['serviceIdentifier' => 's']]; $this->assertEquals($result, ApiProvider::resolve($p, 't', 's', 'v')); $p = function ($a, $b, $c) {return null;}; $this->expectException(UnresolvedApiException::class); ApiProvider::resolve($p, 't', 's', 'v'); } public function testCanGetServiceVersions() { $mp = $this->getTestApiProvider(); $this->assertEquals( ['2012-08-10', '2010-02-04'], $mp->getVersions('dynamodb') ); $this->assertEquals([], $mp->getVersions('foo')); $fp = $this->getTestApiProvider(false); $this->assertEquals( ['2012-08-10', '2010-02-04'], $fp->getVersions('dynamodb') ); } public function testCanGetDefaultProvider() { $p = ApiProvider::defaultProvider(); $this->assertArrayHasKey('s3', $this->getPropertyValue($p, 'manifest')); } public function testManifestProviderReturnsNullForMissingService() { $p = $this->getTestApiProvider(); $this->assertNull($p('api', 'foo', '2015-02-02')); } public function testManifestProviderCanLoadData() { $p = $this->getTestApiProvider(); $data = $p('api', 'dynamodb', 'latest'); $this->assertIsArray($data); $this->assertArrayHasKey('foo', $data); } public function testFilesystemProviderEnsuresDirectoryIsValid() { $this->expectException(\InvalidArgumentException::class); ApiProvider::filesystem('/path/to/invalid/dir'); } public function testNullOnMissingFile() { $p = $this->getTestApiProvider(); $this->assertNull($p('api', 'nofile', 'latest')); } public function testReturnsLatestServiceData() { $p = ApiProvider::filesystem(__DIR__ . '/api_provider_fixtures'); $this->assertEquals(['foo' => 'bar'], $p('api', 'dynamodb', 'latest')); } public function testReturnsNullWhenNoLatestVersionIsAvailable() { $p = ApiProvider::filesystem(__DIR__ . '/api_provider_fixtures'); $this->assertnull($p('api', 'dodo', 'latest')); } public function testReturnsPaginatorConfigsForLatestCompatibleVersion() { $p = $this->getTestApiProvider(); $result = $p('paginator', 'dynamodb', 'latest'); $this->assertEquals(['abc' => '123'], $result); $result = $p('paginator', 'dynamodb', '2011-12-05'); $this->assertEquals(['abc' => '123'], $result); } public function testReturnsWaiterConfigsForLatestCompatibleVersion() { $p = $this->getTestApiProvider(); $result = $p('waiter', 'dynamodb', 'latest'); $this->assertEquals(['abc' => '456'], $result); $result = $p('waiter', 'dynamodb', '2011-12-05'); $this->assertEquals(['abc' => '456'], $result); } public function testThrowsOnBadType() { $this->expectException(UnresolvedApiException::class); $p = $this->getTestApiProvider(); ApiProvider::resolve($p, 'foo', 's3', 'latest'); } public function testThrowsOnBadService() { $this->expectException(UnresolvedApiException::class); $p = $this->getTestApiProvider(); ApiProvider::resolve($p, 'api', '', 'latest'); } public function testThrowsOnBadVersion() { $this->expectException(UnresolvedApiException::class); $p = $this->getTestApiProvider(); ApiProvider::resolve($p, 'api', 'dynamodb', 'derp'); } }