diff --git a/.env.dist b/.env.dist new file mode 100644 index 0000000..0bcd1a4 --- /dev/null +++ b/.env.dist @@ -0,0 +1,4 @@ +ENDPOINT=https://api.taobao.com/router/rest +APP_KEY=00000000 +APP_SECRET=d784fa8b6d98d27699781bd9a7cf19f0 +SESSION=test diff --git a/.gitignore b/.gitignore index 906105c..1465077 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ phpunit.xml .project .swp /nbproject +.env diff --git a/composer.json b/composer.json index e8dc9d4..e9f801a 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,8 @@ "squizlabs/php_codesniffer": "^3.5", "guzzlehttp/guzzle": "^7.1", "phpcompatibility/php-compatibility": "*", - "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0" + "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0", + "vlucas/phpdotenv": "^5.2" }, "scripts": { "phpunit": "./vendor/bin/phpunit -c phpunit.xml.dist", diff --git a/src/TopClient/Client.php b/src/TopClient/Client.php index 2a3857a..0e49614 100644 --- a/src/TopClient/Client.php +++ b/src/TopClient/Client.php @@ -18,7 +18,6 @@ use RetailCrm\Component\ServiceLocator; use RetailCrm\Interfaces\AppDataInterface; use RetailCrm\Interfaces\AuthenticatorInterface; use RetailCrm\Interfaces\RequestFactoryInterface; -use RetailCrm\Interfaces\RequestTimestampProviderInterface; use RetailCrm\Model\Request\BaseRequest; use RetailCrm\Traits\ValidatorAwareTrait; use Symfony\Component\Validator\Constraints as Assert; diff --git a/tests/RetailCrm/Test/TestCase.php b/tests/RetailCrm/Test/TestCase.php index c7aede4..dabbc6f 100644 --- a/tests/RetailCrm/Test/TestCase.php +++ b/tests/RetailCrm/Test/TestCase.php @@ -49,9 +49,39 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase /** * @return \RetailCrm\Interfaces\AppDataInterface */ - protected function getAppData(): AppDataInterface + protected function getEnvAppData(): AppDataInterface { - return new AppData(AppData::OVERSEAS_ENDPOINT, 'appKey', 'helloworld'); + return $this->getAppData( + self::getenv('ENDPOINT', AppData::OVERSEAS_ENDPOINT), + self::getenv('APP_KEY', 'appKey'), + self::getenv('APP_SECRET', 'helloworld') + ); + } + + /** + * @param string $endpoint + * @param string $appKey + * @param string $appSecret + * + * @return \RetailCrm\Interfaces\AppDataInterface + */ + protected function getAppData( + string $endpoint = AppData::OVERSEAS_ENDPOINT, + string $appKey = 'appKey', + string $appSecret = 'helloworld' + ): AppDataInterface{ + return new AppData($endpoint, $appKey, $appSecret); + } + + /** + * @return \RetailCrm\Interfaces\AuthenticatorInterface + */ + protected function getEnvAuthenticator(): AuthenticatorInterface + { + return $this->getAuthenticator( + self::getenv('APP_KEY', 'appKey'), + self::getenv('SESSION', 'helloworld') + ); } /** @@ -100,4 +130,19 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase return $request; } + + /** + * @param string $variable + * @param mixed $default + * + * @return mixed|null + */ + protected static function getenv(string $variable, $default = null) + { + if (!array_key_exists($variable, $_ENV)) { + return $default; + } + + return $_ENV[$variable]; + } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 26ce5dc..4ea496c 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -8,3 +8,5 @@ if (function_exists('date_default_timezone_set') $loader = include dirname(__DIR__) . '/vendor/autoload.php'; $loader->add('RetailCrm\\Test', __DIR__); +$dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/..'); +$dotenv->load();