assertEquals('test_sid', $config->sid); $this->assertEquals('test_app_key', $config->appKey); $this->assertEquals('test_app_secret', $config->appSecret); $this->assertEquals('https://api.example.com', $config->baseUrl); $this->assertEquals(30, $config->timeout); $this->assertTrue($config->debug); $this->assertEquals('/tmp/test.log', $config->logFile); } public function testConstructorWithDefaults(): void { $config = new Config( sid: 'test_sid', appKey: 'test_app_key', appSecret: 'test_app_secret' ); $this->assertEquals('test_sid', $config->sid); $this->assertEquals('test_app_key', $config->appKey); $this->assertEquals('test_app_secret', $config->appSecret); $this->assertEquals(Config::SANDBOX_BASE_URL, $config->baseUrl); $this->assertEquals(30, $config->timeout); $this->assertFalse($config->debug); $this->assertNull($config->logFile); } public function testSandboxFactory(): void { $config = Config::sandbox('test_sid', 'test_app_key', 'test_app_secret'); $this->assertEquals('test_sid', $config->sid); $this->assertEquals('test_app_key', $config->appKey); $this->assertEquals('test_app_secret', $config->appSecret); $this->assertEquals(Config::SANDBOX_BASE_URL, $config->baseUrl); $this->assertTrue($config->debug); $this->assertTrue($config->isSandbox()); } public function testProductionFactory(): void { $config = Config::production('test_sid', 'test_app_key', 'test_app_secret'); $this->assertEquals('test_sid', $config->sid); $this->assertEquals('test_app_key', $config->appKey); $this->assertEquals('test_app_secret', $config->appSecret); $this->assertEquals(Config::PRODUCTION_BASE_URL, $config->baseUrl); $this->assertFalse($config->debug); $this->assertFalse($config->isSandbox()); } public function testGetEndpoint(): void { $config = new Config('test_sid', 'test_app_key', 'test_app_secret', 'https://api.example.com'); $this->assertEquals('https://api.example.com/test.php', $config->getEndpoint('test.php')); $this->assertEquals('https://api.example.com/test.php', $config->getEndpoint('/test.php')); } public function testGetEndpointWithTrailingSlash(): void { $config = new Config('test_sid', 'test_app_key', 'test_app_secret', 'https://api.example.com/'); $this->assertEquals('https://api.example.com/test.php', $config->getEndpoint('test.php')); $this->assertEquals('https://api.example.com/test.php', $config->getEndpoint('/test.php')); } public function testIsSandbox(): void { $sandboxConfig = new Config('sid', 'key', 'secret', Config::SANDBOX_BASE_URL); $productionConfig = new Config('sid', 'key', 'secret', Config::PRODUCTION_BASE_URL); $customSandboxConfig = new Config('sid', 'key', 'secret', 'https://sandbox.test.com'); $this->assertTrue($sandboxConfig->isSandbox()); $this->assertFalse($productionConfig->isSandbox()); $this->assertTrue($customSandboxConfig->isSandbox()); } public function testValidationWithEmptySid(): void { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('SID cannot be empty'); new Config('', 'test_app_key', 'test_app_secret'); } public function testValidationWithEmptyAppKey(): void { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('App Key cannot be empty'); new Config('test_sid', '', 'test_app_secret'); } public function testValidationWithEmptyAppSecret(): void { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('App Secret cannot be empty'); new Config('test_sid', 'test_app_key', ''); } public function testValidationWithInvalidTimeout(): void { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Timeout must be greater than 0'); new Config('test_sid', 'test_app_key', 'test_app_secret', Config::SANDBOX_BASE_URL, 0); } public function testValidationWithNegativeTimeout(): void { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Timeout must be greater than 0'); new Config('test_sid', 'test_app_key', 'test_app_secret', Config::SANDBOX_BASE_URL, -1); } public function testValidationWithInvalidBaseUrl(): void { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Invalid base URL'); new Config('test_sid', 'test_app_key', 'test_app_secret', 'invalid-url'); } public function testConstants(): void { $this->assertEquals('https://sandbox.wangdian.cn/openapi2', Config::SANDBOX_BASE_URL); $this->assertEquals('https://www.wangdian.cn/openapi2', Config::PRODUCTION_BASE_URL); } }