Prechádzať zdrojové kódy

refactor: 统一代码风格

runphp 2 týždňov pred
rodič
commit
43f2dd6359
38 zmenil súbory, kde vykonal 170 pridanie a 164 odobranie
  1. 5 5
      examples/basic_example.php
  2. 17 17
      examples/stock_example.php
  3. 9 9
      examples/trade_example.php
  4. 1 1
      src/Auth/Authenticator.php
  5. 2 2
      src/Client.php
  6. 1 1
      src/Config/Config.php
  7. 1 1
      src/DTO/Trade/OrderItem.php
  8. 1 1
      src/DTO/Trade/TradeOrder.php
  9. 1 1
      src/Exception/ApiException.php
  10. 1 1
      src/Exception/AuthException.php
  11. 1 1
      src/Exception/ConfigException.php
  12. 1 1
      src/Exception/HttpException.php
  13. 1 1
      src/Exception/ValidationException.php
  14. 1 1
      src/Exception/WangdianException.php
  15. 1 1
      src/Http/HttpClient.php
  16. 1 1
      src/Response/ApiResponse.php
  17. 2 2
      src/Response/ResponseHandler.php
  18. 2 2
      src/Services/BaseService.php
  19. 3 2
      src/Services/BasicService.php
  20. 1 1
      src/Services/GoodsService.php
  21. 5 3
      src/Services/PurchaseService.php
  22. 3 2
      src/Services/RefundService.php
  23. 7 4
      src/Services/StockService.php
  24. 1 1
      src/Services/TradeService.php
  25. 1 1
      src/WangdianFactory.php
  26. 12 12
      tests/Integration/WangdianIntegrationTest.php
  27. 7 7
      tests/TestConfig.php
  28. 2 2
      tests/Unit/Auth/AuthenticatorTest.php
  29. 21 22
      tests/Unit/ClientTest.php
  30. 1 1
      tests/Unit/Config/ConfigTest.php
  31. 3 3
      tests/Unit/Exception/ExceptionTest.php
  32. 26 26
      tests/Unit/Http/HttpClientTest.php
  33. 1 1
      tests/Unit/Response/ApiResponseTest.php
  34. 5 5
      tests/Unit/Response/ResponseHandlerTest.php
  35. 10 10
      tests/Unit/Services/BaseServiceTest.php
  36. 2 2
      tests/Unit/Services/TradeServiceTest.php
  37. 6 6
      tests/Unit/WangdianFactoryTest.php
  38. 4 4
      tests/config/test_config.php

+ 5 - 5
examples/basic_example.php

