diff --git a/.gitignore b/.gitignore index d3987a5..a48827e 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,6 @@ build/phplint.cache /test-requirements.txt /.env /.idea/ +/__tests__/_generated/ +/__tests__/_output/ +/__tests__/Support/ diff --git a/__tests__/Acceptance.suite.yml b/__tests__/Acceptance.suite.yml deleted file mode 100644 index 5b10b9d..0000000 --- a/__tests__/Acceptance.suite.yml +++ /dev/null @@ -1,16 +0,0 @@ -# Codeception Test Suite Configuration -# -# Suite for acceptance tests. -# Perform tests in browser using the WebDriver or PhpBrowser. -# If you need both WebDriver and PHPBrowser tests - create a separate suite. - -actor: AcceptanceTester -modules: - enabled: - - PhpBrowser: - url: http://localhost/myapp -# add Codeception\Step\Retry trait to AcceptanceTester to enable retries -step_decorators: - - Codeception\Step\ConditionalAssertion - - Codeception\Step\TryTo - - Codeception\Step\Retry diff --git a/__tests__/Functional.suite.yml b/__tests__/Functional.suite.yml deleted file mode 100644 index 1b7276a..0000000 --- a/__tests__/Functional.suite.yml +++ /dev/null @@ -1,12 +0,0 @@ -# Codeception Test Suite Configuration -# -# Suite for functional tests -# Emulate web requests and make application process them -# Include one of framework modules (Symfony, Yii2, Laravel, Phalcon5) to use it -# Remove this suite if you don't use frameworks - -actor: FunctionalTester -modules: - enabled: - # add a framework module here -step_decorators: ~ diff --git a/__tests__/README_TESTS.md b/__tests__/README_TESTS.md new file mode 100644 index 0000000..9588f48 --- /dev/null +++ b/__tests__/README_TESTS.md @@ -0,0 +1,54 @@ +## Tool: +We use `codeception` for testing. You shall have installed `codeception` via `composer` in order to run the tests. + + +## How to write tests: +All tests shall be in `__tests__/Unit/` folder. And shall be named as `*Test.php`. All test functions shall be named as `test*` (see example). + +Import sdk: + +```php +require_once(dirname(dirname(__DIR__)) . '/vendor/autoload.php'); +``` + +Good practice is to use `_before` to configure sdks APIs: +```php + + //example + protected function _before() + { + //load .env + $env = parse_ini_file('.env'); + + $config = OpenAPI\Client\Configuration::getDefaultConfiguration()->setApiKey('X-App-Id', $env["X_APP_ID"]); + $config = OpenAPI\Client\Configuration::getDefaultConfiguration()->setApiKey('X-App-Token', $env["X_APP_TOKEN"]); + $config = OpenAPI\Client\Configuration::getDefaultConfiguration()->setHost($env["VOUCHERIFY_HOST"]); + + $this->productsApiInstance = new OpenAPI\Client\Api\ProductsApi( + new GuzzleHttp\Client(), + $config + ); + $this->campaignsApiInstance = new OpenAPI\Client\Api\CampaignsApi( + new GuzzleHttp\Client(), + $config + ); + $this->redemptionsApiInstance = new OpenAPI\Client\Api\RedemptionsApi( + new GuzzleHttp\Client(), + $config + ); + } + +``` + +Test example: +```php + //example + public function testListRedemptions() + { + $this->redemptionsApiInstance->listRedemptions(1, 1); + } +``` + + +## Environment variables: +`.env` file shall be in the root of the project and shall contain `X_APP_ID`, `X_APP_TOKEN` and `VOUCHERIFY_HOST` variables. Check `.env.example` for reference. diff --git a/__tests__/Support/AcceptanceTester.php b/__tests__/Support/AcceptanceTester.php deleted file mode 100644 index 6ccbabd..0000000 --- a/__tests__/Support/AcceptanceTester.php +++ /dev/null @@ -1,29 +0,0 @@ -