$errorCode, 'message' => 'Test message for ' . $errorCode, ]; $exception = LicenseException::fromApiResponse($data, 403); self::assertInstanceOf($expectedClass, $exception); self::assertSame('Test message for ' . $errorCode, $exception->getMessage()); self::assertSame($errorCode, $exception->errorCode); self::assertSame(403, $exception->getCode()); } public static function exceptionMappingProvider(): array { return [ 'license_not_found' => ['license_not_found', LicenseNotFoundException::class], 'license_expired' => ['license_expired', LicenseExpiredException::class], 'license_revoked' => ['license_revoked', LicenseRevokedException::class], 'license_inactive' => ['license_inactive', LicenseInactiveException::class], 'license_invalid' => ['license_invalid', LicenseInvalidException::class], 'domain_mismatch' => ['domain_mismatch', DomainMismatchException::class], 'max_activations_reached' => ['max_activations_reached', MaxActivationsReachedException::class], 'activation_failed' => ['activation_failed', ActivationFailedException::class], ]; } #[Test] public function itCreatesRateLimitExceptionWithRetryAfter(): void { $data = [ 'error' => 'rate_limit_exceeded', 'message' => 'Too many requests.', 'retry_after' => 45, ]; $exception = LicenseException::fromApiResponse($data, 429); self::assertInstanceOf(RateLimitExceededException::class, $exception); self::assertSame(45, $exception->retryAfter); } #[Test] public function itCreatesGenericExceptionForUnknownErrorCode(): void { $data = [ 'error' => 'unknown_error', 'message' => 'Something went wrong.', ]; $exception = LicenseException::fromApiResponse($data, 500); self::assertInstanceOf(LicenseException::class, $exception); self::assertNotInstanceOf(LicenseNotFoundException::class, $exception); self::assertSame('unknown_error', $exception->errorCode); } #[Test] public function itHandlesMissingMessageInApiResponse(): void { $data = [ 'error' => 'license_not_found', ]; $exception = LicenseException::fromApiResponse($data, 404); self::assertSame('Unknown license error', $exception->getMessage()); } #[Test] public function itHandlesMissingErrorCodeInApiResponse(): void { $data = [ 'message' => 'Some error occurred.', ]; $exception = LicenseException::fromApiResponse($data, 500); self::assertInstanceOf(LicenseException::class, $exception); self::assertNull($exception->errorCode); } }