@@ -19,7 +19,7 @@ try {
     // Query shop information
     echo "Querying shop information...\n";
     $response = $client->basic()->queryShop('api_test');
-    
+
     if ($response->isSuccess()) {
         $shopData = $response->getData();
         echo "Shop found: " . ($shopData['shop_name'] ?? 'Unknown') . "\n";
@@ -31,7 +31,7 @@ try {
     // Query warehouses
     echo "\nQuerying warehouses...\n";
     $response = $client->basic()->queryWarehouse();
-    
+
     if ($response->isSuccess()) {
         $warehouses = $response->getData();
         echo "Found " . count($warehouses) . " warehouses\n";
@@ -41,11 +41,11 @@ try {
     } else {
         echo "Warehouse query failed: " . $response->getMessage() . "\n";
     }
-    
+
     // Query logistics providers
     echo "\nQuerying logistics providers...\n";
     $response = $client->basic()->queryLogistics();
-    
+
     if ($response->isSuccess()) {
         $logistics = $response->getData();
         echo "Found " . count($logistics) . " logistics providers\n";
@@ -67,4 +67,4 @@ try {
     echo "HTTP Status: " . $e->getHttpStatusCode() . "\n";
 } catch (Exception $e) {
     echo "Unexpected Error: " . $e->getMessage() . "\n";
-}
+}

+ 17 - 17
examples/stock_example.php

@@ -17,28 +17,28 @@ $client = WangdianFactory::createSandboxClient(
 try {
     // Query current stock
     echo "Querying stock information...\n";
-    
+
     $queryParams = [
         'start_time' => date('Y-m-d 00:00:00', strtotime('-7 days')),
         'end_time' => date('Y-m-d 23:59:59'),
     ];
-    
+
     $response = $client->stock()->query($queryParams);
-    
+
     if ($response->isSuccess()) {
         $stocks = $response->getData();
         echo "Found " . count($stocks) . " stock records\n";
-        
+
         foreach (array_slice($stocks, 0, 10) as $stock) {
             echo "- Spec: {$stock['spec_no']}, Stock: {$stock['num']}, Warehouse: {$stock['warehouse_no']}\n";
         }
     } else {
         echo "Stock query failed: " . $response->getMessage() . "\n";
     }
-    
+
     // Push a stockin order
     echo "\nPushing stockin order...\n";
-    
+
     $stockinData = [
         'stockin_info' => [
             'warehouse_no' => '001',
@@ -55,19 +55,19 @@ try {
             ]
         ]
     ];
-    
+
     $response = $client->stock()->pushStockinOrder($stockinData);
-    
+
     if ($response->isSuccess()) {
         echo "Stockin order pushed successfully!\n";
         echo "Response: " . $response->toJson() . "\n";
     } else {
         echo "Stockin order push failed: " . $response->getMessage() . "\n";
     }
-    
+
     // Push stock transfer between warehouses
     echo "\nPushing stock transfer...\n";
-    
+
     $transferData = [
         'transfer_info' => [
             'from_warehouse_no' => '001',
@@ -83,28 +83,28 @@ try {
             ]
         ]
     ];
-    
+
     $response = $client->stock()->pushTransfer($transferData);
-    
+
     if ($response->isSuccess()) {
         echo "Stock transfer pushed successfully!\n";
         echo "Response: " . $response->toJson() . "\n";
     } else {
         echo "Stock transfer push failed: " . $response->getMessage() . "\n";
     }
-    
+
     // Query stock transfers
     echo "\nQuerying stock transfers...\n";
-    
+
     $response = $client->stock()->queryTransfer([
         'start_time' => date('Y-m-d 00:00:00'),
         'end_time' => date('Y-m-d 23:59:59'),
     ]);
-    
+
     if ($response->isSuccess()) {
         $transfers = $response->getData();
         echo "Found " . count($transfers) . " transfers today\n";
-        
+
         foreach (array_slice($transfers, 0, 5) as $transfer) {
             echo "- Transfer No: {$transfer['transfer_no']}, Status: {$transfer['status']}\n";
         }
@@ -117,4 +117,4 @@ try {
     echo "API Code: " . $e->getApiCode() . "\n";
 } catch (Exception $e) {
     echo "Error: " . $e->getMessage() . "\n";
-}
+}

+ 9 - 9
examples/trade_example.php

@@ -17,7 +17,7 @@ $client = WangdianFactory::createSandboxClient(
 try {
     // Push a trade order
     echo "Pushing trade order...\n";
-    
+
     $tradeData = [
         'shop_no' => 'api_test',
         'switch' => 0,
@@ -72,30 +72,30 @@ try {
             ]
         ]
     ];
-    
+
     $response = $client->trade()->push($tradeData);
-    
+
     if ($response->isSuccess()) {
         echo "Trade pushed successfully!\n";
         echo "Response: " . $response->toJson() . "\n";
     } else {
         echo "Trade push failed: " . $response->getMessage() . "\n";
     }
-    
+
     // Query recent trades
     echo "\nQuerying recent trades...\n";
-    
+
     $queryParams = [
         'start_time' => date('Y-m-d 00:00:00'),
         'end_time' => date('Y-m-d 23:59:59'),
     ];
-    
+
     $response = $client->trade()->query($queryParams);
-    
+
     if ($response->isSuccess()) {
         $trades = $response->getData();
         echo "Found " . count($trades) . " trades today\n";
-        
+
         foreach (array_slice($trades, 0, 5) as $trade) {
             echo "- TID: {$trade['tid']}, Status: {$trade['trade_status']}, Amount: {$trade['paid']}\n";
         }
@@ -108,4 +108,4 @@ try {
     echo "API Code: " . $e->getApiCode() . "\n";
 } catch (Exception $e) {
     echo "Error: " . $e->getMessage() . "\n";
-}
+}

+ 1 - 1
src/Auth/Authenticator.php

@@ -95,4 +95,4 @@ class Authenticator
             }
         }
     }
-}
+}

+ 2 - 2
src/Client.php

@@ -58,7 +58,7 @@ class Client
 
         // Handle and validate response
         $response = $this->responseHandler->handle($responseData);
-        
+
         // Throw exception if response indicates error
         $this->responseHandler->validateOrThrow($responseData);
 
@@ -144,4 +144,4 @@ class Client
     {
         return $this->responseHandler;
     }
-}
+}

+ 1 - 1
src/Config/Config.php

@@ -93,4 +93,4 @@ readonly class Config
             throw new \InvalidArgumentException('Invalid base URL');
         }
     }
-}
+}

+ 1 - 1
src/DTO/Trade/OrderItem.php

@@ -48,4 +48,4 @@ readonly class OrderItem
             'cid' => $this->cid,
         ];
     }
-}
+}

+ 1 - 1
src/DTO/Trade/TradeOrder.php

@@ -76,4 +76,4 @@ readonly class TradeOrder
             'order_list' => $this->orderList,
         ];
     }
-}
+}

+ 1 - 1
src/Exception/ApiException.php

@@ -29,4 +29,4 @@ class ApiException extends WangdianException
     {
         return $this->responseData;
     }
