Skip to content
Open
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
20 changes: 17 additions & 3 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,22 @@ Closes #(номер issue)

Опишите тесты, которые вы провели для проверки изменений.

Локальный CI-гейт (без MODX/MySQL), тот же набор что в `.github/workflows/ci.yml`:

```bash
cd core/components/minishop3
composer install
composer ci:php

cd ../../../vueManager
npm ci
npm run lint:ci
```

PHPStan в этот гейт не входит (отдельный follow-up).

- [ ] Ручное тестирование
- [ ] Автоматические тесты (PHPStan, ESLint)
- [ ] Автоматические тесты (`composer ci:php`, `npm run lint:ci` / GitHub Actions CI)
- [ ] Тестирование на разных версиях PHP/MODX

**Конфигурация тестирования:**
Expand All @@ -40,8 +54,8 @@ Closes #(номер issue)
- [ ] Добавлены/обновлены комментарии в сложных местах
- [ ] Изменения не ломают существующую функциональность
- [ ] Лексиконы добавлены на **двух языках** (ru/en)
- [ ] PHPStan проходит без новых ошибок
- [ ] ESLint проходит без ошибок (для JS/Vue изменений)
- [ ] PHPStan проходит без новых ошибок (локально; в CI пока нет)
- [ ] ESLint проходит без ошибок (`npm run lint:ci` для Vue)
- [ ] Обновлён CHANGELOG.md (для значимых изменений)

## Дополнительные заметки
Expand Down
65 changes: 65 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: CI

on:
pull_request:
push:
branches:
- beta
- master
- main

concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read

jobs:
php:
name: PHP lint + smoke
runs-on: ubuntu-latest
defaults:
run:
working-directory: core/components/minishop3

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
coverage: none
tools: composer:v2

- name: Install Composer dependencies
run: composer install --no-interaction --prefer-dist --no-progress

- name: PHP syntax check + smoke tests
run: composer ci:php

vue:
name: vueManager lint
runs-on: ubuntu-latest
defaults:
run:
working-directory: vueManager

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '20'
cache: npm
cache-dependency-path: vueManager/package-lock.json

- name: Install npm dependencies
run: npm ci

- name: ESLint
run: npm run lint:ci
4 changes: 4 additions & 0 deletions core/components/minishop3/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
"MiniShop3\\": "src/"
}
},
"scripts": {
"test:smoke": "php tests/run-smoke.php",
"ci:php": "bash scripts/ci-php.sh"
},
"minimum-stability": "stable",
"prefer-stable": true
}
14 changes: 14 additions & 0 deletions core/components/minishop3/scripts/ci-php.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
# PHP CI gate: syntax check + smoke tests (no MODX/MySQL).
set -euo pipefail

ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$ROOT"

count="$(find src migrations tests -type f -name '*.php' | wc -l | tr -d ' ')"
find src migrations tests -type f -name '*.php' -print0 \
| xargs -0 -n1 php -l >/dev/null
php -l phinx.php >/dev/null
echo "OK php -l (${count} under src/migrations/tests + phinx.php)"

composer test:smoke
13 changes: 3 additions & 10 deletions core/components/minishop3/tests/PhinxCharsetConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,15 @@

declare(strict_types=1);

require __DIR__ . '/support/modx_phinx_stub.php';

$fail = static function (string $message): never {
fwrite(STDERR, "FAIL: {$message}\n");
exit(1);
};

$buildConfig = static function (array $options): array {
$modx = new class ($options) {
public function __construct(private readonly array $options)
{
}

public function getOption(string $key, mixed $options = null, mixed $default = null): mixed
{
return $this->options[$key] ?? $default;
}
};
$modx = ms3_create_modx_phinx_stub($options);

return require __DIR__ . '/../phinx.php';
};
Expand Down
38 changes: 12 additions & 26 deletions core/components/minishop3/tests/PhinxMigrationTablePrefixTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

declare(strict_types=1);

require __DIR__ . '/support/modx_phinx_stub.php';

$fail = static function (string $message): never {
fwrite(STDERR, "FAIL: {$message}\n");
exit(1);
Expand Down Expand Up @@ -55,32 +57,16 @@ public function exec(string $sql): int
string $tablePrefix,
?object $pdo = null,
): array {
$modx = new class ($tablePrefix, $pdo) {
public function __construct(
private readonly string $tablePrefix,
public readonly ?object $pdo,
) {
}

public function getOption(string $key, mixed $options = null, mixed $default = null): mixed
{
return match ($key) {
'table_prefix' => $this->tablePrefix,
'host' => 'localhost',
'dbname' => 'modx',
'username' => 'user',
'password' => 'password',
'port' => '3306',
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
default => $default,
};
}

public function log(int $level, string $message): void
{
}
};
$modx = ms3_create_modx_phinx_stub([
'table_prefix' => $tablePrefix,
'host' => 'localhost',
'dbname' => 'modx',
'username' => 'user',
'password' => 'password',
'port' => '3306',
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
], $pdo);

return require __DIR__ . '/../phinx.php';
};
Expand Down
48 changes: 48 additions & 0 deletions core/components/minishop3/tests/run-smoke.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/**
* Runs standalone smoke tests under tests/*Test.php (no MODX/MySQL).
*
* Each *Test.php is a self-contained script that exits with a status code.
* This runner executes them in subprocesses; do not require() them here.
*
* Usage:
* php tests/run-smoke.php
* composer test:smoke
* composer ci:php
*/

declare(strict_types=1);

$testsDir = __DIR__;
$pattern = $testsDir . DIRECTORY_SEPARATOR . '*Test.php';
$files = glob($pattern) ?: [];
sort($files, SORT_STRING);

if ($files === []) {
fwrite(STDERR, "No smoke tests matched {$pattern}\n");
exit(1);
}

$failed = 0;

foreach ($files as $file) {
$relative = 'tests/' . basename($file);
fwrite(STDOUT, "→ {$relative}\n");

$command = escapeshellarg(PHP_BINARY) . ' ' . escapeshellarg($file);
passthru($command, $exitCode);

if ($exitCode !== 0) {
fwrite(STDERR, "FAIL {$relative} (exit {$exitCode})\n");
$failed++;
}
}

if ($failed > 0) {
fwrite(STDERR, "Smoke tests failed: {$failed}\n");
exit(1);
}

fwrite(STDOUT, 'OK smoke tests (' . count($files) . ")\n");
exit(0);
33 changes: 33 additions & 0 deletions core/components/minishop3/tests/support/modx_phinx_stub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/**
* Minimal modX-shaped stub for requiring phinx.php without a live MODX.
*/

declare(strict_types=1);

/**
* @param array<string, mixed> $options Values returned by getOption($key).
*/
function ms3_create_modx_phinx_stub(array $options, ?object $pdo = null): object
{
return new class ($options, $pdo) {
/**
* @param array<string, mixed> $options
*/
public function __construct(
private readonly array $options,
public readonly ?object $pdo,
) {
}

public function getOption(string $key, mixed $options = null, mixed $default = null): mixed
{
return $this->options[$key] ?? $default;
}

public function log(int $level, string $message): void
{
}
};
}
1 change: 1 addition & 0 deletions vueManager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"build": "vite build",
"preview": "vite preview",
"lint": "eslint . --fix",
"lint:ci": "eslint . --max-warnings 0",
"format": "prettier --write \"src/**/*.{js,vue,scss,css}\"",
"format:check": "prettier --check \"src/**/*.{js,vue,scss,css}\"",
"lint:all": "npm run lint && npm run format:check && npm run lint:scss",
Expand Down
Loading