-
Notifications
You must be signed in to change notification settings - Fork 0
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 #1 from kurozumi/add-test
テスト追加
- Loading branch information
Showing
11 changed files
with
279 additions
and
4 deletions.
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,46 @@ | ||
name: PHPStan | ||
on: [workflow_dispatch, pull_request] | ||
|
||
env: | ||
PLUGIN_CODE: StripeWebhook | ||
PLUGIN_PACKAGE_NAME: 'ec-cube/stripewebhook' | ||
|
||
jobs: | ||
phpstan: | ||
name: PHPStan | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
eccube-versions: ['4.3'] | ||
php-versions: [ '8.2' ] | ||
database: [ 'mysql' ] | ||
include: | ||
- database: mysql | ||
database_url: mysql://root:[email protected]:3306/eccube_db | ||
database_server_version: 5.7 | ||
database_charset: utf8mb4 | ||
services: | ||
mysql: | ||
image: mysql:5.7 | ||
env: | ||
MYSQL_ROOT_PASSWORD: password | ||
ports: | ||
- 3306:3306 | ||
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.event.pull_request.head.sha }} | ||
|
||
- uses: kurozumi/[email protected] | ||
with: | ||
plugin-code: ${{ env.PLUGIN_CODE }} | ||
plugin-package-name: ${{ env.PLUGIN_PACKAGE_NAME }} | ||
eccube-versions: ${{ matrix.eccube-versions }} | ||
php-versions: ${{ matrix.php-versions }} | ||
database-url: ${{ matrix.database_url }} | ||
database-server-version: ${{ matrix.database_server_version }} | ||
database-charset: ${{ matrix.database_charset }} |
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,71 @@ | ||
name: CI/CD for EC-CUBE4 Plugin | ||
on: [workflow_dispatch, pull_request] | ||
|
||
env: | ||
PLUGIN_CODE: StripeWebhook | ||
PLUGIN_PACKAGE_NAME: 'ec-cube/stripewebhook' | ||
|
||
jobs: | ||
phpunit: | ||
name: PHPUnit | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
eccube-versions: [ '4.3' ] | ||
php-versions: [ '8.2', '8.3' ] | ||
database: [ 'mysql', 'mysql8', 'pgsql' ] | ||
include: | ||
- database: mysql | ||
database_url: mysql://root:[email protected]:3306/eccube_db | ||
database_server_version: 5.7 | ||
database_charset: utf8mb4 | ||
- database: mysql8 | ||
database_url: mysql://root:[email protected]:3308/eccube_db | ||
database_server_version: 8 | ||
database_charset: utf8mb4 | ||
- database: pgsql | ||
database_url: postgres://postgres:[email protected]:5432/eccube_db | ||
database_server_version: 14 | ||
database_charset: utf8 | ||
|
||
services: | ||
mysql: | ||
image: mysql:5.7 | ||
env: | ||
MYSQL_ROOT_PASSWORD: password | ||
ports: | ||
- 3306:3306 | ||
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 | ||
mysql8: | ||
image: mysql:8 | ||
env: | ||
MYSQL_ROOT_PASSWORD: password | ||
ports: | ||
- 3308:3306 | ||
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 | ||
postgres: | ||
image: postgres:11 | ||
env: | ||
POSTGRES_USER: postgres | ||
POSTGRES_PASSWORD: password | ||
ports: | ||
- 5432:5432 | ||
# needed because the postgres container does not provide a healthcheck | ||
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.event.pull_request.head.sha }} | ||
|
||
- uses: kurozumi/eccube-plugin-test@main | ||
with: | ||
plugin-code: ${{ env.PLUGIN_CODE }} | ||
plugin-package-name: ${{ env.PLUGIN_PACKAGE_NAME }} | ||
eccube-versions: ${{ matrix.eccube-versions }} | ||
php-versions: ${{ matrix.php-versions }} | ||
database-url: ${{ matrix.database_url }} | ||
database-server-version: ${{ matrix.database_server_version }} | ||
database-charset: ${{ matrix.database_charset }} |
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
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,9 @@ | ||
{ | ||
"id": "event_id", | ||
"data": { | ||
"object": { | ||
"object": "test" | ||
} | ||
}, | ||
"type": "event_name" | ||
} |
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,19 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Stripe Webhook | ||
* | ||
* Copyright(c) Akira Kurozumi All Rights Reserved. | ||
* | ||
* https://a-zumi.net | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
return new Plugin\StripeWebhook\RemoteEvent\Event\StripeEvent( | ||
name: 'event_name', | ||
id: 'event_id', | ||
payload: ['object' => 'test'], | ||
resource: new Stripe\StripeObject() | ||
); |
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,61 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of Stripe Webhook | ||
* | ||
* Copyright(c) Akira Kurozumi All Rights Reserved. | ||
* | ||
* https://a-zumi.net | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Plugin\StripeWebhook\Tests\Webhook; | ||
|
||
use Plugin\StripeWebhook\Webhook\StripeRequestParser; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\RemoteEvent\RemoteEvent; | ||
use Symfony\Component\Webhook\Client\RequestParserInterface; | ||
use Symfony\Component\Webhook\Test\AbstractRequestParserTestCase; | ||
|
||
class StripeRequestParserTest extends AbstractRequestParserTestCase | ||
{ | ||
/** | ||
* @dataProvider getPayloads | ||
*/ | ||
public function testParse(string $payload, RemoteEvent $expected) | ||
{ | ||
$request = $this->createRequest($payload); | ||
$parser = $this->createRequestParser(); | ||
$wh = $parser->parse($request, $this->getSecret()); | ||
|
||
self::assertEquals($expected->getName(), $wh->getName()); | ||
self::assertEquals($expected->getId(), $wh->getId()); | ||
self::assertEquals($expected->getPayload(), $wh->getPayload()); | ||
} | ||
|
||
protected function createRequestParser(): RequestParserInterface | ||
{ | ||
return new StripeRequestParser(); | ||
} | ||
|
||
protected function getSecret(): string | ||
{ | ||
return 'STRIPE_SIGNING_SECRET'; | ||
} | ||
|
||
protected function createRequest(string $payload): Request | ||
{ | ||
$timestamp = time(); | ||
$signedPayload = "{$timestamp}.{$payload}"; | ||
$expectedSignature = \hash_hmac('sha256', $signedPayload, $this->getSecret()); | ||
|
||
return Request::create('/', 'POST', [], [], [], [ | ||
'Content-Type' => 'application/json', | ||
'HTTP_STRIPE_SIGNATURE' => "t={$timestamp},v1={$expectedSignature},v0=signature", | ||
], $payload); | ||
} | ||
} |
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 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Stripe Webhook | ||
* | ||
* Copyright(c) Akira Kurozumi All Rights Reserved. | ||
* | ||
* https://a-zumi.net | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
$loader = require __DIR__.'/../../../../vendor/autoload.php'; | ||
|
||
$envFile = __DIR__.'/../../../../.env'; | ||
if (file_exists($envFile)) { | ||
(new Symfony\Component\Dotenv\Dotenv()) | ||
->usePutenv() | ||
->bootEnv($envFile); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
parameters: | ||
level: 1 |
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,45 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.5/phpunit.xsd" | ||
backupGlobals="false" | ||
colors="true" | ||
bootstrap="Tests/bootstrap.php" | ||
> | ||
<php> | ||
<ini name="error_reporting" value="-1" /> | ||
<env name="KERNEL_CLASS" value="Eccube\Kernel" /> | ||
<env name="APP_ENV" value="test" /> | ||
<env name="APP_DEBUG" value="0" /> | ||
<env name="SHELL_VERBOSITY" value="-1" /> | ||
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak" /> | ||
<env name="SYMFONY_PHPUNIT_VERSION" value="9.5" /> | ||
<!-- define your env variables for the test env here --> | ||
</php> | ||
|
||
<!-- テストの場所 --> | ||
<testsuites> | ||
<testsuite name="Plugin Test Suite"> | ||
<directory>./Tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<!-- 出力するログファイル | ||
<logging> | ||
<log type="coverage-clover" target="./reports/coverage.clover"/> | ||
</logging> | ||
--> | ||
|
||
<!-- カバーレージのターゲット --> | ||
<filter> | ||
<whitelist processUncoveredFilesFromWhitelist="true"> | ||
<directory suffix=".php">./</directory> | ||
<exclude> | ||
<directory suffix=".php">./Tests</directory> | ||
<directory suffix=".php">./Resource</directory> | ||
<file>./PluginManager.php</file> | ||
</exclude> | ||
</whitelist> | ||
</filter> | ||
|
||
<listeners> |