-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from odolbeau/first-test
tests(checkout-intent): Create first functional test
- Loading branch information
Showing
7 changed files
with
156 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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,53 @@ | ||
on: [pull_request] | ||
name: PHPUnit | ||
|
||
jobs: | ||
tests: | ||
name: Tests | ||
runs-on: Ubuntu-20.04 | ||
|
||
strategy: | ||
matrix: | ||
include: | ||
# Lowest deps (PHP 8.1 & sf 6.4) | ||
- php: 8.1 | ||
symfony-require: 6.4.* | ||
composer-flags: '--prefer-stable --prefer-lowest' | ||
# Normal deps with different php versions | ||
- php: 8.2 | ||
symfony-require: 7.0.* | ||
composer-flags: '--prefer-stable' | ||
- php: 8.3 | ||
symfony-require: 7.0.* | ||
composer-flags: '--prefer-stable' | ||
# Development release | ||
- php: nightly | ||
symfony-require: 7.1.*@dev | ||
stability: dev | ||
can-fail: true | ||
fail-fast: false | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
coverage: none | ||
|
||
- name: Configure Composer minimum stability | ||
if: matrix.stability | ||
run: composer config minimum-stability ${{ matrix.stability }} | ||
|
||
- name: Install dependencies | ||
env: | ||
SYMFONY_REQUIRE: ${{ matrix.symfony-require }} | ||
run: composer update ${{ matrix.composer-flags }} --no-interaction --no-progress --optimize-autoloader | ||
|
||
- name: Run PHPUnit | ||
env: | ||
HELLOASSO_CLIENT_ID: ${{ secrets.TESTS_HELLOASSO_ID }} | ||
HELLOASSO_CLIENT_SECRET: ${{ secrets.TESTS_HELLOASSO_SECRET }} | ||
run: vendor/bin/phpunit |
This file contains 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 |
---|---|---|
|
@@ -5,3 +5,4 @@ composer.lock | |
|
||
/tools/*/composer.lock | ||
/tools/*/vendor | ||
/.phpunit.cache |
This file contains 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 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 |
---|---|---|
|
@@ -5,3 +5,4 @@ parameters: | |
level: 5 | ||
paths: | ||
- src | ||
- tests |
This file contains 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,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" | ||
bootstrap="vendor/autoload.php" | ||
cacheDirectory=".phpunit.cache" | ||
executionOrder="depends,defects" | ||
beStrictAboutOutputDuringTests="true" | ||
failOnRisky="true" | ||
failOnWarning="true"> | ||
<testsuites> | ||
<testsuite name="default"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<source restrictDeprecations="true" restrictNotices="true" restrictWarnings="true"> | ||
<include> | ||
<directory>src</directory> | ||
</include> | ||
</source> | ||
</phpunit> |
This file contains 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,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Helloasso\Tests\Functional\Service; | ||
|
||
use Helloasso\Models\Carts\CheckoutPayer; | ||
use Helloasso\Models\Carts\InitCheckoutBody; | ||
use Helloasso\Models\Carts\InitCheckoutResponse; | ||
use Helloasso\Service\CheckoutIntentService; | ||
|
||
final class CheckoutIntentServiceTest extends ServiceTestCase | ||
{ | ||
public function testCreate(): void | ||
{ | ||
$service = $this->createService(CheckoutIntentService::class); | ||
|
||
$payer = new CheckoutPayer(); | ||
$payer | ||
->setFirstName('Greta') | ||
->setLastName('Thunberg') | ||
->setDateOfBirth(new \DateTimeImmutable('-20 years')) | ||
; | ||
|
||
$body = new InitCheckoutBody(); | ||
$body | ||
->setItemName('Awesome product') | ||
->setInitialAmount(4200) | ||
->setTotalAmount(4200) | ||
->setBackUrl('https://my-app.fr/back_url') | ||
->setReturnUrl('https://my-app.fr/return_url') | ||
->setErrorUrl('https://my-app.fr/error_url') | ||
->setPayer($payer) | ||
; | ||
|
||
$response = $service->create($body); | ||
|
||
$this->assertInstanceOf(InitCheckoutResponse::class, $response); | ||
} | ||
} |
This file contains 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,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Helloasso\Tests\Functional\Service; | ||
|
||
use Helloasso\Service\ApiRequest; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
abstract class ServiceTestCase extends TestCase | ||
{ | ||
/** | ||
* @template T of ApiRequest | ||
* | ||
* @param class-string<T> $className | ||
* | ||
* @return T | ||
*/ | ||
protected function createService(string $className): ApiRequest | ||
{ | ||
$clientId = getenv('HELLOASSO_CLIENT_ID'); | ||
$clientSecret = getenv('HELLOASSO_CLIENT_SECRET'); | ||
$organisationSlug = getenv('HELLOASSO_ORGANISATION') ? getenv('HELLOASSO_ORGANISATION_SLUG') : 'helloasso-php-sdk'; | ||
|
||
if (false === $clientId || false === $clientSecret) { | ||
throw new \RuntimeException('Some mandatory environment variables ("HELLOASSO_CLIENT_ID", "HELLOASSO_CLIENT_SECRET") have not been set. Please consider creating an account on https://www.helloasso-sandbox.com/ and run tests using HELLOASSO_CLIENT_ID=[YourClientId] HELLOASSO_CLIENT_SECRET=[YourClientSecret] HELLOASSO_ORGANISATION_SLUG=[YourOrganisation] vendor/bin/phpunit'); | ||
} | ||
|
||
return new $className($clientId, $clientSecret, $organisationSlug, true); | ||
} | ||
} |