|
@@ -9,7 +9,6 @@ use SixShop\Wangdian\Auth\Authenticator;
|
|
|
use SixShop\Wangdian\Client;
|
|
use SixShop\Wangdian\Client;
|
|
|
use SixShop\Wangdian\Config\Config;
|
|
use SixShop\Wangdian\Config\Config;
|
|
|
use SixShop\Wangdian\Http\HttpClient;
|
|
use SixShop\Wangdian\Http\HttpClient;
|
|
|
-use SixShop\Wangdian\Response\ApiResponse;
|
|
|
|
|
use SixShop\Wangdian\Response\ResponseHandler;
|
|
use SixShop\Wangdian\Response\ResponseHandler;
|
|
|
use SixShop\Wangdian\Services\BasicService;
|
|
use SixShop\Wangdian\Services\BasicService;
|
|
|
use SixShop\Wangdian\Services\GoodsService;
|
|
use SixShop\Wangdian\Services\GoodsService;
|
|
@@ -27,7 +26,7 @@ class ClientTest extends TestCase
|
|
|
protected function setUp(): void
|
|
protected function setUp(): void
|
|
|
{
|
|
{
|
|
|
$testConfig = TestConfig::get();
|
|
$testConfig = TestConfig::get();
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
$this->config = new Config(
|
|
$this->config = new Config(
|
|
|
sid: $testConfig['credentials']['sid'],
|
|
sid: $testConfig['credentials']['sid'],
|
|
|
appKey: $testConfig['credentials']['app_key'],
|
|
appKey: $testConfig['credentials']['app_key'],
|
|
@@ -36,14 +35,14 @@ class ClientTest extends TestCase
|
|
|
timeout: $testConfig['settings']['timeout'],
|
|
timeout: $testConfig['settings']['timeout'],
|
|
|
debug: $testConfig['settings']['debug']
|
|
debug: $testConfig['settings']['debug']
|
|
|
);
|
|
);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
$this->client = new Client($this->config);
|
|
$this->client = new Client($this->config);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function testConstructorWithDefaultDependencies(): void
|
|
public function testConstructorWithDefaultDependencies(): void
|
|
|
{
|
|
{
|
|
|
$client = new Client($this->config);
|
|
$client = new Client($this->config);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
$this->assertInstanceOf(Client::class, $client);
|
|
$this->assertInstanceOf(Client::class, $client);
|
|
|
$this->assertInstanceOf(Config::class, $client->getConfig());
|
|
$this->assertInstanceOf(Config::class, $client->getConfig());
|
|
|
$this->assertInstanceOf(HttpClient::class, $client->getHttpClient());
|
|
$this->assertInstanceOf(HttpClient::class, $client->getHttpClient());
|
|
@@ -55,9 +54,9 @@ class ClientTest extends TestCase
|
|
|
{
|
|
{
|
|
|
$httpClient = $this->createMock(\Psr\Http\Client\ClientInterface::class);
|
|
$httpClient = $this->createMock(\Psr\Http\Client\ClientInterface::class);
|
|
|
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
|
|
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
$client = new Client($this->config, $httpClient, $logger);
|
|
$client = new Client($this->config, $httpClient, $logger);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
$this->assertInstanceOf(Client::class, $client);
|
|
$this->assertInstanceOf(Client::class, $client);
|
|
|
$this->assertSame($this->config, $client->getConfig());
|
|
$this->assertSame($this->config, $client->getConfig());
|
|
|
}
|
|
}
|
|
@@ -65,28 +64,28 @@ class ClientTest extends TestCase
|
|
|
public function testGetConfig(): void
|
|
public function testGetConfig(): void
|
|
|
{
|
|
{
|
|
|
$config = $this->client->getConfig();
|
|
$config = $this->client->getConfig();
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
$this->assertSame($this->config, $config);
|
|
$this->assertSame($this->config, $config);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function testGetHttpClient(): void
|
|
public function testGetHttpClient(): void
|
|
|
{
|
|
{
|
|
|
$httpClient = $this->client->getHttpClient();
|
|
$httpClient = $this->client->getHttpClient();
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
$this->assertInstanceOf(HttpClient::class, $httpClient);
|
|
$this->assertInstanceOf(HttpClient::class, $httpClient);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function testGetAuthenticator(): void
|
|
public function testGetAuthenticator(): void
|
|
|
{
|
|
{
|
|
|
$authenticator = $this->client->getAuthenticator();
|
|
$authenticator = $this->client->getAuthenticator();
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
$this->assertInstanceOf(Authenticator::class, $authenticator);
|
|
$this->assertInstanceOf(Authenticator::class, $authenticator);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function testGetResponseHandler(): void
|
|
public function testGetResponseHandler(): void
|
|
|
{
|
|
{
|
|
|
$responseHandler = $this->client->getResponseHandler();
|
|
$responseHandler = $this->client->getResponseHandler();
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
$this->assertInstanceOf(ResponseHandler::class, $responseHandler);
|
|
$this->assertInstanceOf(ResponseHandler::class, $responseHandler);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -94,7 +93,7 @@ class ClientTest extends TestCase
|
|
|
{
|
|
{
|
|
|
$service1 = $this->client->basic();
|
|
$service1 = $this->client->basic();
|
|
|
$service2 = $this->client->basic();
|
|
$service2 = $this->client->basic();
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
$this->assertInstanceOf(BasicService::class, $service1);
|
|
$this->assertInstanceOf(BasicService::class, $service1);
|
|
|
$this->assertSame($service1, $service2); // Should return same instance
|
|
$this->assertSame($service1, $service2); // Should return same instance
|
|
|
}
|
|
}
|
|
@@ -103,7 +102,7 @@ class ClientTest extends TestCase
|
|
|
{
|
|
{
|
|
|
$service1 = $this->client->goods();
|
|
$service1 = $this->client->goods();
|
|
|
$service2 = $this->client->goods();
|
|
$service2 = $this->client->goods();
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
$this->assertInstanceOf(GoodsService::class, $service1);
|
|
$this->assertInstanceOf(GoodsService::class, $service1);
|
|
|
$this->assertSame($service1, $service2); // Should return same instance
|
|
$this->assertSame($service1, $service2); // Should return same instance
|
|
|
}
|
|
}
|
|
@@ -112,7 +111,7 @@ class ClientTest extends TestCase
|
|
|
{
|
|
{
|
|
|
$service1 = $this->client->purchase();
|
|
$service1 = $this->client->purchase();
|
|
|
$service2 = $this->client->purchase();
|
|
$service2 = $this->client->purchase();
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
$this->assertInstanceOf(PurchaseService::class, $service1);
|
|
$this->assertInstanceOf(PurchaseService::class, $service1);
|
|
|
$this->assertSame($service1, $service2); // Should return same instance
|
|
$this->assertSame($service1, $service2); // Should return same instance
|
|
|
}
|
|
}
|
|
@@ -121,7 +120,7 @@ class ClientTest extends TestCase
|
|
|
{
|
|
{
|
|
|
$service1 = $this->client->refund();
|
|
$service1 = $this->client->refund();
|
|
|
$service2 = $this->client->refund();
|
|
$service2 = $this->client->refund();
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
$this->assertInstanceOf(RefundService::class, $service1);
|
|
$this->assertInstanceOf(RefundService::class, $service1);
|
|
|
$this->assertSame($service1, $service2); // Should return same instance
|
|
$this->assertSame($service1, $service2); // Should return same instance
|
|
|
}
|
|
}
|
|
@@ -130,7 +129,7 @@ class ClientTest extends TestCase
|
|
|
{
|
|
{
|
|
|
$service1 = $this->client->stock();
|
|
$service1 = $this->client->stock();
|
|
|
$service2 = $this->client->stock();
|
|
$service2 = $this->client->stock();
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
$this->assertInstanceOf(StockService::class, $service1);
|
|
$this->assertInstanceOf(StockService::class, $service1);
|
|
|
$this->assertSame($service1, $service2); // Should return same instance
|
|
$this->assertSame($service1, $service2); // Should return same instance
|
|
|
}
|
|
}
|
|
@@ -139,7 +138,7 @@ class ClientTest extends TestCase
|
|
|
{
|
|
{
|
|
|
$service1 = $this->client->trade();
|
|
$service1 = $this->client->trade();
|
|
|
$service2 = $this->client->trade();
|
|
$service2 = $this->client->trade();
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
$this->assertInstanceOf(TradeService::class, $service1);
|
|
$this->assertInstanceOf(TradeService::class, $service1);
|
|
|
$this->assertSame($service1, $service2); // Should return same instance
|
|
$this->assertSame($service1, $service2); // Should return same instance
|
|
|
}
|
|
}
|
|
@@ -152,7 +151,7 @@ class ClientTest extends TestCase
|
|
|
$refund = $this->client->refund();
|
|
$refund = $this->client->refund();
|
|
|
$stock = $this->client->stock();
|
|
$stock = $this->client->stock();
|
|
|
$trade = $this->client->trade();
|
|
$trade = $this->client->trade();
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// All services should be different instances
|
|
// All services should be different instances
|
|
|
$this->assertNotSame($basic, $goods);
|
|
$this->assertNotSame($basic, $goods);
|
|
|
$this->assertNotSame($basic, $purchase);
|
|
$this->assertNotSame($basic, $purchase);
|
|
@@ -165,10 +164,10 @@ class ClientTest extends TestCase
|
|
|
// Since call method requires working HTTP client and authentication,
|
|
// Since call method requires working HTTP client and authentication,
|
|
|
// we'll test that the method exists and has the right signature
|
|
// we'll test that the method exists and has the right signature
|
|
|
$this->assertTrue(method_exists($this->client, 'call'));
|
|
$this->assertTrue(method_exists($this->client, 'call'));
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
$reflection = new \ReflectionMethod($this->client, 'call');
|
|
$reflection = new \ReflectionMethod($this->client, 'call');
|
|
|
$this->assertTrue($reflection->isPublic());
|
|
$this->assertTrue($reflection->isPublic());
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
$parameters = $reflection->getParameters();
|
|
$parameters = $reflection->getParameters();
|
|
|
$this->assertCount(2, $parameters);
|
|
$this->assertCount(2, $parameters);
|
|
|
$this->assertEquals('endpoint', $parameters[0]->getName());
|
|
$this->assertEquals('endpoint', $parameters[0]->getName());
|
|
@@ -192,12 +191,12 @@ class ClientTest extends TestCase
|
|
|
{
|
|
{
|
|
|
$config1 = Config::sandbox('sid1', 'key1', 'secret1');
|
|
$config1 = Config::sandbox('sid1', 'key1', 'secret1');
|
|
|
$config2 = Config::production('sid2', 'key2', 'secret2');
|
|
$config2 = Config::production('sid2', 'key2', 'secret2');
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
$client1 = new Client($config1);
|
|
$client1 = new Client($config1);
|
|
|
$client2 = new Client($config2);
|
|
$client2 = new Client($config2);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
$this->assertNotSame($client1->getConfig(), $client2->getConfig());
|
|
$this->assertNotSame($client1->getConfig(), $client2->getConfig());
|
|
|
$this->assertTrue($client1->getConfig()->isSandbox());
|
|
$this->assertTrue($client1->getConfig()->isSandbox());
|
|
|
$this->assertFalse($client2->getConfig()->isSandbox());
|
|
$this->assertFalse($client2->getConfig()->isSandbox());
|
|
|
}
|
|
}
|
|
|
-}
|
|
|
|
|
|
|
+}
|