Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 157 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
name: E2E

on:
push:
branches:
- '*'
tags:
- '*'
paths-ignore:
- '**/*.md'
pull_request:
paths-ignore:
- '**/*.md'

jobs:
e2e:
name: Playwright E2E Tests
runs-on: ubuntu-latest

services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: eccube_db
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=3
mailhog:
image: mailhog/mailhog
ports:
- 1025:1025
- 8025:8025

steps:
- name: Checkout plugin repository
uses: actions/checkout@v6
with:
path: plugin

- name: Checkout EC-CUBE
uses: actions/checkout@v6
with:
repository: EC-CUBE/ec-cube
ref: '4.3'
path: eccube

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
extensions: mbstring, intl, pdo_mysql, curl, zip, opcache
coverage: none

- name: Install EC-CUBE dependencies
working-directory: eccube
run: composer install --no-progress --prefer-dist --optimize-autoloader --no-interaction

- name: Install plugin
run: |
mkdir -p eccube/app/Plugin/StockAlertMail
find plugin -mindepth 1 -maxdepth 1 ! -name '.github' ! -name '.git' -exec cp -r {} eccube/app/Plugin/StockAlertMail/ \;
- name: Setup EC-CUBE
working-directory: eccube
env:
APP_ENV: 'dev'
APP_DEBUG: '1'
DATABASE_URL: 'mysql://root:root@127.0.0.1:3306/eccube_db'
DATABASE_SERVER_VERSION: '8.0'
DATABASE_CHARSET: 'utf8mb4'
MAILER_DSN: 'smtp://127.0.0.1:1025'
ECCUBE_AUTH_MAGIC: 'e2etestmagic'
run: |
cat > .env.local << 'ENVEOF'
APP_ENV=dev
APP_DEBUG=1
DATABASE_URL=mysql://root:root@127.0.0.1:3306/eccube_db
DATABASE_SERVER_VERSION=8.0
DATABASE_CHARSET=utf8mb4
MAILER_DSN=smtp://127.0.0.1:1025
ECCUBE_AUTH_MAGIC=e2etestmagic
ENVEOF
php bin/console doctrine:database:create --if-not-exists
php bin/console doctrine:schema:create
php bin/console eccube:fixtures:load
php bin/console eccube:plugin:install --code=StockAlertMail
php bin/console eccube:plugin:enable --code=StockAlertMail
php bin/console eccube:plugin:schema-update StockAlertMail
php bin/console cache:warmup
- name: Install Symfony CLI
run: |
curl -1sLf 'https://dl.cloudsmith.io/public/symfony/stable/setup.deb.sh' | sudo -E bash
sudo apt install symfony-cli
- name: Start Symfony server
working-directory: eccube
env:
APP_ENV: 'dev'
APP_DEBUG: '1'
DATABASE_URL: 'mysql://root:root@127.0.0.1:3306/eccube_db'
DATABASE_SERVER_VERSION: '8.0'
DATABASE_CHARSET: 'utf8mb4'
MAILER_DSN: 'smtp://127.0.0.1:1025'
ECCUBE_AUTH_MAGIC: 'e2etestmagic'
run: |
symfony serve -d --port=8000 --no-tls
sleep 3
curl -sf http://127.0.0.1:8000/admin/login > /dev/null
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Install Playwright
working-directory: eccube/app/Plugin/StockAlertMail/e2e
run: |
npm ci
npx playwright install --with-deps chromium
- name: Run Playwright tests
working-directory: eccube/app/Plugin/StockAlertMail/e2e
env:
ECCUBE_URL: 'http://127.0.0.1:8000'
ECCUBE_ROOT: ${{ github.workspace }}/eccube
MAILHOG_API: 'http://localhost:8025/api'
APP_ENV: 'dev'
DATABASE_URL: 'mysql://root:root@127.0.0.1:3306/eccube_db'
DATABASE_SERVER_VERSION: '8.0'
DATABASE_CHARSET: 'utf8mb4'
MAILER_DSN: 'smtp://127.0.0.1:1025'
run: npx playwright test

- name: Upload Playwright report
if: always()
uses: actions/upload-artifact@v6
with:
name: playwright-report
path: eccube/app/Plugin/StockAlertMail/e2e/playwright-report/
retention-days: 7
if-no-files-found: ignore

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v6
with:
name: playwright-test-results
path: eccube/app/Plugin/StockAlertMail/e2e/test-results/
retention-days: 7
if-no-files-found: ignore
59 changes: 59 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Lint

on:
push:
branches:
- '*'
tags:
- '*'
paths-ignore:
- '**/*.md'
pull_request:
paths-ignore:
- '**/*.md'

jobs:
lint:
name: PHP-CS-Fixer & PHPStan
runs-on: ubuntu-latest

steps:
- name: Checkout plugin repository
uses: actions/checkout@v6
with:
path: plugin

- name: Checkout EC-CUBE
uses: actions/checkout@v6
with:
repository: EC-CUBE/ec-cube
ref: '4.3'
path: eccube

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
extensions: mbstring, intl, pdo_mysql, pdo_pgsql, curl, zip, opcache
coverage: none

- name: Install EC-CUBE dependencies
working-directory: eccube
run: composer install --no-progress --prefer-dist --optimize-autoloader --no-interaction

