Skip to content

Commit 1015097

Browse files
committed
harden testing
1 parent 12639b7 commit 1015097

17 files changed

Lines changed: 136 additions & 0 deletions

tests/Service/AdminPortalTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public function testGenerateLink(): void
2020
$result = $client->adminPortal()->generateLink(organization: 'test_value');
2121
$this->assertInstanceOf(\WorkOS\Resource\PortalLinkResponse::class, $result);
2222
$this->assertSame($fixture['link'], $result->link);
23+
$this->assertIsArray($result->toArray());
2324
$request = $this->getLastRequest();
2425
$this->assertSame('POST', $request->getMethod());
2526
$this->assertStringEndsWith('portal/generate_link', $request->getUri()->getPath());

tests/Service/ApiKeysTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public function testCreateValidations(): void
1919
$client = $this->createMockClient([['status' => 200, 'body' => $fixture]]);
2020
$result = $client->apiKeys()->createValidations(value: 'test_value');
2121
$this->assertInstanceOf(\WorkOS\Resource\ApiKeyValidationResponse::class, $result);
22+
$this->assertIsArray($result->toArray());
2223
$request = $this->getLastRequest();
2324
$this->assertSame('POST', $request->getMethod());
2425
$this->assertStringEndsWith('api_keys/validations', $request->getUri()->getPath());
@@ -59,6 +60,7 @@ public function testCreateOrganizationApiKeys(): void
5960
$this->assertInstanceOf(\WorkOS\Resource\ApiKeyWithValue::class, $result);
6061
$this->assertSame($fixture['id'], $result->id);
6162
$this->assertSame($fixture['name'], $result->name);
63+
$this->assertIsArray($result->toArray());
6264
$request = $this->getLastRequest();
6365
$this->assertSame('POST', $request->getMethod());
6466
$this->assertStringEndsWith('organizations/test_organizationId/api_keys', $request->getUri()->getPath());
@@ -75,6 +77,9 @@ public function testPaginationBoundary(): void
7577
$client = $this->createMockClient([['status' => 200, 'body' => $fixture]]);
7678
$result = $client->apiKeys()->listOrganizationApiKeys('test_organizationId');
7779
$this->assertInstanceOf(\WorkOS\PaginatedResponse::class, $result);
80+
// Verify cursors are null on boundary page
81+
$this->assertNull($result->listMetadata['before']);
82+
$this->assertNull($result->listMetadata['after']);
7883
// Iterating should not throw on null cursors
7984
foreach ($result as $item) {
8085
$this->assertNotNull($item);

tests/Service/AuditLogsTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public function testListOrganizationAuditLogsRetention(): void
1919
$client = $this->createMockClient([['status' => 200, 'body' => $fixture]]);
2020
$result = $client->auditLogs()->listOrganizationAuditLogsRetention('test_id');
2121
$this->assertInstanceOf(\WorkOS\Resource\AuditLogsRetentionJson::class, $result);
22+
$this->assertIsArray($result->toArray());
2223
$request = $this->getLastRequest();
2324
$this->assertSame('GET', $request->getMethod());
2425
$this->assertStringEndsWith('organizations/test_id/audit_logs_retention', $request->getUri()->getPath());
@@ -30,6 +31,7 @@ public function testUpdateOrganizationAuditLogsRetention(): void
3031
$client = $this->createMockClient([['status' => 200, 'body' => $fixture]]);
3132
$result = $client->auditLogs()->updateOrganizationAuditLogsRetention('test_id', retentionPeriodInDays: 1);
3233
$this->assertInstanceOf(\WorkOS\Resource\AuditLogsRetentionJson::class, $result);
34+
$this->assertIsArray($result->toArray());
3335
$request = $this->getLastRequest();
3436
$this->assertSame('PUT', $request->getMethod());
3537
$this->assertStringEndsWith('organizations/test_id/audit_logs_retention', $request->getUri()->getPath());
@@ -75,6 +77,7 @@ public function testCreateSchema(): void
7577
$client = $this->createMockClient([['status' => 200, 'body' => $fixture]]);
7678
$result = $client->auditLogs()->createSchema('test_actionName', targets: []);
7779
$this->assertInstanceOf(\WorkOS\Resource\AuditLogSchemaJson::class, $result);
80+
$this->assertIsArray($result->toArray());
7881
$request = $this->getLastRequest();
7982
$this->assertSame('POST', $request->getMethod());
8083
$this->assertStringEndsWith('audit_logs/actions/test_actionName/schemas', $request->getUri()->getPath());
@@ -86,6 +89,7 @@ public function testCreateEvent(): void
8689
$client = $this->createMockClient([['status' => 200, 'body' => $fixture]]);
8790
$result = $client->auditLogs()->createEvent(organizationId: 'test_value', event: \WorkOS\Resource\AuditLogEvent::fromArray($this->loadFixture('audit_log_event')));
8891
$this->assertInstanceOf(\WorkOS\Resource\AuditLogEventCreateResponse::class, $result);
92+
$this->assertIsArray($result->toArray());
8993
$request = $this->getLastRequest();
9094
$this->assertSame('POST', $request->getMethod());
9195
$this->assertStringEndsWith('audit_logs/events', $request->getUri()->getPath());
@@ -100,6 +104,7 @@ public function testCreateExport(): void
100104
$result = $client->auditLogs()->createExport(organizationId: 'test_value', rangeStart: 'test_value', rangeEnd: 'test_value');
101105
$this->assertInstanceOf(\WorkOS\Resource\AuditLogExportJson::class, $result);
102106
$this->assertSame($fixture['id'], $result->id);
107+
$this->assertIsArray($result->toArray());
103108
$request = $this->getLastRequest();
104109
$this->assertSame('POST', $request->getMethod());
105110
$this->assertStringEndsWith('audit_logs/exports', $request->getUri()->getPath());
@@ -116,6 +121,7 @@ public function testGetExport(): void
116121
$result = $client->auditLogs()->getExport('test_auditLogExportId');
117122
$this->assertInstanceOf(\WorkOS\Resource\AuditLogExportJson::class, $result);
118123
$this->assertSame($fixture['id'], $result->id);
124+
$this->assertIsArray($result->toArray());
119125
$request = $this->getLastRequest();
120126
$this->assertSame('GET', $request->getMethod());
121127
$this->assertStringEndsWith('audit_logs/exports/test_auditLogExportId', $request->getUri()->getPath());
@@ -130,6 +136,9 @@ public function testPaginationBoundary(): void
130136
$client = $this->createMockClient([['status' => 200, 'body' => $fixture]]);
131137
$result = $client->auditLogs()->listActions();
132138
$this->assertInstanceOf(\WorkOS\PaginatedResponse::class, $result);
139+
// Verify cursors are null on boundary page
140+
$this->assertNull($result->listMetadata['before']);
141+
$this->assertNull($result->listMetadata['after']);
133142
// Iterating should not throw on null cursors
134143
foreach ($result as $item) {
135144
$this->assertNotNull($item);

tests/Service/AuthorizationTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public function testCheck(): void
1919
$client = $this->createMockClient([['status' => 200, 'body' => $fixture]]);
2020
$result = $client->authorization()->check('test_organization_membership_id', permissionSlug: 'test_value');
2121
$this->assertInstanceOf(\WorkOS\Resource\AuthorizationCheck::class, $result);
22+
$this->assertIsArray($result->toArray());
2223
$request = $this->getLastRequest();
2324
$this->assertSame('POST', $request->getMethod());
2425
$this->assertStringEndsWith('authorization/organization_memberships/test_organization_membership_id/check', $request->getUri()->getPath());
@@ -69,6 +70,7 @@ public function testAssignRole(): void
6970
$result = $client->authorization()->assignRole('test_organization_membership_id', roleSlug: 'test_value');
7071
$this->assertInstanceOf(\WorkOS\Resource\RoleAssignment::class, $result);
7172
$this->assertSame($fixture['id'], $result->id);
73+
$this->assertIsArray($result->toArray());
7274
$request = $this->getLastRequest();
7375
$this->assertSame('POST', $request->getMethod());
7476
$this->assertStringEndsWith('authorization/organization_memberships/test_organization_membership_id/role_assignments', $request->getUri()->getPath());
@@ -102,6 +104,7 @@ public function testListOrganizationRoles(): void
102104
$client = $this->createMockClient([['status' => 200, 'body' => $fixture]]);
103105
$result = $client->authorization()->listOrganizationRoles('test_organizationId');
104106
$this->assertInstanceOf(\WorkOS\Resource\RoleList::class, $result);
107+
$this->assertIsArray($result->toArray());
105108
$request = $this->getLastRequest();
106109
$this->assertSame('GET', $request->getMethod());
107110
$this->assertStringEndsWith('authorization/organizations/test_organizationId/roles', $request->getUri()->getPath());
@@ -115,6 +118,7 @@ public function testCreateOrganizationRole(): void
115118
$this->assertInstanceOf(\WorkOS\Resource\Role::class, $result);
116119
$this->assertSame($fixture['id'], $result->id);
117120
$this->assertSame($fixture['slug'], $result->slug);
121+
$this->assertIsArray($result->toArray());
118122
$request = $this->getLastRequest();
119123
$this->assertSame('POST', $request->getMethod());
120124
$this->assertStringEndsWith('authorization/organizations/test_organizationId/roles', $request->getUri()->getPath());
@@ -130,6 +134,7 @@ public function testGetOrganizationRole(): void
130134
$this->assertInstanceOf(\WorkOS\Resource\Role::class, $result);
131135
$this->assertSame($fixture['id'], $result->id);
132136
$this->assertSame($fixture['slug'], $result->slug);
137+
$this->assertIsArray($result->toArray());
133138
$request = $this->getLastRequest();
134139
$this->assertSame('GET', $request->getMethod());
135140
$this->assertStringEndsWith('authorization/organizations/test_organizationId/roles/test_slug', $request->getUri()->getPath());
@@ -143,6 +148,7 @@ public function testUpdateOrganizationRole(): void
143148
$this->assertInstanceOf(\WorkOS\Resource\Role::class, $result);
144149
$this->assertSame($fixture['id'], $result->id);
145150
$this->assertSame($fixture['slug'], $result->slug);
151+
$this->assertIsArray($result->toArray());
146152
$request = $this->getLastRequest();
147153
$this->assertSame('PATCH', $request->getMethod());
148154
$this->assertStringEndsWith('authorization/organizations/test_organizationId/roles/test_slug', $request->getUri()->getPath());
@@ -165,6 +171,7 @@ public function testCreateRolePermissions(): void
165171
$this->assertInstanceOf(\WorkOS\Resource\Role::class, $result);
166172
$this->assertSame($fixture['id'], $result->id);
167173
$this->assertSame($fixture['slug'], $result->slug);
174+
$this->assertIsArray($result->toArray());
168175
$request = $this->getLastRequest();
169176
$this->assertSame('POST', $request->getMethod());
170177
$this->assertStringEndsWith('authorization/organizations/test_organizationId/roles/test_slug/permissions', $request->getUri()->getPath());
@@ -178,6 +185,7 @@ public function testUpdateRolePermissions(): void
178185
$this->assertInstanceOf(\WorkOS\Resource\Role::class, $result);
179186
$this->assertSame($fixture['id'], $result->id);
180187
$this->assertSame($fixture['slug'], $result->slug);
188+
$this->assertIsArray($result->toArray());
181189
$request = $this->getLastRequest();
182190
$this->assertSame('PUT', $request->getMethod());
183191
$this->assertStringEndsWith('authorization/organizations/test_organizationId/roles/test_slug/permissions', $request->getUri()->getPath());
@@ -200,6 +208,7 @@ public function testGetOrganizationResource(): void
200208
$this->assertInstanceOf(\WorkOS\Resource\AuthorizationResource::class, $result);
201209
$this->assertSame($fixture['id'], $result->id);
202210
$this->assertSame($fixture['name'], $result->name);
211+
$this->assertIsArray($result->toArray());
203212
$request = $this->getLastRequest();
204213
$this->assertSame('GET', $request->getMethod());
205214
$this->assertStringEndsWith('authorization/organizations/test_organization_id/resources/test_resource_type_slug/test_external_id', $request->getUri()->getPath());
@@ -213,6 +222,7 @@ public function testUpdateOrganizationResource(): void
213222
$this->assertInstanceOf(\WorkOS\Resource\AuthorizationResource::class, $result);
214223
$this->assertSame($fixture['id'], $result->id);
215224
$this->assertSame($fixture['name'], $result->name);
225+
$this->assertIsArray($result->toArray());
216226
$request = $this->getLastRequest();
217227
$this->assertSame('PATCH', $request->getMethod());
218228
$this->assertStringEndsWith('authorization/organizations/test_organization_id/resources/test_resource_type_slug/test_external_id', $request->getUri()->getPath());
@@ -275,6 +285,7 @@ public function testCreateResource(): void
275285
$this->assertInstanceOf(\WorkOS\Resource\AuthorizationResource::class, $result);
276286
$this->assertSame($fixture['id'], $result->id);
277287
$this->assertSame($fixture['name'], $result->name);
288+
$this->assertIsArray($result->toArray());
278289
$request = $this->getLastRequest();
279290
$this->assertSame('POST', $request->getMethod());
280291
$this->assertStringEndsWith('authorization/resources', $request->getUri()->getPath());
@@ -293,6 +304,7 @@ public function testGetResource(): void
293304
$this->assertInstanceOf(\WorkOS\Resource\AuthorizationResource::class, $result);
294305
$this->assertSame($fixture['id'], $result->id);
295306
$this->assertSame($fixture['name'], $result->name);
307+
$this->assertIsArray($result->toArray());
296308
$request = $this->getLastRequest();
297309
$this->assertSame('GET', $request->getMethod());
298310
$this->assertStringEndsWith('authorization/resources/test_resource_id', $request->getUri()->getPath());
@@ -306,6 +318,7 @@ public function testUpdateResource(): void
306318
$this->assertInstanceOf(\WorkOS\Resource\AuthorizationResource::class, $result);
307319
$this->assertSame($fixture['id'], $result->id);
308320
$this->assertSame($fixture['name'], $result->name);
321+
$this->assertIsArray($result->toArray());
309322
$request = $this->getLastRequest();
310323
$this->assertSame('PATCH', $request->getMethod());
311324
$this->assertStringEndsWith('authorization/resources/test_resource_id', $request->getUri()->getPath());
@@ -344,6 +357,7 @@ public function testListEnvironmentRoles(): void
344357
$client = $this->createMockClient([['status' => 200, 'body' => $fixture]]);
345358
$result = $client->authorization()->listEnvironmentRoles();
346359
$this->assertInstanceOf(\WorkOS\Resource\RoleList::class, $result);
360+
$this->assertIsArray($result->toArray());
347361
$request = $this->getLastRequest();
348362
$this->assertSame('GET', $request->getMethod());
349363
$this->assertStringEndsWith('authorization/roles', $request->getUri()->getPath());
@@ -357,6 +371,7 @@ public function testCreateEnvironmentRole(): void
357371
$this->assertInstanceOf(\WorkOS\Resource\Role::class, $result);
358372
$this->assertSame($fixture['id'], $result->id);
359373
$this->assertSame($fixture['slug'], $result->slug);
374+
$this->assertIsArray($result->toArray());
360375
$request = $this->getLastRequest();
361376
$this->assertSame('POST', $request->getMethod());
362377
$this->assertStringEndsWith('authorization/roles', $request->getUri()->getPath());
@@ -373,6 +388,7 @@ public function testGetEnvironmentRole(): void
373388
$this->assertInstanceOf(\WorkOS\Resource\Role::class, $result);
374389
$this->assertSame($fixture['id'], $result->id);
375390
$this->assertSame($fixture['slug'], $result->slug);
391+
$this->assertIsArray($result->toArray());
376392
$request = $this->getLastRequest();
377393
$this->assertSame('GET', $request->getMethod());
378394
$this->assertStringEndsWith('authorization/roles/test_slug', $request->getUri()->getPath());
@@ -386,6 +402,7 @@ public function testUpdateEnvironmentRole(): void
386402
$this->assertInstanceOf(\WorkOS\Resource\Role::class, $result);
387403
$this->assertSame($fixture['id'], $result->id);
388404
$this->assertSame($fixture['slug'], $result->slug);
405+
$this->assertIsArray($result->toArray());
389406
$request = $this->getLastRequest();
390407
$this->assertSame('PATCH', $request->getMethod());
391408
$this->assertStringEndsWith('authorization/roles/test_slug', $request->getUri()->getPath());
@@ -399,6 +416,7 @@ public function testAddEnvironmentRolePermission(): void
399416
$this->assertInstanceOf(\WorkOS\Resource\Role::class, $result);
400417
$this->assertSame($fixture['id'], $result->id);
401418
$this->assertSame($fixture['slug'], $result->slug);
419+
$this->assertIsArray($result->toArray());
402420
$request = $this->getLastRequest();
403421
$this->assertSame('POST', $request->getMethod());
404422
$this->assertStringEndsWith('authorization/roles/test_slug/permissions', $request->getUri()->getPath());
@@ -412,6 +430,7 @@ public function testSetEnvironmentRolePermissions(): void
412430
$this->assertInstanceOf(\WorkOS\Resource\Role::class, $result);
413431
$this->assertSame($fixture['id'], $result->id);
414432
$this->assertSame($fixture['slug'], $result->slug);
433+
$this->assertIsArray($result->toArray());
415434
$request = $this->getLastRequest();
416435
$this->assertSame('PUT', $request->getMethod());
417436
$this->assertStringEndsWith('authorization/roles/test_slug/permissions', $request->getUri()->getPath());
@@ -441,6 +460,7 @@ public function testCreatePermission(): void
441460
$this->assertInstanceOf(\WorkOS\Resource\Permission::class, $result);
442461
$this->assertSame($fixture['id'], $result->id);
443462
$this->assertSame($fixture['slug'], $result->slug);
463+
$this->assertIsArray($result->toArray());
444464
$request = $this->getLastRequest();
445465
$this->assertSame('POST', $request->getMethod());
446466
$this->assertStringEndsWith('authorization/permissions', $request->getUri()->getPath());
@@ -457,6 +477,7 @@ public function testGetPermission(): void
457477
$this->assertInstanceOf(\WorkOS\Resource\AuthorizationPermission::class, $result);
458478
$this->assertSame($fixture['id'], $result->id);
459479
$this->assertSame($fixture['slug'], $result->slug);
480+
$this->assertIsArray($result->toArray());
460481
$request = $this->getLastRequest();
461482
$this->assertSame('GET', $request->getMethod());
462483
$this->assertStringEndsWith('authorization/permissions/test_slug', $request->getUri()->getPath());
@@ -470,6 +491,7 @@ public function testUpdatePermission(): void
470491
$this->assertInstanceOf(\WorkOS\Resource\AuthorizationPermission::class, $result);
471492
$this->assertSame($fixture['id'], $result->id);
472493
$this->assertSame($fixture['slug'], $result->slug);
494+
$this->assertIsArray($result->toArray());
473495
$request = $this->getLastRequest();
474496
$this->assertSame('PATCH', $request->getMethod());
475497
$this->assertStringEndsWith('authorization/permissions/test_slug', $request->getUri()->getPath());
@@ -493,6 +515,9 @@ public function testPaginationBoundary(): void
493515
$client = $this->createMockClient([['status' => 200, 'body' => $fixture]]);
494516
$result = $client->authorization()->listOrganizationMembershipResources('test_organization_membership_id', permissionSlug: 'test_value');
495517
$this->assertInstanceOf(\WorkOS\PaginatedResponse::class, $result);
518+
// Verify cursors are null on boundary page
519+
$this->assertNull($result->listMetadata['before']);
520+
$this->assertNull($result->listMetadata['after']);
496521
// Iterating should not throw on null cursors
497522
foreach ($result as $item) {
498523
$this->assertNotNull($item);

0 commit comments

Comments
 (0)