config = new Config( sid: $testConfig['credentials']['sid'], appKey: $testConfig['credentials']['app_key'], appSecret: $testConfig['credentials']['app_secret'], baseUrl: $testConfig['endpoints']['sandbox_base_url'], timeout: $testConfig['settings']['timeout'], debug: $testConfig['settings']['debug'] ); $this->client = new Client($this->config); } public function testConstructorWithDefaultDependencies(): void { $client = new Client($this->config); $this->assertInstanceOf(Client::class, $client); $this->assertInstanceOf(Config::class, $client->getConfig()); $this->assertInstanceOf(HttpClient::class, $client->getHttpClient()); $this->assertInstanceOf(Authenticator::class, $client->getAuthenticator()); $this->assertInstanceOf(ResponseHandler::class, $client->getResponseHandler()); } public function testConstructorWithCustomDependencies(): void { $httpClient = $this->createMock(\Psr\Http\Client\ClientInterface::class); $logger = $this->createMock(\Psr\Log\LoggerInterface::class); $client = new Client($this->config, $httpClient, $logger); $this->assertInstanceOf(Client::class, $client); $this->assertSame($this->config, $client->getConfig()); } public function testGetConfig(): void { $config = $this->client->getConfig(); $this->assertSame($this->config, $config); } public function testGetHttpClient(): void { $httpClient = $this->client->getHttpClient(); $this->assertInstanceOf(HttpClient::class, $httpClient); } public function testGetAuthenticator(): void { $authenticator = $this->client->getAuthenticator(); $this->assertInstanceOf(Authenticator::class, $authenticator); } public function testGetResponseHandler(): void { $responseHandler = $this->client->getResponseHandler(); $this->assertInstanceOf(ResponseHandler::class, $responseHandler); } public function testBasicServiceSingleton(): void { $service1 = $this->client->basic(); $service2 = $this->client->basic(); $this->assertInstanceOf(BasicService::class, $service1); $this->assertSame($service1, $service2); // Should return same instance } public function testGoodsServiceSingleton(): void { $service1 = $this->client->goods(); $service2 = $this->client->goods(); $this->assertInstanceOf(GoodsService::class, $service1); $this->assertSame($service1, $service2); // Should return same instance } public function testPurchaseServiceSingleton(): void { $service1 = $this->client->purchase(); $service2 = $this->client->purchase(); $this->assertInstanceOf(PurchaseService::class, $service1); $this->assertSame($service1, $service2); // Should return same instance } public function testRefundServiceSingleton(): void { $service1 = $this->client->refund(); $service2 = $this->client->refund(); $this->assertInstanceOf(RefundService::class, $service1); $this->assertSame($service1, $service2); // Should return same instance } public function testStockServiceSingleton(): void { $service1 = $this->client->stock(); $service2 = $this->client->stock(); $this->assertInstanceOf(StockService::class, $service1); $this->assertSame($service1, $service2); // Should return same instance } public function testTradeServiceSingleton(): void { $service1 = $this->client->trade(); $service2 = $this->client->trade(); $this->assertInstanceOf(TradeService::class, $service1); $this->assertSame($service1, $service2); // Should return same instance } public function testAllServicesAreDifferentInstances(): void { $basic = $this->client->basic(); $goods = $this->client->goods(); $purchase = $this->client->purchase(); $refund = $this->client->refund(); $stock = $this->client->stock(); $trade = $this->client->trade(); // All services should be different instances $this->assertNotSame($basic, $goods); $this->assertNotSame($basic, $purchase); $this->assertNotSame($goods, $refund); $this->assertNotSame($stock, $trade); } public function testCallMethodIntegration(): void { // Since call method requires working HTTP client and authentication, // we'll test that the method exists and has the right signature $this->assertTrue(method_exists($this->client, 'call')); $reflection = new \ReflectionMethod($this->client, 'call'); $this->assertTrue($reflection->isPublic()); $parameters = $reflection->getParameters(); $this->assertCount(2, $parameters); $this->assertEquals('endpoint', $parameters[0]->getName()); $this->assertEquals('params', $parameters[1]->getName()); $this->assertTrue($parameters[1]->isDefaultValueAvailable()); $this->assertEquals([], $parameters[1]->getDefaultValue()); } public function testServiceFactoryMethods(): void { // Test that all service factory methods exist $this->assertTrue(method_exists($this->client, 'basic')); $this->assertTrue(method_exists($this->client, 'goods')); $this->assertTrue(method_exists($this->client, 'purchase')); $this->assertTrue(method_exists($this->client, 'refund')); $this->assertTrue(method_exists($this->client, 'stock')); $this->assertTrue(method_exists($this->client, 'trade')); } public function testClientWithDifferentConfigs(): void { $config1 = Config::sandbox('sid1', 'key1', 'secret1'); $config2 = Config::production('sid2', 'key2', 'secret2'); $client1 = new Client($config1); $client2 = new Client($config2); $this->assertNotSame($client1->getConfig(), $client2->getConfig()); $this->assertTrue($client1->getConfig()->isSandbox()); $this->assertFalse($client2->getConfig()->isSandbox()); } }