- name: Install plugin
run: |
mkdir -p eccube/app/Plugin/StockAlertMail
find plugin -mindepth 1 -maxdepth 1 ! -name '.github' ! -name '.git' -exec cp -r {} eccube/app/Plugin/StockAlertMail/ \;
- name: Clear cache
working-directory: eccube
run: php bin/console cache:clear --env=dev --no-warmup

- name: PHP-CS-Fixer (dry-run)
working-directory: eccube
run: vendor/bin/php-cs-fixer fix app/Plugin/StockAlertMail/ --dry-run --diff --no-interaction

- name: PHPStan
working-directory: eccube
run: vendor/bin/phpstan analyse app/Plugin/StockAlertMail/ --level=1 --no-progress
64 changes: 9 additions & 55 deletions .github/workflows/ci.yml → .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,68 +1,22 @@
name: CI
name: PHPUnit

on:
push:
branches:
- '*'
tags:
- '*'
paths:
- '**'
- '!*.md'
paths-ignore:
- '**/*.md'
- 'e2e/**'
pull_request:
paths:
- '**'
- '!*.md'
paths-ignore:
- '**/*.md'
- 'e2e/**'

jobs:
lint:
name: PHP-CS-Fixer & PHPStan
runs-on: ubuntu-latest

steps:
- name: Checkout plugin repository
uses: actions/checkout@v6
with:
path: plugin

- name: Checkout EC-CUBE
uses: actions/checkout@v6
with:
repository: EC-CUBE/ec-cube
ref: '4.3'
path: eccube

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
extensions: mbstring, intl, pdo_mysql, pdo_pgsql, curl, zip, opcache
coverage: none

- name: Install EC-CUBE dependencies
working-directory: eccube
run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader --no-interaction

- name: Install plugin
run: |
mkdir -p eccube/app/Plugin/StockAlertMail
find plugin -mindepth 1 -maxdepth 1 ! -name '.github' ! -name '.git' -exec cp -r {} eccube/app/Plugin/StockAlertMail/ \;
- name: Clear cache
working-directory: eccube
run: php bin/console cache:clear --env=dev --no-warmup

- name: PHP-CS-Fixer (dry-run)
working-directory: eccube
run: vendor/bin/php-cs-fixer fix app/Plugin/StockAlertMail/ --dry-run --diff --no-interaction

- name: PHPStan
working-directory: eccube
run: vendor/bin/phpstan analyse app/Plugin/StockAlertMail/ --level=1 --no-progress

test:
name: PHPUnit Tests (EC-CUBE ${{ matrix.ec-cube-version }}, PHP ${{ matrix.php-version }}, ${{ matrix.database }})
needs: lint
name: EC-CUBE ${{ matrix.ec-cube-version }} / PHP ${{ matrix.php-version }} / ${{ matrix.database }}
runs-on: ubuntu-latest

strategy:
Expand Down Expand Up @@ -132,7 +86,7 @@ jobs:
- name: Install EC-CUBE dependencies
working-directory: eccube
run: |
composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader --no-interaction
composer install --no-progress --prefer-dist --optimize-autoloader --no-interaction
- name: Install plugin
run: |
Expand Down
12 changes: 12 additions & 0 deletions Service/StockAlertMailBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public function createDummyItems(): array
// ダミー商品A(規格なし)
$productA = new Product();
$productA->setName($this->translator->trans('stock_alert_mail.test.dummy_product_a'));
$this->setEntityId($productA, 1);

$pcA = new ProductClass();
$pcA->setProduct($productA);
Expand All @@ -118,6 +119,7 @@ public function createDummyItems(): array
// ダミー商品B(規格あり)
$productB = new Product();
$productB->setName($this->translator->trans('stock_alert_mail.test.dummy_product_b'));
$this->setEntityId($productB, 2);

$cc1 = new ClassCategory();
$cc1->setName($this->translator->trans('stock_alert_mail.test.dummy_class1'));
Expand All @@ -133,6 +135,16 @@ public function createDummyItems(): array
return [$pcA, $pcB];
}

/**
* エンティティに仮IDを設定する(テスト用ダミーデータ向け)
*/
private function setEntityId(object $entity, int $id): void
{
$ref = new \ReflectionProperty($entity, 'id');
$ref->setAccessible(true);
$ref->setValue($entity, $id);
}

private function findMailTemplate(): ?MailTemplate
{
return $this->mailTemplateRepository->findOneBy([
Expand Down
4 changes: 4 additions & 0 deletions e2e/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
auth.json
test-results/
playwright-report/
28 changes: 28 additions & 0 deletions e2e/helpers/command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { execSync } from 'child_process';
import path from 'path';

const ECCUBE_ROOT = process.env.ECCUBE_ROOT
|| path.resolve(__dirname, '../../../../../..');

/** EC-CUBE の bin/console コマンドを実行する */
export function execConsole(command: string): string {
return execSync(`php bin/console ${command}`, {
cwd: ECCUBE_ROOT,
encoding: 'utf-8',
timeout: 30_000,
env: { ...process.env },
}).trim();
}

/** 在庫アラートコマンドを実行する */
export function execStockAlert(): { exitCode: number; output: string } {
try {
const output = execConsole('eccube:plugin:stock-alert-mail');
return { exitCode: 0, output };
} catch (e: any) {
return {
exitCode: e.status ?? 1,
output: e.stdout?.toString() ?? e.message,
};
}
}
Loading
Loading