Repository navigation
Polish code and add github actions for running tests #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
85ef7bb
Fixed timeout handling and HTTP error mapping
duxthefux dbd6980
Added mocked unit tests and made live tests skippable
duxthefux 4a8bc3a
Updated dependencies and tooling
duxthefux c3c23c4
Added GitHub Actions workflow
duxthefux 131acb2
Updated README with development and test instructions
duxthefux c0f5c2f
Added live API job to GitHub Actions workflow
duxthefux ffd8986
Added PHP 7.4 check to GitHub Actions workflow
duxthefux e5aa38a
Run live API job only after checks passed
duxthefux 6f1befc
Addressed review comments on Client
duxthefux fb640a5
Hardened Client error handling and documented upgrade
duxthefux 58de139
Fixed test wiring and CI follow-ups from review
duxthefux cbf2d22
Fixed code style failure on PHP 8.4
duxthefux e125efb
Fixed live test using non-public company endpoint
duxthefux 1ac704a
Removed AccountTest from the api suite
duxthefux 46a47ba
Sent request bodies as JSON instead of form data
duxthefux File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| /.env.example export-ignore | ||
| /.gitattributes export-ignore | ||
| /.github export-ignore | ||
| /.gitignore export-ignore | ||
| /.php-cs-fixer.php export-ignore | ||
| /phpstan.neon export-ignore | ||
| /phpunit.xml export-ignore | ||
| /tests export-ignore |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| <?php | ||
|
|
||
| // Runtime smoke test for the minimum supported PHP version (7.4). | ||
| // Uses only production dependencies: Guzzle's MockHandler stands in for the network. | ||
| // Usage: php php74-smoke.php <path to the consumer project's vendor/autoload.php> | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| require $argv[1]; | ||
|
|
||
| use GuzzleHttp\Client as GuzzleClient; | ||
| use GuzzleHttp\Handler\MockHandler; | ||
| use GuzzleHttp\Psr7\Response; | ||
| use ready2order\Client; | ||
|
|
||
| $mock = new MockHandler([new Response(200, [], '{"company_name":"ACME"}')]); | ||
| $client = new Client('token', 'http://smoke.test/v1', new GuzzleClient(['handler' => $mock])); | ||
|
|
||
| if ($client->setTimeout(5)->setLanguage('de-DE')->getTimeout() !== 5) { | ||
| fwrite(STDERR, "setTimeout/getTimeout failed\n"); | ||
| exit(1); | ||
| } | ||
|
|
||
| if ($client->get('company') !== ['company_name' => 'ACME']) { | ||
| fwrite(STDERR, "get() returned unexpected data\n"); | ||
| exit(1); | ||
| } | ||
|
|
||
| echo 'OK on PHP ' . PHP_VERSION . "\n"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: [master] | ||
| pull_request: | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| checks: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 10 | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| php: ['8.3', '8.4'] | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: shivammathur/setup-php@v2 | ||
| with: | ||
| php-version: ${{ matrix.php }} | ||
| extensions: curl, json, mbstring | ||
| coverage: none | ||
|
|
||
| - run: composer validate --strict | ||
|
|
||
| - run: composer install --no-interaction --prefer-dist | ||
|
|
||
| - name: Code style | ||
| run: composer lint:check | ||
|
|
||
| - name: Static analysis | ||
| run: composer analyse | ||
|
|
||
| # Unit tests use mocked HTTP; no network or token needed. | ||
| - name: Unit tests | ||
| run: composer test | ||
|
|
||
| # composer.json claims PHP >=7.4, but the dev dependencies (PHPUnit 12) need | ||
| # 8.3, so the test suite cannot run there. Instead install the library into a | ||
| # throwaway project like a consumer would (only `require` is resolved), then | ||
| # lint it and run a smoke test. | ||
| php74: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 10 | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: shivammathur/setup-php@v2 | ||
| with: | ||
| php-version: '7.4' | ||
| extensions: curl, json, mbstring | ||
| coverage: none | ||
|
|
||
| - name: Lint src | ||
| run: find src -name '*.php' -print0 | xargs -0 -n1 php -l | ||
|
|
||
| - name: Install as a consumer would | ||
| run: | | ||
| mkdir "$RUNNER_TEMP/consumer" | ||
| cd "$RUNNER_TEMP/consumer" | ||
| composer init --no-interaction --name=smoke/consumer | ||
| composer config repositories.lib path "$GITHUB_WORKSPACE" | ||
| composer require --no-interaction "ready2order/r2o-api-client-php:@dev" | ||
|
|
||
| - name: Smoke test | ||
| run: php .github/scripts/php74-smoke.php "$RUNNER_TEMP/consumer/vendor/autoload.php" | ||
|
|
||
| # The library allows Guzzle ^7.16 || ^8.3 but `checks` resolves the newest (8.x). | ||
| # Pin the oldest supported 7.x and re-run the unit tests against it. | ||
| guzzle7: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 10 | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: shivammathur/setup-php@v2 | ||
| with: | ||
| php-version: '8.3' | ||
| extensions: curl, json, mbstring | ||
| coverage: none | ||
|
|
||
| - run: composer install --no-interaction --prefer-dist | ||
|
|
||
| - run: composer require --no-interaction --with-all-dependencies "guzzlehttp/guzzle:7.16.0" | ||
|
|
||
| - name: Unit tests (Guzzle 7) | ||
| run: composer test | ||
|
|
||
| # Hits the real API with a test-account token; creates and deletes data. | ||
| # Runs only after the static checks pass, so a commit that fails lint never | ||
| # touches the real account. Skipped for fork PRs (no secrets). The concurrency | ||
| # group makes runs queue instead of overlapping on the same account; GitHub | ||
| # keeps only one pending run per group, so a newer queued run replaces an | ||
| # older pending one. | ||
| live-api: | ||
| needs: checks | ||
| timeout-minutes: 10 | ||
| if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository | ||
| runs-on: ubuntu-latest | ||
| concurrency: | ||
| group: live-api | ||
| cancel-in-progress: false | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: shivammathur/setup-php@v2 | ||
| with: | ||
| php-version: '8.3' | ||
| extensions: curl, json, mbstring | ||
| coverage: none | ||
|
|
||
| - run: composer install --no-interaction --prefer-dist | ||
|
|
||
| # --fail-on-skipped: an unset secret/variable must fail the job, not pass it with every test skipped. | ||
| - name: Live API tests | ||
| run: composer test:api -- --fail-on-skipped | ||
| env: | ||
| R2O_API_TOKEN: ${{ secrets.R2O_API_TOKEN }} | ||
| R2O_API_ENDPOINT: ${{ vars.R2O_API_ENDPOINT }} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |
| .env | ||
| /vendor | ||
| composer.lock | ||
| .php_cs.cache | ||
| .php-cs-fixer.cache | ||
| .phpunit.result.cache | ||
| .claude | ||
| CLAUDE.md | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| parameters: | ||
| level: 5 | ||
| paths: | ||
| - src | ||
| - tests | ||
| treatPhpDocTypesAsCertain: false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.