-}
+}

+ 1 - 1
src/Exception/AuthException.php

@@ -9,4 +9,4 @@ namespace SixShop\Wangdian\Exception;
  */
 class AuthException extends WangdianException
 {
-}
+}

+ 1 - 1
src/Exception/ConfigException.php

@@ -9,4 +9,4 @@ namespace SixShop\Wangdian\Exception;
  */
 class ConfigException extends WangdianException
 {
-}
+}

+ 1 - 1
src/Exception/HttpException.php

@@ -23,4 +23,4 @@ class HttpException extends WangdianException
     {
         return $this->httpStatusCode;
     }
-}
+}

+ 1 - 1
src/Exception/ValidationException.php

@@ -23,4 +23,4 @@ class ValidationException extends WangdianException
     {
         return $this->errors;
     }
-}
+}

+ 1 - 1
src/Exception/WangdianException.php

@@ -25,4 +25,4 @@ abstract class WangdianException extends \Exception
     {
         return $this->context;
     }
-}
+}

+ 1 - 1
src/Http/HttpClient.php

@@ -127,4 +127,4 @@ class HttpClient
 
         return $decoded;
     }
-}
+}

+ 1 - 1
src/Response/ApiResponse.php

@@ -85,4 +85,4 @@ readonly class ApiResponse
     {
         return $this->data[$key] ?? $default;
     }
-}
+}

+ 2 - 2
src/Response/ResponseHandler.php

@@ -51,7 +51,7 @@ class ResponseHandler
     {
         if (!$this->isSuccess($response)) {
             $error = $this->extractError($response);
-            
+
             throw new ApiException(
                 message: $error['message'],
                 code: 0,
@@ -62,4 +62,4 @@ class ResponseHandler
             );
         }
     }
-}
+}

+ 2 - 2
src/Services/BaseService.php

@@ -31,7 +31,7 @@ abstract class BaseService
     protected function validateRequired(array $params, array $required): void
     {
         foreach ($required as $field) {
-            if (!isset($params[$field]) || 
+            if (!isset($params[$field]) ||
                 (is_string($params[$field]) && empty(trim($params[$field]))) ||
                 (is_array($params[$field]) && empty($params[$field]))
             ) {
@@ -57,4 +57,4 @@ abstract class BaseService
     {
         return is_array($value) ? json_encode($value, JSON_UNESCAPED_UNICODE) : $value;
     }
-}
+}

+ 3 - 2
src/Services/BasicService.php

@@ -60,8 +60,9 @@ class BasicService extends BaseService
     {
         $this->validateRequired($providerData, ['provider_name']);
 
-        return $this->call('purchase_provider_create.php', 
+        return $this->call(
+            'purchase_provider_create.php',
             $this->filterParams($providerData)
         );
     }
-}
+}

+ 1 - 1
src/Services/GoodsService.php

@@ -50,4 +50,4 @@ class GoodsService extends BaseService
     {
         return $this->call('suites_query.php', $this->filterParams($params));
     }
-}
+}

+ 5 - 3
src/Services/PurchaseService.php

@@ -48,7 +48,8 @@ class PurchaseService extends BaseService
      */
     public function pushReturn(array $returnData): ApiResponse
     {
-        return $this->call('purchase_return_push.php', 
+        return $this->call(
+            'purchase_return_push.php',
             $this->filterParams($returnData)
         );
     }
@@ -66,7 +67,8 @@ class PurchaseService extends BaseService
      */
     public function pushStockinPurchase(array $stockinData): ApiResponse
     {
-        return $this->call('stockin_purchase_push.php', 
+        return $this->call(
+            'stockin_purchase_push.php',
             $this->filterParams($stockinData)
         );
     }
@@ -86,4 +88,4 @@ class PurchaseService extends BaseService
     {
         return $this->call('stockout_return_order_query.php', $this->filterParams($params));
     }
-}
+}

+ 3 - 2
src/Services/RefundService.php

@@ -36,7 +36,8 @@ class RefundService extends BaseService
      */
     public function pushStockinRefund(array $refundData): ApiResponse
     {
-        return $this->call('stockin_refund_push.php', 
+        return $this->call(
+            'stockin_refund_push.php',
             $this->filterParams($refundData)
         );
     }
@@ -48,4 +49,4 @@ class RefundService extends BaseService
     {
         return $this->call('stockin_refund_query.php', $this->filterParams($params));
     }
-}
+}

+ 7 - 4
src/Services/StockService.php

