assertReadyForApi(); $this->assertTrue($configuration->isConfigured()); $this->assertSame('https://openapi.esign.cn', $configuration->baseUrl()); $this->assertSame('production-app-id', $configuration->appId()); } public function test_it_rejects_production_credentials_with_the_sandbox_endpoint(): void { $configuration = $this->configuration(baseUrl: 'https://smlopenapi.esign.cn'); $this->expectException(RuntimeException::class); $this->expectExceptionMessage('正式环境不能使用沙箱 API 地址'); $configuration->assertReadyForApi(); } public function test_it_rejects_sandbox_credentials_with_the_production_endpoint(): void { $configuration = $this->configuration(environment: 'sandbox', baseUrl: 'https://openapi.esign.cn'); $this->expectException(RuntimeException::class); $this->expectExceptionMessage('沙箱环境不能使用正式 API 地址'); $configuration->assertReadyForApi(); } public function test_it_requires_both_credentials_before_an_api_request(): void { $configuration = $this->configuration(appSecret: ''); $this->assertFalse($configuration->isConfigured()); $this->expectExceptionMessage('尚未配置 App ID 或 AppSecret'); $configuration->assertReadyForApi(); } private function configuration( string $environment = 'production', string $baseUrl = 'https://openapi.esign.cn', string $appId = 'production-app-id', string $appSecret = 'production-app-secret', ): EsignConfiguration { return new EsignConfiguration( environment: $environment, baseUrl: $baseUrl, appId: $appId, appSecret: $appSecret, notifyUrl: '', callbackToleranceSeconds: 900, timeout: 20, ); } }