@@ -32,6 +32,7 @@ public function testConstructor(): void
3232 'staticSites ' => [],
3333 'workers ' => [],
3434 'jobs ' => [],
35+ 'phaseLastUpdatedAt ' => '2021-02-10T17:05:30Z ' ,
3536 'createdAt ' => '2021-02-10T17:05:30Z ' ,
3637 'updatedAt ' => '2021-02-10T17:05:30Z ' ,
3738 'cause ' => 'cause ' ,
@@ -51,6 +52,7 @@ public function testConstructor(): void
5152 self ::assertSame ($ values ['staticSites ' ], $ entity ->staticSites );
5253 self ::assertSame ($ values ['workers ' ], $ entity ->workers );
5354 self ::assertSame ($ values ['jobs ' ], $ entity ->jobs );
55+ self ::assertSame ($ values ['phaseLastUpdatedAt ' ], $ entity ->phaseLastUpdatedAt );
5456 self ::assertSame ($ values ['createdAt ' ], $ entity ->createdAt );
5557 self ::assertSame ($ values ['updatedAt ' ], $ entity ->updatedAt );
5658 self ::assertSame ($ values ['cause ' ], $ entity ->cause );
@@ -60,9 +62,172 @@ public function testConstructor(): void
6062 self ::assertSame ($ values ['tierSlug ' ], $ entity ->tierSlug );
6163
6264 self ::assertSame ($ values ['staticSites ' ], $ entity ->static_sites );
65+ self ::assertSame ($ values ['phaseLastUpdatedAt ' ], $ entity ->phase_last_updated_at );
6366 self ::assertSame ($ values ['createdAt ' ], $ entity ->created_at );
6467 self ::assertSame ($ values ['updatedAt ' ], $ entity ->updated_at );
6568 self ::assertSame ($ values ['clonedFrom ' ], $ entity ->cloned_from );
6669 self ::assertSame ($ values ['tierSlug ' ], $ entity ->tier_slug );
6770 }
71+
72+ public function testConstructorAcceptsApiShapedObjects (): void
73+ {
74+ $ payload = \json_decode (<<<'JSON'
75+ {
76+ "id": "b6bdf840-2854-4f87-a36c-5f231c617c84",
77+ "spec": {
78+ "name": "sample-golang",
79+ "services": [
80+ {
81+ "name": "web",
82+ "github": {
83+ "repo": "digitalocean/sample-golang",
84+ "branch": "main"
85+ },
86+ "routes": [
87+ {
88+ "path": "/"
89+ }
90+ ]
91+ }
92+ ]
93+ },
94+ "services": [
95+ {
96+ "name": "web",
97+ "source_commit_hash": "abc123",
98+ "alerts": [
99+ {
100+ "rule": "CPU_UTILIZATION"
101+ }
102+ ]
103+ }
104+ ],
105+ "static_sites": [
106+ {
107+ "name": "docs",
108+ "routes": [
109+ {
110+ "path": "/docs"
111+ }
112+ ]
113+ }
114+ ],
115+ "workers": [
116+ {
117+ "name": "queue",
118+ "instance_count": 1
119+ }
120+ ],
121+ "jobs": [
122+ {
123+ "name": "migrate",
124+ "kind": "POST_DEPLOY"
125+ }
126+ ],
127+ "phase_last_updated_at": "2024-01-02T00:03:00Z",
128+ "created_at": "2024-01-02T00:00:00Z",
129+ "updated_at": "2024-01-02T00:04:00Z",
130+ "cause": "manual",
131+ "cloned_from": "dep-0",
132+ "progress": {
133+ "success_steps": 1,
134+ "steps": [
135+ {
136+ "name": "build",
137+ "components": [
138+ {
139+ "name": "web"
140+ }
141+ ]
142+ }
143+ ]
144+ },
145+ "phase": "ACTIVE",
146+ "tier_slug": "basic"
147+ }
148+ JSON, false , 512 , \JSON_THROW_ON_ERROR );
149+
150+ $ expectedSpec = [
151+ 'name ' => 'sample-golang ' ,
152+ 'services ' => [
153+ [
154+ 'name ' => 'web ' ,
155+ 'github ' => [
156+ 'repo ' => 'digitalocean/sample-golang ' ,
157+ 'branch ' => 'main ' ,
158+ ],
159+ 'routes ' => [
160+ [
161+ 'path ' => '/ ' ,
162+ ],
163+ ],
164+ ],
165+ ],
166+ ];
167+ $ expectedServices = [
168+ [
169+ 'name ' => 'web ' ,
170+ 'source_commit_hash ' => 'abc123 ' ,
171+ 'alerts ' => [
172+ [
173+ 'rule ' => 'CPU_UTILIZATION ' ,
174+ ],
175+ ],
176+ ],
177+ ];
178+ $ expectedStaticSites = [
179+ [
180+ 'name ' => 'docs ' ,
181+ 'routes ' => [
182+ [
183+ 'path ' => '/docs ' ,
184+ ],
185+ ],
186+ ],
187+ ];
188+ $ expectedWorkers = [
189+ [
190+ 'name ' => 'queue ' ,
191+ 'instance_count ' => 1 ,
192+ ],
193+ ];
194+ $ expectedJobs = [
195+ [
196+ 'name ' => 'migrate ' ,
197+ 'kind ' => 'POST_DEPLOY ' ,
198+ ],
199+ ];
200+ $ expectedProgress = [
201+ 'success_steps ' => 1 ,
202+ 'steps ' => [
203+ [
204+ 'name ' => 'build ' ,
205+ 'components ' => [
206+ [
207+ 'name ' => 'web ' ,
208+ ],
209+ ],
210+ ],
211+ ],
212+ ];
213+
214+ $ entity = new AppDeployment ($ payload );
215+
216+ self ::assertInstanceOf (AbstractEntity::class, $ entity );
217+ self ::assertInstanceOf (AppDeployment::class, $ entity );
218+ self ::assertSame ('b6bdf840-2854-4f87-a36c-5f231c617c84 ' , $ entity ->id );
219+ self ::assertSame ($ expectedSpec , $ entity ->spec );
220+ self ::assertSame ($ expectedServices , $ entity ->services );
221+ self ::assertSame ($ expectedStaticSites , $ entity ->staticSites );
222+ self ::assertSame ($ expectedWorkers , $ entity ->workers );
223+ self ::assertSame ($ expectedJobs , $ entity ->jobs );
224+ self ::assertSame ($ expectedProgress , $ entity ->progress );
225+ self ::assertSame ('2024-01-02T00:03:00Z ' , $ entity ->phaseLastUpdatedAt );
226+ self ::assertSame ('dep-0 ' , $ entity ->clonedFrom );
227+ self ::assertSame ('basic ' , $ entity ->tierSlug );
228+ self ::assertSame ($ expectedStaticSites , $ entity ->static_sites );
229+ self ::assertSame ('2024-01-02T00:03:00Z ' , $ entity ->phase_last_updated_at );
230+ self ::assertSame ('dep-0 ' , $ entity ->cloned_from );
231+ self ::assertSame ('basic ' , $ entity ->tier_slug );
232+ }
68233}
0 commit comments