@@ -84,7 +84,8 @@ class StockService extends BaseService
      */
     public function pushStockinTransfer(array $transferData): ApiResponse
     {
-        return $this->call('stockin_transfer_push.php', 
+        return $this->call(
+            'stockin_transfer_push.php',
             $this->filterParams($transferData)
         );
     }
@@ -94,7 +95,8 @@ class StockService extends BaseService
      */
     public function pushStockoutTransfer(array $transferData): ApiResponse
     {
-        return $this->call('stockout_transfer_push.php', 
+        return $this->call(
+            'stockout_transfer_push.php',
             $this->filterParams($transferData)
         );
     }
@@ -104,7 +106,8 @@ class StockService extends BaseService
      */
     public function syncByPd(array $pdData): ApiResponse
     {
-        return $this->call('stock_sync_by_pd.php', 
+        return $this->call(
+            'stock_sync_by_pd.php',
             $this->filterParams($pdData)
         );
     }
@@ -116,4 +119,4 @@ class StockService extends BaseService
     {
         return $this->call('stock_pd_order_query.php', $this->filterParams($params));
     }
-}
+}

+ 1 - 1
src/Services/TradeService.php

@@ -78,4 +78,4 @@ class TradeService extends BaseService
     {
         return $this->call('stockout_order_query_trade.php', $this->filterParams($params));
     }
-}
+}

+ 1 - 1
src/WangdianFactory.php

@@ -74,4 +74,4 @@ class WangdianFactory
             logFile: $logFile
         );
     }
-}
+}

+ 12 - 12
tests/Integration/WangdianIntegrationTest.php

@@ -30,7 +30,7 @@ class WangdianIntegrationTest extends TestCase
         $testConfig = TestConfig::get();
         $this->config = new Config(
             sid: $testConfig['credentials']['sid'],
-            appKey: $testConfig['credentials']['app_key'], 
+            appKey: $testConfig['credentials']['app_key'],
             appSecret: $testConfig['credentials']['app_secret'],
             baseUrl: $testConfig['endpoints']['sandbox_base_url'],
             timeout: $testConfig['settings']['timeout'],
@@ -41,7 +41,7 @@ class WangdianIntegrationTest extends TestCase
     public function testFactoryCreatesSandboxClient(): void
     {
         $testConfig = TestConfig::get();
-        
+
         $client = WangdianFactory::createSandboxClient(
             sid: $testConfig['credentials']['sid'],
             appKey: $testConfig['credentials']['app_key'],
@@ -55,7 +55,7 @@ class WangdianIntegrationTest extends TestCase
     public function testBasicAuthenticationWorkflow(): void
     {
         $testConfig = TestConfig::get();
-        
+
         $client = WangdianFactory::createSandboxClient(
             sid: $testConfig['credentials']['sid'],
             appKey: $testConfig['credentials']['app_key'],
@@ -77,7 +77,7 @@ class WangdianIntegrationTest extends TestCase
     public function testSignatureGeneration(): void
     {
         $testConfig = TestConfig::get();
-        
+
         $client = WangdianFactory::createSandboxClient(
             sid: $testConfig['credentials']['sid'],
             appKey: $testConfig['credentials']['app_key'],
@@ -91,7 +91,7 @@ class WangdianIntegrationTest extends TestCase
         // Signatures should be valid MD5 hashes
         $this->assertMatchesRegularExpression('/^[a-f0-9]{32}$/', $signature1);
         $this->assertMatchesRegularExpression('/^[a-f0-9]{32}$/', $signature2);
-        
+
         // Note: They may be different due to timestamp differences
         $this->assertIsString($signature1);
         $this->assertIsString($signature2);
@@ -108,7 +108,7 @@ class WangdianIntegrationTest extends TestCase
         }
 
         $testConfig = TestConfig::get();
-        
+
         $client = WangdianFactory::createSandboxClient(
             sid: $testConfig['credentials']['sid'],
             appKey: $testConfig['credentials']['app_key'],
@@ -118,16 +118,16 @@ class WangdianIntegrationTest extends TestCase
         try {
             // Try to query warehouses - this should work with valid credentials
             $response = $client->basic()->queryWarehouse();
-            
+
             $this->assertInstanceOf(\SixShop\Wangdian\Response\ApiResponse::class, $response);
             // Don't assert success as it depends on actual API status
             $this->assertIsInt($response->getCode());
             $this->assertIsString($response->getMessage());
-            
+
         } catch (\SixShop\Wangdian\Exception\ApiException $e) {
             // API exceptions are expected with test credentials
             $this->addToAssertionCount(1); // Count as assertion
-            
+
         } catch (\SixShop\Wangdian\Exception\HttpException $e) {
             // HTTP exceptions might indicate network issues
             $this->addToAssertionCount(1); // Count as assertion
@@ -138,15 +138,15 @@ class WangdianIntegrationTest extends TestCase
     {
         // Ensure real credentials are not accidentally logged or exposed
         $testConfig = TestConfig::get();
-        
+
         $this->assertTrue(TestConfig::isUsingRealCredentials());
         $this->assertNotEquals('mock_sid_12345', $testConfig['credentials']['sid']);
         $this->assertNotEquals('mock_app_key_67890', $testConfig['credentials']['app_key']);
         $this->assertNotEquals('mock_app_secret_abcdef', $testConfig['credentials']['app_secret']);
-        
+
         // Verify the real credentials match what was provided
         $this->assertEquals('apidevnew2', $testConfig['credentials']['sid']);
         $this->assertEquals('rhsw02-test', $testConfig['credentials']['app_key']);
         $this->assertEquals('03da28e20', $testConfig['credentials']['app_secret']);
     }
-}
+}

+ 7 - 7
tests/TestConfig.php

@@ -31,24 +31,24 @@ class TestConfig
             if ($envContent !== false) {
                 $lines = explode("\n", $envContent);
                 $envVars = [];
-                
+
                 foreach ($lines as $line) {
                     $line = trim($line);
                     if (empty($line) || str_starts_with($line, '#')) {
                         continue;
                     }
-                    
+
                     $parts = explode('=', $line, 2);
                     if (count($parts) === 2) {
                         $envVars[$parts[0]] = $parts[1];
                     }
                 }
-                
-                if (isset($envVars['WANGDIAN_TEST_SID']) && 
-                    isset($envVars['WANGDIAN_TEST_APP_KEY']) && 
+
+                if (isset($envVars['WANGDIAN_TEST_SID']) &&
+                    isset($envVars['WANGDIAN_TEST_APP_KEY']) &&
                     isset($envVars['WANGDIAN_TEST_APP_SECRET'])) {
                     $useRealCredentials = true;
-                    
+
                     self::$config = [
                         'credentials' => [
                             'sid' => $envVars['WANGDIAN_TEST_SID'],
@@ -145,4 +145,4 @@ class TestConfig
             ],
         ];
     }
-}
+}

+ 2 - 2
tests/Unit/Auth/AuthenticatorTest.php

@@ -45,7 +45,7 @@ class AuthenticatorTest extends TestCase
         ];
 
         $signature1 = $this->authenticator->generateSignature($params);
-        
+
         unset($params['sign']);
         $signature2 = $this->authenticator->generateSignature($params);
 
@@ -226,4 +226,4 @@ class AuthenticatorTest extends TestCase
         $expected = '01-a:0005-value';
         $this->assertEquals($expected, $packed);
     }
-}
+}

+ 21 - 22
tests/Unit/ClientTest.php

@@ -9,7 +9,6 @@ use SixShop\Wangdian\Auth\Authenticator;
 use SixShop\Wangdian\Client;
 use SixShop\Wangdian\Config\Config;
 use SixShop\Wangdian\Http\HttpClient;
-use SixShop\Wangdian\Response\ApiResponse;
 use SixShop\Wangdian\Response\ResponseHandler;
 use SixShop\Wangdian\Services\BasicService;
 use SixShop\Wangdian\Services\GoodsService;
@@ -27,7 +26,7 @@ class ClientTest extends TestCase
     protected function setUp(): void
     {
         $testConfig = TestConfig::get();
-        
+
         $this->config = new Config(
             sid: $testConfig['credentials']['sid'],
             appKey: $testConfig['credentials']['app_key'],
@@ -36,14 +35,14 @@ class ClientTest extends TestCase
             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());
@@ -55,9 +54,9 @@ class ClientTest extends TestCase
     {
         $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());
     }
@@ -65,28 +64,28 @@ class ClientTest extends TestCase
     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);
     }
 
