testSid, $this->testAppKey, $this->testAppSecret ); $this->assertInstanceOf(Client::class, $client); $config = $client->getConfig(); $this->assertEquals($this->testSid, $config->sid); $this->assertEquals($this->testAppKey, $config->appKey); $this->assertEquals($this->testAppSecret, $config->appSecret); $this->assertEquals(Config::SANDBOX_BASE_URL, $config->baseUrl); $this->assertTrue($config->debug); $this->assertTrue($config->isSandbox()); } public function testCreateSandboxClientWithCustomDependencies(): void { $httpClient = $this->createMock(\Psr\Http\Client\ClientInterface::class); $logger = $this->createMock(\Psr\Log\LoggerInterface::class); $client = WangdianFactory::createSandboxClient( $this->testSid, $this->testAppKey, $this->testAppSecret, $httpClient, $logger ); $this->assertInstanceOf(Client::class, $client); $this->assertTrue($client->getConfig()->isSandbox()); } public function testCreateProductionClient(): void { $client = WangdianFactory::createProductionClient( $this->testSid, $this->testAppKey, $this->testAppSecret ); $this->assertInstanceOf(Client::class, $client); $config = $client->getConfig(); $this->assertEquals($this->testSid, $config->sid); $this->assertEquals($this->testAppKey, $config->appKey); $this->assertEquals($this->testAppSecret, $config->appSecret); $this->assertEquals(Config::PRODUCTION_BASE_URL, $config->baseUrl); $this->assertFalse($config->debug); $this->assertFalse($config->isSandbox()); } public function testCreateProductionClientWithCustomDependencies(): void { $httpClient = $this->createMock(\Psr\Http\Client\ClientInterface::class); $logger = $this->createMock(\Psr\Log\LoggerInterface::class); $client = WangdianFactory::createProductionClient( $this->testSid, $this->testAppKey, $this->testAppSecret, $httpClient, $logger ); $this->assertInstanceOf(Client::class, $client); $this->assertFalse($client->getConfig()->isSandbox()); } public function testCreateClientWithCustomConfig(): void { $customConfig = new Config( sid: $this->testSid, appKey: $this->testAppKey, appSecret: $this->testAppSecret, baseUrl: 'https://custom.api.com/v1', timeout: 60, debug: true, logFile: '/tmp/custom.log' ); $client = WangdianFactory::createClient($customConfig); $this->assertInstanceOf(Client::class, $client); $this->assertSame($customConfig, $client->getConfig()); } public function testCreateClientWithCustomConfigAndDependencies(): void { $customConfig = new Config( sid: $this->testSid, appKey: $this->testAppKey, appSecret: $this->testAppSecret ); $httpClient = $this->createMock(\Psr\Http\Client\ClientInterface::class); $logger = $this->createMock(\Psr\Log\LoggerInterface::class); $client = WangdianFactory::createClient($customConfig, $httpClient, $logger); $this->assertInstanceOf(Client::class, $client); $this->assertSame($customConfig, $client->getConfig()); } public function testCreateConfig(): void { $config = WangdianFactory::createConfig( sid: $this->testSid, appKey: $this->testAppKey, appSecret: $this->testAppSecret ); $this->assertInstanceOf(Config::class, $config); $this->assertEquals($this->testSid, $config->sid); $this->assertEquals($this->testAppKey, $config->appKey); $this->assertEquals($this->testAppSecret, $config->appSecret); $this->assertEquals(Config::SANDBOX_BASE_URL, $config->baseUrl); // Default $this->assertEquals(30, $config->timeout); // Default $this->assertFalse($config->debug); // Default $this->assertNull($config->logFile); // Default } public function testCreateConfigWithCustomParameters(): void { $customBaseUrl = 'https://custom.wangdian.com/api'; $customTimeout = 45; $customLogFile = '/var/log/wangdian.log'; $config = WangdianFactory::createConfig( sid: $this->testSid, appKey: $this->testAppKey, appSecret: $this->testAppSecret, baseUrl: $customBaseUrl, timeout: $customTimeout, debug: true, logFile: $customLogFile ); $this->assertInstanceOf(Config::class, $config); $this->assertEquals($this->testSid, $config->sid); $this->assertEquals($this->testAppKey, $config->appKey); $this->assertEquals($this->testAppSecret, $config->appSecret); $this->assertEquals($customBaseUrl, $config->baseUrl); $this->assertEquals($customTimeout, $config->timeout); $this->assertTrue($config->debug); $this->assertEquals($customLogFile, $config->logFile); } public function testCreateConfigWithProductionUrl(): void { $config = WangdianFactory::createConfig( sid: $this->testSid, appKey: $this->testAppKey, appSecret: $this->testAppSecret, baseUrl: Config::PRODUCTION_BASE_URL ); $this->assertEquals(Config::PRODUCTION_BASE_URL, $config->baseUrl); $this->assertFalse($config->isSandbox()); } public function testFactoryMethodsCreateIndependentInstances(): void { $client1 = WangdianFactory::createSandboxClient('sid1', 'key1', 'secret1'); $client2 = WangdianFactory::createSandboxClient('sid2', 'key2', 'secret2'); $this->assertNotSame($client1, $client2); $this->assertNotSame($client1->getConfig(), $client2->getConfig()); $this->assertEquals('sid1', $client1->getConfig()->sid); $this->assertEquals('sid2', $client2->getConfig()->sid); } public function testSandboxAndProductionClientsHaveDifferentConfigs(): void { $sandboxClient = WangdianFactory::createSandboxClient( $this->testSid, $this->testAppKey, $this->testAppSecret ); $productionClient = WangdianFactory::createProductionClient( $this->testSid, $this->testAppKey, $this->testAppSecret ); $sandboxConfig = $sandboxClient->getConfig(); $productionConfig = $productionClient->getConfig(); $this->assertTrue($sandboxConfig->isSandbox()); $this->assertFalse($productionConfig->isSandbox()); $this->assertTrue($sandboxConfig->debug); $this->assertFalse($productionConfig->debug); $this->assertEquals(Config::SANDBOX_BASE_URL, $sandboxConfig->baseUrl); $this->assertEquals(Config::PRODUCTION_BASE_URL, $productionConfig->baseUrl); } public function testFactoryMethodsAreStatic(): void { $reflection = new \ReflectionClass(WangdianFactory::class); $methods = [ 'createSandboxClient', 'createProductionClient', 'createClient', 'createConfig' ]; foreach ($methods as $methodName) { $method = $reflection->getMethod($methodName); $this->assertTrue($method->isStatic(), "Method {$methodName} should be static"); $this->assertTrue($method->isPublic(), "Method {$methodName} should be public"); } } }