|
|
6 tháng trước cách đây | |
|---|---|---|
| .. | ||
| Integration | 6 tháng trước cách đây | |
| Unit | 6 tháng trước cách đây | |
| config | 6 tháng trước cách đây | |
| README.md | 6 tháng trước cách đây | |
| TestConfig.php | 6 tháng trước cách đây | |
This document explains how to safely configure and run tests for the Wangdian SDK.
.env.testingtests/
├── config/
│ └── test_config.php # Mock credentials (safe to commit)
├── TestConfig.php # Configuration loader helper
├── Integration/ # Tests that can use real credentials
└── Unit/ # Tests using only mock data
.env.testing # Real credentials (NEVER commit)
.env.testing.example # Template file (safe to commit)
cp .env.testing.example .env.testing
Edit .env.testing with your actual credentials:
WANGDIAN_TEST_SID=apidevnew2
WANGDIAN_TEST_APP_KEY=rhsw02-test
WANGDIAN_TEST_APP_SECRET=03da28e20
WANGDIAN_TEST_BASE_URL=https://sandbox.wangdian.cn/openapi2
RUN_INTEGRATION_TESTS=true
RUN_REAL_API_TESTS=false
# Run only unit tests (uses mock data)
vendor/bin/phpunit tests/Unit/
# Run integration tests (uses real credentials if configured)
vendor/bin/phpunit tests/Integration/
# Run all tests
vendor/bin/phpunit
.env.testing doesn't exist → Uses mock credentialsThe following files are automatically ignored by Git:
.env.testing (contains real credentials)tests/config/credentials.php (backup protection)tests/config/real_config.php (additional protection)RUN_REAL_API_TESTS=truetests/Unit/)tests/Integration/)realapi)vendor/bin/phpunit --group realapi| Variable | Description | Default |
|---|---|---|
WANGDIAN_TEST_SID |
卖家账号 (Seller ID) | mock_sid_12345 |
WANGDIAN_TEST_APP_KEY |
接口账号 (API Key) | mock_app_key_67890 |
WANGDIAN_TEST_APP_SECRET |
接口秘钥 (API Secret) | mock_app_secret_abcdef |
WANGDIAN_TEST_BASE_URL |
API Base URL | Sandbox URL |
RUN_INTEGRATION_TESTS |
Enable integration tests | false |
RUN_REAL_API_TESTS |
Enable real API calls | false |
Use TestConfig::get() to safely load configuration:
use SixShop\Wangdian\Tests\TestConfig;
// Get configuration (auto-detects real vs mock)
$config = TestConfig::get();
// Check configuration status
if (TestConfig::isUsingRealCredentials()) {
echo "Using real credentials from .env.testing\n";
}
if (TestConfig::shouldRunIntegrationTests()) {
echo "Integration tests enabled\n";
}
.env.testing.env.testing is in .gitignore# Verify .env.testing is ignored
git status
# Should NOT show .env.testing as tracked
# Verify gitignore is working
echo "test" > .env.testing
git status
# Should NOT show .env.testing in untracked files
# Test with mock credentials (safe)
rm .env.testing
vendor/bin/phpunit tests/Unit/Config/ConfigTest.php
# Test with real credentials
cp .env.testing.example .env.testing
# Edit .env.testing with real values
vendor/bin/phpunit tests/Integration/WangdianIntegrationTest.php
The following test credentials have been securely configured:
apidevnew2rhsw02-test03da28e20These credentials are automatically loaded when .env.testing exists and never exposed in committed code.