@@ -94,7 +93,7 @@ class ClientTest extends TestCase
     {
         $service1 = $this->client->basic();
         $service2 = $this->client->basic();
-        
+
         $this->assertInstanceOf(BasicService::class, $service1);
         $this->assertSame($service1, $service2); // Should return same instance
     }
@@ -103,7 +102,7 @@ class ClientTest extends TestCase
     {
         $service1 = $this->client->goods();
         $service2 = $this->client->goods();
-        
+
         $this->assertInstanceOf(GoodsService::class, $service1);
         $this->assertSame($service1, $service2); // Should return same instance
     }
@@ -112,7 +111,7 @@ class ClientTest extends TestCase
     {
         $service1 = $this->client->purchase();
         $service2 = $this->client->purchase();
-        
+
         $this->assertInstanceOf(PurchaseService::class, $service1);
         $this->assertSame($service1, $service2); // Should return same instance
     }
@@ -121,7 +120,7 @@ class ClientTest extends TestCase
     {
         $service1 = $this->client->refund();
         $service2 = $this->client->refund();
-        
+
         $this->assertInstanceOf(RefundService::class, $service1);
         $this->assertSame($service1, $service2); // Should return same instance
     }
@@ -130,7 +129,7 @@ class ClientTest extends TestCase
     {
         $service1 = $this->client->stock();
         $service2 = $this->client->stock();
-        
+
         $this->assertInstanceOf(StockService::class, $service1);
         $this->assertSame($service1, $service2); // Should return same instance
     }
