Skip to content

Commit 88e3c29

Browse files
authored
Fixed nullable nested objects (#188)
* Failing test for nested objects * Renamed functions * Make sure we support nullable properly * minor * Adding list->member * Bugfix * bugfix * bigfix * new baseline
1 parent 9ee471c commit 88e3c29

File tree

3 files changed

+111
-18
lines changed

3 files changed

+111
-18
lines changed

Result/DescribeStackEventsOutput.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ protected function populateResult(ResponseInterface $response, HttpClientInterfa
126126
$data = new \SimpleXMLElement($response->getContent(false));
127127
$data = $data->DescribeStackEventsResult;
128128

129-
$this->StackEvents = (function (\SimpleXMLElement $xml): array {
129+
$this->StackEvents = !$data->StackEvents ? [] : (function (\SimpleXMLElement $xml): array {
130130
$items = [];
131-
foreach ($xml as $item) {
131+
foreach ($xml->member as $item) {
132132
$items[] = new StackEvent([
133133
'StackId' => (string) $item->StackId,
134134
'EventId' => (string) $item->EventId,

Result/DescribeStacksOutput.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,17 @@ protected function populateResult(ResponseInterface $response, HttpClientInterfa
126126
$data = new \SimpleXMLElement($response->getContent(false));
127127
$data = $data->DescribeStacksResult;
128128

129-
$this->Stacks = (function (\SimpleXMLElement $xml): array {
129+
$this->Stacks = !$data->Stacks ? [] : (function (\SimpleXMLElement $xml): array {
130130
$items = [];
131-
foreach ($xml as $item) {
131+
foreach ($xml->member as $item) {
132132
$items[] = new Stack([
133133
'StackId' => ($v = $item->StackId) ? (string) $v : null,
134134
'StackName' => (string) $item->StackName,
135135
'ChangeSetId' => ($v = $item->ChangeSetId) ? (string) $v : null,
136136
'Description' => ($v = $item->Description) ? (string) $v : null,
137-
'Parameters' => (function (\SimpleXMLElement $xml): array {
137+
'Parameters' => !$item->Parameters ? [] : (function (\SimpleXMLElement $xml): array {
138138
$items = [];
139-
foreach ($xml as $item) {
139+
foreach ($xml->member as $item) {
140140
$items[] = new Parameter([
141141
'ParameterKey' => ($v = $item->ParameterKey) ? (string) $v : null,
142142
'ParameterValue' => ($v = $item->ParameterValue) ? (string) $v : null,
@@ -150,10 +150,10 @@ protected function populateResult(ResponseInterface $response, HttpClientInterfa
150150
'CreationTime' => new \DateTimeImmutable((string) $item->CreationTime),
151151
'DeletionTime' => ($v = $item->DeletionTime) ? new \DateTimeImmutable((string) $v) : null,
152152
'LastUpdatedTime' => ($v = $item->LastUpdatedTime) ? new \DateTimeImmutable((string) $v) : null,
153-
'RollbackConfiguration' => new RollbackConfiguration([
154-
'RollbackTriggers' => (function (\SimpleXMLElement $xml): array {
153+
'RollbackConfiguration' => !$item->RollbackConfiguration ? null : new RollbackConfiguration([
154+
'RollbackTriggers' => !$item->RollbackConfiguration->RollbackTriggers ? [] : (function (\SimpleXMLElement $xml): array {
155155
$items = [];
156-
foreach ($xml as $item) {
156+
foreach ($xml->member as $item) {
157157
$items[] = new RollbackTrigger([
158158
'Arn' => (string) $item->Arn,
159159
'Type' => (string) $item->Type,
@@ -167,9 +167,9 @@ protected function populateResult(ResponseInterface $response, HttpClientInterfa
167167
'StackStatus' => (string) $item->StackStatus,
168168
'StackStatusReason' => ($v = $item->StackStatusReason) ? (string) $v : null,
169169
'DisableRollback' => ($v = $item->DisableRollback) ? 'true' === (string) $v : null,
170-
'NotificationARNs' => (function (\SimpleXMLElement $xml): array {
170+
'NotificationARNs' => !$item->NotificationARNs ? [] : (function (\SimpleXMLElement $xml): array {
171171
$items = [];
172-
foreach ($xml as $item) {
172+
foreach ($xml->member as $item) {
173173
$a = ($v = $item) ? (string) $v : null;
174174
if (null !== $a) {
175175
$items[] = $a;
@@ -179,9 +179,9 @@ protected function populateResult(ResponseInterface $response, HttpClientInterfa
179179
return $items;
180180
})($item->NotificationARNs),
181181
'TimeoutInMinutes' => ($v = $item->TimeoutInMinutes) ? (int) (string) $v : null,
182-
'Capabilities' => (function (\SimpleXMLElement $xml): array {
182+
'Capabilities' => !$item->Capabilities ? [] : (function (\SimpleXMLElement $xml): array {
183183
$items = [];
184-
foreach ($xml as $item) {
184+
foreach ($xml->member as $item) {
185185
$a = ($v = $item) ? (string) $v : null;
186186
if (null !== $a) {
187187
$items[] = $a;
@@ -190,9 +190,9 @@ protected function populateResult(ResponseInterface $response, HttpClientInterfa
190190

191191
return $items;
192192
})($item->Capabilities),
193-
'Outputs' => (function (\SimpleXMLElement $xml): array {
193+
'Outputs' => !$item->Outputs ? [] : (function (\SimpleXMLElement $xml): array {
194194
$items = [];
195-
foreach ($xml as $item) {
195+
foreach ($xml->member as $item) {
196196
$items[] = new Output([
197197
'OutputKey' => ($v = $item->OutputKey) ? (string) $v : null,
198198
'OutputValue' => ($v = $item->OutputValue) ? (string) $v : null,
@@ -204,9 +204,9 @@ protected function populateResult(ResponseInterface $response, HttpClientInterfa
204204
return $items;
205205
})($item->Outputs),
206206
'RoleARN' => ($v = $item->RoleARN) ? (string) $v : null,
207-
'Tags' => (function (\SimpleXMLElement $xml): array {
207+
'Tags' => !$item->Tags ? [] : (function (\SimpleXMLElement $xml): array {
208208
$items = [];
209-
foreach ($xml as $item) {
209+
foreach ($xml->member as $item) {
210210
$items[] = new Tag([
211211
'Key' => (string) $item->Key,
212212
'Value' => (string) $item->Value,
@@ -218,7 +218,7 @@ protected function populateResult(ResponseInterface $response, HttpClientInterfa
218218
'EnableTerminationProtection' => ($v = $item->EnableTerminationProtection) ? 'true' === (string) $v : null,
219219
'ParentId' => ($v = $item->ParentId) ? (string) $v : null,
220220
'RootId' => ($v = $item->RootId) ? (string) $v : null,
221-
'DriftInformation' => new StackDriftInformation([
221+
'DriftInformation' => !$item->DriftInformation ? null : new StackDriftInformation([
222222
'StackDriftStatus' => (string) $item->DriftInformation->StackDriftStatus,
223223
'LastCheckTimestamp' => ($v = $item->DriftInformation->LastCheckTimestamp) ? new \DateTimeImmutable((string) $v) : null,
224224
]),
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace AsyncAws\CloudFormation\Tests\Unit\Result;
6+
7+
use AsyncAws\CloudFormation\Result\DescribeStacksOutput;
8+
use AsyncAws\CloudFormation\Result\Stack;
9+
use AsyncAws\Core\Test\Http\SimpleMockedResponse;
10+
use PHPUnit\Framework\TestCase;
11+
use Symfony\Component\HttpClient\MockHttpClient;
12+
13+
class DescribeStackOutputTest extends TestCase
14+
{
15+
public function testPopulateResult()
16+
{
17+
$xml = <<<XML
18+
<DescribeStacksResponse xmlns="http://cloudformation.amazonaws.com/doc/2010-05-15/">
19+
<DescribeStacksResult>
20+
<Stacks>
21+
<member>
22+
<Outputs>
23+
<member>
24+
<Description>Current Lambda function version</Description>
25+
<OutputKey>ConsoleLambdaFunctionQualifiedArn</OutputKey>
26+
<OutputValue>arn:aws:lambda:eu-central-1:34253654745:function:foobar-console:30</OutputValue>
27+
</member>
28+
<member>
29+
<Description>Current Lambda function version</Description>
30+
<OutputKey>WorkerLambdaFunctionQualifiedArn</OutputKey>
31+
<OutputValue>arn:aws:lambda:eu-central-1:34253654745:function:foobar-worker:21</OutputValue>
32+
</member>
33+
<member>
34+
<Description>Current Lambda function version</Description>
35+
<OutputKey>WebsiteLambdaFunctionQualifiedArn</OutputKey>
36+
<OutputValue>arn:aws:lambda:eu-central-1:34253654745:function:foobar-website:30</OutputValue>
37+
</member>
38+
<member>
39+
<Description>URL of the service endpoint</Description>
40+
<OutputKey>ServiceEndpoint</OutputKey>
41+
<OutputValue>https://p1kq4xmqt0.execute-api.eu-central-1.amazonaws.com/prod</OutputValue>
42+
</member>
43+
<member>
44+
<OutputKey>ServerlessDeploymentBucketName</OutputKey>
45+
<OutputValue>foo-lambda-applications-eu-central-1</OutputValue>
46+
</member>
47+
</Outputs>
48+
<Capabilities>
49+
<member>CAPABILITY_IAM</member>
50+
<member>CAPABILITY_NAMED_IAM</member>
51+
</Capabilities>
52+
<CreationTime>2020-02-16T13:48:03.325Z</CreationTime>
53+
<NotificationARNs/>
54+
<StackId>arn:aws:cloudformation:eu-central-1:34253654745:stack/foobar/f3b22b50-51c2-12ea-b958-06a323f6b6e2</StackId>
55+
<StackName>foobar</StackName>
56+
<Description>The AWS CloudFormation template for this Serverless application</Description>
57+
<StackStatus>UPDATE_COMPLETE</StackStatus>
58+
<DisableRollback>false</DisableRollback>
59+
<Tags>
60+
<member>
61+
<Value>prod</Value>
62+
<Key>STAGE</Key>
63+
</member>
64+
</Tags>
65+
<RollbackConfiguration/>
66+
<DriftInformation>
67+
<StackDriftStatus>NOT_CHECKED</StackDriftStatus>
68+
</DriftInformation>
69+
<EnableTerminationProtection>false</EnableTerminationProtection>
70+
<LastUpdatedTime>2020-02-19T22:10:24.681Z</LastUpdatedTime>
71+
</member>
72+
</Stacks>
73+
</DescribeStacksResult>
74+
<ResponseMetadata>
75+
<RequestId>8a082b63-a17b-4f2b-b8aa-b9fa8a550c60</RequestId>
76+
</ResponseMetadata>
77+
</DescribeStacksResponse>
78+
XML;
79+
80+
$response = new SimpleMockedResponse($xml);
81+
$result = new DescribeStacksOutput($response, new MockHttpClient());
82+
83+
$stack = null;
84+
foreach ($result->getStacks(true) as $s) {
85+
$stack = $s;
86+
}
87+
88+
self::assertInstanceOf(Stack::class, $stack, 'Could not find any stacks');
89+
$output = $stack->getOutputs();
90+
self::assertCount(5, $output);
91+
self::assertEquals('ConsoleLambdaFunctionQualifiedArn', $output[0]->getOutputKey());
92+
}
93+
}

0 commit comments

Comments
 (0)