Skip to content

Commit 8b14e9c

Browse files
authored
Ability to add additional response content to failing result mock factory. (#719)
1 parent 7d03467 commit 8b14e9c

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

src/Test/ResultMockFactory.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,20 @@ class ResultMockFactory
3030
*
3131
* @return Result|T
3232
*/
33-
public static function createFailing(string $class, int $code, ?string $message = null)
34-
{
33+
public static function createFailing(
34+
string $class,
35+
int $code,
36+
?string $message = null,
37+
array $additionalContent = []
38+
) {
3539
if (Result::class !== $class) {
3640
$parent = get_parent_class($class);
3741
if (false === $parent || Result::class !== $parent) {
3842
throw new \LogicException(sprintf('The "%s::%s" can only be used for classes that extend "%s"', __CLASS__, __METHOD__, Result::class));
3943
}
4044
}
4145

42-
$httpResponse = new SimpleMockedResponse(\json_encode(['message' => $message]), ['content-type' => 'application/json'], $code);
46+
$httpResponse = new SimpleMockedResponse(\json_encode(\array_merge(['message' => $message], $additionalContent)), ['content-type' => 'application/json'], $code);
4347
$client = new MockHttpClient($httpResponse);
4448
$response = new Response($client->request('POST', 'http://localhost'), $client, new NullLogger());
4549

tests/Unit/Test/ResultMockFactoryTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,25 @@ public function testCreateFailling()
8080

8181
$result->resolve();
8282
}
83+
84+
public function testCreateFaillingWithAdditionalTypeContent()
85+
{
86+
$result = ResultMockFactory::createFailing(
87+
Result::class,
88+
400,
89+
'Boom',
90+
['__type' => 'com.amazonaws.dynamodb.v20120810#ResourceNotFoundException']
91+
);
92+
93+
try {
94+
$result->resolve();
95+
} catch (ClientException $e) {
96+
self::assertSame('ResourceNotFoundException', $e->getAwsCode());
97+
self::assertSame('com.amazonaws.dynamodb.v20120810#ResourceNotFoundException', $e->getAwsType());
98+
99+
return;
100+
}
101+
102+
self::fail('ClientException should be thrown');
103+
}
83104
}

0 commit comments

Comments
 (0)