1010ini_set ('display_startup_errors ' , 1 );
1111error_reporting (E_ALL );
1212
13+ const FOO_RESPONSES = [
14+ 'GET:/v1/mock/tests/foo:passed ' ,
15+ 'POST:/v1/mock/tests/foo:passed ' ,
16+ 'PUT:/v1/mock/tests/foo:passed ' ,
17+ 'PATCH:/v1/mock/tests/foo:passed ' ,
18+ 'DELETE:/v1/mock/tests/foo:passed ' ,
19+ ];
20+
21+ const BAR_RESPONSES = [
22+ 'GET:/v1/mock/tests/bar:passed ' ,
23+ 'POST:/v1/mock/tests/bar:passed ' ,
24+ 'PUT:/v1/mock/tests/bar:passed ' ,
25+ 'PATCH:/v1/mock/tests/bar:passed ' ,
26+ 'DELETE:/v1/mock/tests/bar:passed ' ,
27+ ];
28+
29+ const GENERAL_RESPONSES = [
30+ 'GET:/v1/mock/tests/general/redirect/done:passed ' ,
31+ 'POST:/v1/mock/tests/general/upload:passed ' ,
32+ ];
33+
34+ const EXCEPTION_RESPONSES = [
35+ 'Mock 400 error ' ,
36+ 'Server Error ' ,
37+ 'This is a text error ' ,
38+ ];
39+
40+ const REALTIME_RESPONSES = [
41+ 'WS:/v1/realtime:passed ' ,
42+ ];
43+
1344class SDKTest extends TestCase
1445{
1546 /**
@@ -24,7 +55,12 @@ class SDKTest extends TestCase
2455 'php-7.4 ' => 'docker run --rm -v $(pwd):/app -w /app php:7.4-cli-alpine php tests/languages/php/test.php ' ,
2556 'php-8.0 ' => 'docker run --rm -v $(pwd):/app -w /app php:8.0-cli-alpine php tests/languages/php/test.php ' ,
2657 ],
27- 'supportException ' => true ,
58+ 'expectedOutput ' => [
59+ ...FOO_RESPONSES ,
60+ ...BAR_RESPONSES ,
61+ ...GENERAL_RESPONSES ,
62+ ...EXCEPTION_RESPONSES ,
63+ ],
2864 ],
2965
3066 'cli ' => [
@@ -39,7 +75,11 @@ class SDKTest extends TestCase
3975 'envs ' => [
4076 'default ' => 'php tests/languages/cli/test.php ' ,
4177 ],
42- 'supportException ' => false ,
78+ 'expectedOutput ' => [
79+ ...FOO_RESPONSES ,
80+ ...BAR_RESPONSES ,
81+ ...GENERAL_RESPONSES ,
82+ ],
4383 ],
4484
4585 'dart ' => [
@@ -53,7 +93,12 @@ class SDKTest extends TestCase
5393 'dart-stable ' => 'docker run --rm -v $(pwd):/app -w /app/tests/sdks/dart dart:stable sh -c "dart pub get && dart pub run tests/tests.dart" ' ,
5494 'dart-beta ' => 'docker run --rm -v $(pwd):/app -w /app/tests/sdks/dart dart:beta sh -c "dart pub get && dart pub run tests/tests.dart" ' ,
5595 ],
56- 'supportException ' => true ,
96+ 'expectedOutput ' => [
97+ ...FOO_RESPONSES ,
98+ ...BAR_RESPONSES ,
99+ ...GENERAL_RESPONSES ,
100+ ...EXCEPTION_RESPONSES ,
101+ ],
57102 ],
58103
59104 'flutter ' => [
@@ -65,8 +110,13 @@ class SDKTest extends TestCase
65110 'envs ' => [
66111 'flutter-stable ' => 'docker run --rm -v $(pwd):/app -w /app/tests/sdks/flutter --env PUB_CACHE=vendor cirrusci/flutter:stable sh -c "flutter pub get && flutter test test/appwrite_test.dart" ' ,
67112 ],
68- 'supportException ' => true ,
69- 'supportRealtime ' => true ,
113+ 'expectedOutput ' => [
114+ ...FOO_RESPONSES ,
115+ ...BAR_RESPONSES ,
116+ ...GENERAL_RESPONSES ,
117+ ...EXCEPTION_RESPONSES ,
118+ ...REALTIME_RESPONSES ,
119+ ],
70120 ],
71121
72122 'android ' => [
@@ -79,8 +129,13 @@ class SDKTest extends TestCase
79129 'envs ' => [
80130 'java-8 ' => 'docker run --rm -v $(pwd):/app -w /app/tests/sdks/android alvrme/alpine-android:latest-jdk8 sh -c "./gradlew :library:testReleaseUnitTest -q && cat library/result.txt" ' ,
81131 ],
82- 'supportException ' => true ,
83- 'supportRealtime ' => true ,
132+ 'expectedOutput ' => [
133+ ...FOO_RESPONSES ,
134+ ...BAR_RESPONSES ,
135+ ...GENERAL_RESPONSES ,
136+ ...EXCEPTION_RESPONSES ,
137+ ...REALTIME_RESPONSES ,
138+ ],
84139 ],
85140
86141 'kotlin ' => [
@@ -94,7 +149,12 @@ class SDKTest extends TestCase
94149 'java-8 ' => 'docker run --rm -v $(pwd):/app -w /app/tests/sdks/kotlin openjdk:8-jdk-alpine sh -c "./gradlew :test -q && cat result.txt" ' ,
95150 'java-11 ' => 'docker run --rm -v $(pwd):/app -w /app/tests/sdks/kotlin adoptopenjdk/openjdk11:alpine sh -c "./gradlew :test -q && cat result.txt" ' ,
96151 ],
97- 'supportException ' => true ,
152+ 'expectedOutput ' => [
153+ ...FOO_RESPONSES ,
154+ ...BAR_RESPONSES ,
155+ ...GENERAL_RESPONSES ,
156+ ...EXCEPTION_RESPONSES ,
157+ ],
98158 ],
99159
100160 'swift-server ' => [
@@ -106,7 +166,12 @@ class SDKTest extends TestCase
106166 'envs ' => [
107167 'swift-5.5 ' => 'docker run --rm -v $(pwd):/app -w /app/tests/sdks/swift-server swift:5.5 swift test ' ,
108168 ],
109- 'supportException ' => true ,
169+ 'expectedOutput ' => [
170+ ...FOO_RESPONSES ,
171+ ...BAR_RESPONSES ,
172+ ...GENERAL_RESPONSES ,
173+ ...EXCEPTION_RESPONSES ,
174+ ],
110175 ],
111176
112177 'swift-client ' => [
@@ -118,8 +183,13 @@ class SDKTest extends TestCase
118183 'envs ' => [
119184 'swift-5.5 ' => 'docker run --rm -v $(pwd):/app -w /app/tests/sdks/swift-client swift:5.5 swift test ' ,
120185 ],
121- 'supportException ' => true ,
122- 'supportRealtime ' => true ,
186+ 'expectedOutput ' => [
187+ ...FOO_RESPONSES ,
188+ ...BAR_RESPONSES ,
189+ ...GENERAL_RESPONSES ,
190+ ...EXCEPTION_RESPONSES ,
191+ ...REALTIME_RESPONSES ,
192+ ],
123193 ],
124194
125195 'dotnet ' => [
@@ -134,7 +204,12 @@ class SDKTest extends TestCase
134204 'dotnet-5.0 ' => 'docker run --rm -v $(pwd):/app -w /app/tests/sdks/dotnet/src/test/ mcr.microsoft.com/dotnet/sdk:5.0-alpine pwsh tests.ps1 ' ,
135205 'dotnet-3.1 ' => 'docker run --rm -v $(pwd):/app -w /app/tests/sdks/dotnet/src/test/ mcr.microsoft.com/dotnet/sdk:3.1-alpine pwsh tests.ps1 ' ,
136206 ],
137- 'supportException ' => true ,
207+ 'expectedOutput ' => [
208+ ...FOO_RESPONSES ,
209+ ...BAR_RESPONSES ,
210+ ...GENERAL_RESPONSES ,
211+ ...EXCEPTION_RESPONSES ,
212+ ],
138213 ],
139214
140215 'web ' => [
@@ -151,8 +226,13 @@ class SDKTest extends TestCase
151226 'firefox ' => 'docker run --rm -v $(pwd):/app -e BROWSER=firefox -w /app/tests/sdks/web mcr.microsoft.com/playwright:v1.15.0-focal node tests.js ' ,
152227 'node ' => 'docker run --rm -v $(pwd):/app -w /app/tests/sdks/web mcr.microsoft.com/playwright:v1.15.0-focal node node.js ' ,
153228 ],
154- 'supportException ' => true ,
155- 'supportRealtime ' => true
229+ 'expectedOutput ' => [
230+ ...FOO_RESPONSES ,
231+ ...BAR_RESPONSES ,
232+ ...GENERAL_RESPONSES ,
233+ ...EXCEPTION_RESPONSES ,
234+ ...REALTIME_RESPONSES ,
235+ ],
156236 ],
157237 'deno ' => [
158238 'class ' => 'Appwrite\SDK\Language\Deno ' ,
@@ -161,7 +241,12 @@ class SDKTest extends TestCase
161241 'envs ' => [
162242 'deno-1.1.3 ' => 'docker run --rm -v $(pwd):/app -w /app hayd/alpine-deno:1.1.3 run --allow-net --allow-read tests/languages/deno/tests.ts ' , // TODO: use official image when its out
163243 ],
164- 'supportException ' => true ,
244+ 'expectedOutput ' => [
245+ ...FOO_RESPONSES ,
246+ ...BAR_RESPONSES ,
247+ ...GENERAL_RESPONSES ,
248+ ...EXCEPTION_RESPONSES ,
249+ ],
165250 ],
166251
167252 'node ' => [
@@ -174,7 +259,12 @@ class SDKTest extends TestCase
174259 'nodejs-14 ' => 'docker run --rm -v $(pwd):/app -w /app node:14-alpine node tests/languages/node/test.js ' ,
175260 'nodejs-16 ' => 'docker run --rm -v $(pwd):/app -w /app node:16-alpine node tests/languages/node/test.js ' ,
176261 ],
177- 'supportException ' => true ,
262+ 'expectedOutput ' => [
263+ ...FOO_RESPONSES ,
264+ ...BAR_RESPONSES ,
265+ ...GENERAL_RESPONSES ,
266+ ...EXCEPTION_RESPONSES ,
267+ ],
178268 ],
179269
180270 'ruby ' => [
@@ -185,7 +275,11 @@ class SDKTest extends TestCase
185275 'envs ' => [
186276 'ruby-2.7 ' => 'docker run --rm -v $(pwd):/app -w /app --env GEM_HOME=vendor ruby:2.7-alpine ruby tests/languages/ruby/tests.rb ' ,
187277 ],
188- 'supportException ' => false ,
278+ 'expectedOutput ' => [
279+ ...FOO_RESPONSES ,
280+ ...BAR_RESPONSES ,
281+ ...GENERAL_RESPONSES ,
282+ ],
189283 ],
190284
191285 'python ' => [
@@ -201,7 +295,12 @@ class SDKTest extends TestCase
201295 'python-3.7 ' => 'docker run --rm -v $(pwd):/app -w /app --env PIP_TARGET=tests/sdks/python/vendor --env PYTHONPATH=tests/sdks/python/vendor python:3.7-alpine python tests/sdks/python/test.py ' ,
202296 'python-3.6 ' => 'docker run --rm -v $(pwd):/app -w /app --env PIP_TARGET=tests/sdks/python/vendor --env PYTHONPATH=tests/sdks/python/vendor python:3.7-alpine python tests/sdks/python/test.py ' ,
203297 ],
204- 'supportException ' => true ,
298+ 'expectedOutput ' => [
299+ ...FOO_RESPONSES ,
300+ ...BAR_RESPONSES ,
301+ ...GENERAL_RESPONSES ,
302+ ...EXCEPTION_RESPONSES ,
303+ ],
205304 ],
206305 ];
207306
@@ -310,29 +409,10 @@ public function testHTTPSuccess()
310409 $ removed = array_shift ($ output );
311410 } while ($ removed != 'Test Started ' && sizeof ($ output ) != 0 );
312411
313- $ this ->assertGreaterThan (10 , count ($ output ));
314-
315- $ this ->assertEquals ('GET:/v1/mock/tests/foo:passed ' , $ output [0 ] ?? '' );
316- $ this ->assertEquals ('POST:/v1/mock/tests/foo:passed ' , $ output [1 ] ?? '' );
317- $ this ->assertEquals ('PUT:/v1/mock/tests/foo:passed ' , $ output [2 ] ?? '' );
318- $ this ->assertEquals ('PATCH:/v1/mock/tests/foo:passed ' , $ output [3 ] ?? '' );
319- $ this ->assertEquals ('DELETE:/v1/mock/tests/foo:passed ' , $ output [4 ] ?? '' );
320- $ this ->assertEquals ('GET:/v1/mock/tests/bar:passed ' , $ output [5 ] ?? '' );
321- $ this ->assertEquals ('POST:/v1/mock/tests/bar:passed ' , $ output [6 ] ?? '' );
322- $ this ->assertEquals ('PUT:/v1/mock/tests/bar:passed ' , $ output [7 ] ?? '' );
323- $ this ->assertEquals ('PATCH:/v1/mock/tests/bar:passed ' , $ output [8 ] ?? '' );
324- $ this ->assertEquals ('DELETE:/v1/mock/tests/bar:passed ' , $ output [9 ] ?? '' );
325- $ this ->assertEquals ('GET:/v1/mock/tests/general/redirect/done:passed ' , $ output [10 ] ?? '' );
326- $ this ->assertEquals ('POST:/v1/mock/tests/general/upload:passed ' , $ output [11 ] ?? '' );
327-
328- if ($ options ['supportException ' ]) {
329- $ this ->assertEquals ('Mock 400 error ' ,$ output [12 ] ?? '' );
330- $ this ->assertEquals ('Server Error ' , $ output [13 ] ?? '' );
331- $ this ->assertEquals ('This is a text error ' , $ output [14 ] ?? '' );
332- }
412+ $ this ->assertGreaterThanOrEqual (count ($ options ['expectedOutput ' ]), count ($ output ));
333413
334- if ($ options ['supportRealtime ' ] ?? false ) {
335- $ this ->assertEquals (' WS:/v1/realtime:passed ' , $ output [15 ] ?? '' );
414+ foreach ($ options ['expectedOutput ' ] as $ i => $ row ) {
415+ $ this ->assertEquals ($ output [$ i ], $ row );
336416 }
337417 }
338418 }
0 commit comments