markTestSkipped('Integration tests are disabled. Set RUN_INTEGRATION_TESTS=true in .env.testing to enable.'); } if (!TestConfig::isUsingRealCredentials()) { $this->markTestSkipped('Real credentials not configured. Please check .env.testing file.'); } $testConfig = TestConfig::get(); $this->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'] ); } public function testFactoryCreatesSandboxClient(): void { $testConfig = TestConfig::get(); $client = WangdianFactory::createSandboxClient( sid: $testConfig['credentials']['sid'], appKey: $testConfig['credentials']['app_key'], appSecret: $testConfig['credentials']['app_secret'] ); $this->assertInstanceOf(\SixShop\Wangdian\Client::class, $client); $this->assertTrue($client->getConfig()->isSandbox()); } public function testBasicAuthenticationWorkflow(): void { $testConfig = TestConfig::get(); $client = WangdianFactory::createSandboxClient( sid: $testConfig['credentials']['sid'], appKey: $testConfig['credentials']['app_key'], appSecret: $testConfig['credentials']['app_secret'] ); // Test that authenticator properly adds auth params $authenticator = $client->getAuthenticator(); $params = $authenticator->addAuthParams(['test' => 'value']); $this->assertArrayHasKey('sid', $params); $this->assertArrayHasKey('appkey', $params); $this->assertArrayHasKey('timestamp', $params); $this->assertArrayHasKey('sign', $params); $this->assertEquals($testConfig['credentials']['sid'], $params['sid']); $this->assertEquals($testConfig['credentials']['app_key'], $params['appkey']); } public function testSignatureGeneration(): void { $testConfig = TestConfig::get(); $client = WangdianFactory::createSandboxClient( sid: $testConfig['credentials']['sid'], appKey: $testConfig['credentials']['app_key'], appSecret: $testConfig['credentials']['app_secret'] ); $authenticator = $client->getAuthenticator(); $signature1 = $authenticator->generateSignature(['test' => 'value']); $signature2 = $authenticator->generateSignature(['test' => 'value']); // 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); } /** * This test makes a real API call - only run if explicitly enabled * @group realapi */ public function testRealApiCall(): void { if (!TestConfig::shouldRunRealApiTests()) { $this->markTestSkipped('Real API tests are disabled. Set RUN_REAL_API_TESTS=true in .env.testing to enable.'); } $testConfig = TestConfig::get(); $client = WangdianFactory::createSandboxClient( sid: $testConfig['credentials']['sid'], appKey: $testConfig['credentials']['app_key'], appSecret: $testConfig['credentials']['app_secret'] ); 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 } } public function testConfigurationSecurity(): void { // 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']); } }