@@ -139,7 +138,7 @@ class ClientTest extends TestCase
     {
         $service1 = $this->client->trade();
         $service2 = $this->client->trade();
-        
+
         $this->assertInstanceOf(TradeService::class, $service1);
         $this->assertSame($service1, $service2); // Should return same instance
     }
@@ -152,7 +151,7 @@ class ClientTest extends TestCase
         $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);
@@ -165,10 +164,10 @@ class ClientTest extends TestCase
         // 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());
@@ -192,12 +191,12 @@ class ClientTest extends TestCase
     {
         $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());
     }
-}
+}

+ 1 - 1
tests/Unit/Config/ConfigTest.php

@@ -151,4 +151,4 @@ class ConfigTest extends TestCase
         $this->assertEquals('https://sandbox.wangdian.cn/openapi2', Config::SANDBOX_BASE_URL);
         $this->assertEquals('https://www.wangdian.cn/openapi2', Config::PRODUCTION_BASE_URL);
     }
-}
+}

+ 3 - 3
tests/Unit/Exception/ExceptionTest.php

@@ -20,7 +20,7 @@ class ExceptionTest extends TestCase
         $code = 123;
         $context = ['key' => 'value'];
 
-        $exception = new class($message, $code, null, $context) extends WangdianException {};
+        $exception = new class ($message, $code, null, $context) extends WangdianException {};
 
         $this->assertEquals($message, $exception->getMessage());
         $this->assertEquals($code, $exception->getCode());
@@ -32,7 +32,7 @@ class ExceptionTest extends TestCase
     public function testWangdianExceptionWithPrevious(): void
     {
         $previous = new \Exception('Previous exception');
-        $exception = new class('Test', 0, $previous) extends WangdianException {};
+        $exception = new class ('Test', 0, $previous) extends WangdianException {};
 
         $this->assertSame($previous, $exception->getPrevious());
     }
@@ -210,4 +210,4 @@ class ExceptionTest extends TestCase
         $this->assertEquals($unicodeContext, $exception->getContext());
         $this->assertEquals($unicodeApiCode, $exception->getApiCode());
     }
-}
+}

+ 26 - 26
tests/Unit/Http/HttpClientTest.php

@@ -24,7 +24,7 @@ class HttpClientTest extends TestCase
     {
         // Use secure test configuration
         $testConfig = TestConfig::get();
-        
+
         $this->config = new Config(
             sid: $testConfig['credentials']['sid'],
             appKey: $testConfig['credentials']['app_key'],
@@ -38,7 +38,7 @@ class HttpClientTest extends TestCase
     public function testConstructorWithDefaultClient(): void
     {
         $httpClient = new HttpClient($this->config);
-        
+
         $this->assertInstanceOf(HttpClient::class, $httpClient);
     }
 
@@ -46,18 +46,18 @@ class HttpClientTest extends TestCase
     {
         $mockResponses = TestConfig::getMockResponses();
         $mockResponse = json_encode($mockResponses['success']);
-        
+
         // Create a mock handler with successful response
         $mock = new MockHandler([
             new Response(200, [], $mockResponse)
         ]);
         $handlerStack = HandlerStack::create($mock);
         $mockClient = new Client(['handler' => $handlerStack]);
-        
+
         $httpClient = new HttpClient($this->config, $mockClient);
-        
+
         $result = $httpClient->post('test_endpoint.php', ['param' => 'value']);
-        
+
         $this->assertEquals($mockResponses['success'], $result);
     }
 
@@ -68,12 +68,12 @@ class HttpClientTest extends TestCase
         ]);
         $handlerStack = HandlerStack::create($mock);
         $mockClient = new Client(['handler' => $handlerStack]);
-        
+
         $httpClient = new HttpClient($this->config, $mockClient);
-        
+
         $this->expectException(HttpException::class);
         $this->expectExceptionMessageMatches('/HTTP request failed.*500/');
-        
+
         $httpClient->post('test_endpoint.php', ['param' => 'value']);
     }
 
@@ -84,12 +84,12 @@ class HttpClientTest extends TestCase
         ]);
         $handlerStack = HandlerStack::create($mock);
         $mockClient = new Client(['handler' => $handlerStack]);
-        
+
         $httpClient = new HttpClient($this->config, $mockClient);
-        
+
         $this->expectException(HttpException::class);
         $this->expectExceptionMessage('Failed to parse JSON response');
-        
+
         $httpClient->post('test_endpoint.php', ['param' => 'value']);
     }
 
@@ -100,12 +100,12 @@ class HttpClientTest extends TestCase
         ]);
         $handlerStack = HandlerStack::create($mock);
         $mockClient = new Client(['handler' => $handlerStack]);
-        
+
         $httpClient = new HttpClient($this->config, $mockClient);
