|
9 | 9 | use WorkOS\Exception\RateLimitExceededException; |
10 | 10 | use WorkOS\RequestOptions; |
11 | 11 | use WorkOS\TestHelper; |
| 12 | +use WorkOS\Version; |
12 | 13 |
|
13 | 14 | class RuntimeBehaviorTest extends TestCase |
14 | 15 | { |
@@ -125,6 +126,53 @@ public function testAuthenticationErrorsAreMapped(): void |
125 | 126 | } |
126 | 127 | } |
127 | 128 |
|
| 129 | + public function testDefaultUserAgentIdentifiesTheSdk(): void |
| 130 | + { |
| 131 | + $client = $this->createMockClient([ |
| 132 | + ['status' => 200, 'body' => $this->loadFixture('organization')], |
| 133 | + ]); |
| 134 | + |
| 135 | + $client->organizations()->getOrganization('org_123'); |
| 136 | + |
| 137 | + $this->assertSame( |
| 138 | + sprintf('%s/%s', Version::SDK_IDENTIFIER, Version::SDK_VERSION), |
| 139 | + $this->getLastRequest()->getHeaderLine('User-Agent'), |
| 140 | + ); |
| 141 | + } |
| 142 | + |
| 143 | + public function testConstructorUserAgentOverridesDefault(): void |
| 144 | + { |
| 145 | + $client = $this->createMockClient( |
| 146 | + [['status' => 200, 'body' => $this->loadFixture('organization')]], |
| 147 | + userAgent: 'WorkOS PHP Laravel/5.1.0', |
| 148 | + ); |
| 149 | + |
| 150 | + $client->organizations()->getOrganization('org_123'); |
| 151 | + |
| 152 | + $this->assertSame( |
| 153 | + 'WorkOS PHP Laravel/5.1.0', |
| 154 | + $this->getLastRequest()->getHeaderLine('User-Agent'), |
| 155 | + ); |
| 156 | + } |
| 157 | + |
| 158 | + public function testPerRequestExtraHeadersCannotOverrideUserAgent(): void |
| 159 | + { |
| 160 | + $client = $this->createMockClient( |
| 161 | + [['status' => 200, 'body' => $this->loadFixture('organization')]], |
| 162 | + userAgent: 'WorkOS PHP Laravel/5.1.0', |
| 163 | + ); |
| 164 | + |
| 165 | + $client->organizations()->getOrganization( |
| 166 | + 'org_123', |
| 167 | + new RequestOptions(extraHeaders: ['User-Agent' => 'Custom/9.9.9']), |
| 168 | + ); |
| 169 | + |
| 170 | + $this->assertSame( |
| 171 | + 'WorkOS PHP Laravel/5.1.0', |
| 172 | + $this->getLastRequest()->getHeaderLine('User-Agent'), |
| 173 | + ); |
| 174 | + } |
| 175 | + |
128 | 176 | public function testRateLimitErrorsExposeRetryAfter(): void |
129 | 177 | { |
130 | 178 | $client = $this->createMockClient([ |
|
0 commit comments