-        
+
         $this->expectException(HttpException::class);
         $this->expectExceptionMessage('Empty response body received');
-        
+
         $httpClient->post('test_endpoint.php', ['param' => 'value']);
     }
 
@@ -116,12 +116,12 @@ class HttpClientTest extends TestCase
         ]);
         $handlerStack = HandlerStack::create($mock);
         $mockClient = new Client(['handler' => $handlerStack]);
-        
+
         $httpClient = new HttpClient($this->config, $mockClient);
-        
+
         $this->expectException(HttpException::class);
         $this->expectExceptionMessage('HTTP request failed: Connection timeout');
-        
+
         $httpClient->post('test_endpoint.php', ['param' => 'value']);
     }
 
@@ -129,17 +129,17 @@ class HttpClientTest extends TestCase
     {
         $mockResponses = TestConfig::getMockResponses();
         $mockResponse = json_encode($mockResponses['success']);
-        
+
         $mock = new MockHandler([
             new Response(200, [], $mockResponse)
         ]);
         $handlerStack = HandlerStack::create($mock);
         $mockClient = new Client(['handler' => $handlerStack]);
-        
+
         $httpClient = new HttpClient($this->config, $mockClient);
-        
+
         $result = $httpClient->post('trade_push.php', ['test' => 'data']);
-        
+
         $this->assertEquals($mockResponses['success'], $result);
     }
 
@@ -147,7 +147,7 @@ class HttpClientTest extends TestCase
     {
         $sandboxConfig = Config::sandbox('test_sid', 'test_key', 'test_secret');
         $httpClient = new HttpClient($sandboxConfig);
-        
+
         $this->assertInstanceOf(HttpClient::class, $httpClient);
         $this->assertTrue($sandboxConfig->isSandbox());
     }
@@ -159,9 +159,9 @@ class HttpClientTest extends TestCase
         ]);
         $handlerStack = HandlerStack::create($mock);
         $mockClient = new Client(['handler' => $handlerStack]);
-        
+
         $httpClient = new HttpClient($this->config, $mockClient);
-        
+
         try {
             $httpClient->post('test_endpoint.php', ['param' => 'value']);
             $this->fail('Expected HttpException was not thrown');
@@ -172,4 +172,4 @@ class HttpClientTest extends TestCase
             $this->assertArrayHasKey('data', $context);
         }
     }
-}
+}

+ 1 - 1
tests/Unit/Response/ApiResponseTest.php

@@ -211,4 +211,4 @@ class ApiResponseTest extends TestCase
         $this->assertEquals($complexData, $response->getData());
         $this->assertEquals(2, $response->getData()['meta']['total']);
     }
-}
+}

+ 5 - 5
tests/Unit/Response/ResponseHandlerTest.php

@@ -38,28 +38,28 @@ class ResponseHandlerTest extends TestCase
     public function testIsSuccessWithZeroCode(): void
     {
         $responseData = ['code' => 0];
-        
+
         $this->assertTrue($this->handler->isSuccess($responseData));
     }
 
     public function testIsSuccessWithStringZeroCode(): void
     {
         $responseData = ['code' => '0'];
-        
+
         $this->assertTrue($this->handler->isSuccess($responseData));
     }
 
     public function testIsSuccessWithNonZeroCode(): void
     {
         $responseData = ['code' => 1];
-        
+
         $this->assertFalse($this->handler->isSuccess($responseData));
     }
 
     public function testIsSuccessWithMissingCode(): void
     {
         $responseData = ['message' => 'Some message'];
-        
+
         $this->assertFalse($this->handler->isSuccess($responseData));
     }
 
@@ -216,4 +216,4 @@ class ResponseHandlerTest extends TestCase
         $this->expectException(ApiException::class);
         $this->handler->validateOrThrow($errorData);
     }
-}
+}

+ 10 - 10
tests/Unit/Services/BaseServiceTest.php

@@ -37,12 +37,12 @@ class BaseServiceTest extends TestCase
     protected function setUp(): void
     {
         $testConfig = TestConfig::get();
-        
+
         // Create a minimal client mock for constructor
         $client = $this->getMockBuilder(Client::class)
             ->disableOriginalConstructor()
             ->getMock();
-            
+
         $this->service = new MockService($client);
     }
 
@@ -132,7 +132,7 @@ class BaseServiceTest extends TestCase
     {
         $array = ['key1' => 'value1', 'key2' => 'value2'];
         $result = $this->service->testEncodeIfArray($array);
-        
+
         $this->assertIsString($result);
         $this->assertEquals('{"key1":"value1","key2":"value2"}', $result);
     }
@@ -145,7 +145,7 @@ class BaseServiceTest extends TestCase
             ]
         ];
         $result = $this->service->testEncodeIfArray($array);
-        
+
         $this->assertIsString($result);
         $decoded = json_decode($result, true);
         $this->assertEquals($array, $decoded);
@@ -155,7 +155,7 @@ class BaseServiceTest extends TestCase
     {
         $string = 'test_string';
         $result = $this->service->testEncodeIfArray($string);
-        
+
         $this->assertEquals($string, $result);
         $this->assertIsString($result);
     }
@@ -164,7 +164,7 @@ class BaseServiceTest extends TestCase
     {
         $number = 12345;
         $result = $this->service->testEncodeIfArray($number);
-        
+
         $this->assertEquals($number, $result);
         $this->assertIsInt($result);
     }
@@ -172,7 +172,7 @@ class BaseServiceTest extends TestCase
     public function testEncodeIfArrayWithNull(): void
     {
         $result = $this->service->testEncodeIfArray(null);
-        
+
         $this->assertNull($result);
     }
 
@@ -180,7 +180,7 @@ class BaseServiceTest extends TestCase
     {
         $result = $this->service->testEncodeIfArray(true);
         $this->assertTrue($result);
-        
+
         $result = $this->service->testEncodeIfArray(false);
         $this->assertFalse($result);
     }
@@ -189,11 +189,11 @@ class BaseServiceTest extends TestCase
     {
         $array = ['中文' => '测试', '数据' => ['嵌套' => '值']];
         $result = $this->service->testEncodeIfArray($array);
-        
+
         $this->assertIsString($result);
         $this->assertStringContainsString('中文', $result);
         $this->assertStringContainsString('测试', $result);
         $decoded = json_decode($result, true);
         $this->assertEquals($array, $decoded);
     }
-}
+}

+ 2 - 2
tests/Unit/Services/TradeServiceTest.php

@@ -19,7 +19,7 @@ class TradeServiceTest extends TestCase
         $this->client = $this->getMockBuilder(Client::class)
             ->disableOriginalConstructor()
             ->getMock();
-            
+
         $this->service = new TradeService($this->client);
     }
 
@@ -222,4 +222,4 @@ class TradeServiceTest extends TestCase
         $result = $this->service->queryStockoutOrder($params);
         $this->assertSame($expectedResponse, $result);
     }
-}
+}

+ 6 - 6
tests/Unit/WangdianFactoryTest.php

@@ -24,7 +24,7 @@ class WangdianFactoryTest extends TestCase
         );
 
         $this->assertInstanceOf(Client::class, $client);
-        
+
         $config = $client->getConfig();
         $this->assertEquals($this->testSid, $config->sid);
         $this->assertEquals($this->testAppKey, $config->appKey);
@@ -60,7 +60,7 @@ class WangdianFactoryTest extends TestCase
         );
 
         $this->assertInstanceOf(Client::class, $client);
-        
+
         $config = $client->getConfig();
         $this->assertEquals($this->testSid, $config->sid);
         $this->assertEquals($this->testAppKey, $config->appKey);
@@ -112,7 +112,7 @@ class WangdianFactoryTest extends TestCase
             appKey: $this->testAppKey,
             appSecret: $this->testAppSecret
         );
-        
+
         $httpClient = $this->createMock(\Psr\Http\Client\ClientInterface::class);
         $logger = $this->createMock(\Psr\Log\LoggerInterface::class);
 
@@ -197,7 +197,7 @@ class WangdianFactoryTest extends TestCase
             $this->testAppKey,
             $this->testAppSecret
         );
-        
+
         $productionClient = WangdianFactory::createProductionClient(
             $this->testSid,
             $this->testAppKey,
@@ -218,7 +218,7 @@ class WangdianFactoryTest extends TestCase
     public function testFactoryMethodsAreStatic(): void
     {
         $reflection = new \ReflectionClass(WangdianFactory::class);
-        
+
         $methods = [
             'createSandboxClient',
             'createProductionClient',
@@ -232,4 +232,4 @@ class WangdianFactoryTest extends TestCase
             $this->assertTrue($method->isPublic(), "Method {$methodName} should be public");
         }
     }
-}
+}

+ 4 - 4
tests/config/test_config.php

@@ -15,20 +15,20 @@ return [
         'app_key' => 'mock_app_key_67890',
         'app_secret' => 'mock_app_secret_abcdef',
     ],
-    
+
     // Mock API endpoints for testing
     'test_endpoints' => [
         'sandbox_base_url' => 'https://mock-api.example.com/openapi2',
         'production_base_url' => 'https://mock-prod-api.example.com/openapi2',
     ],
-    
+
     // Test timeouts and settings
     'test_settings' => [
         'timeout' => 5, // Shorter timeout for tests
         'debug' => true,
         'log_file' => null, // No logging during tests
     ],
-    
+
     // Mock response data for testing
     'mock_responses' => [
         'success' => [
@@ -42,4 +42,4 @@ return [
             'data' => null
         ],
     ],
-];
+];