Skip to content

Commit 890b671

Browse files
committed
fix: исправление ошибок E2E тестов и Scheduler
- Исправлен bootstrap-e2e.php для работы с WP_CORE_DIR в CI - Обновлена версия WordPress с 6.6 на 6.7 в CI и документации - Добавлена защита от несуществующих Job классов в Scheduler::job() - Удалена зависимость от ReflectionClass в getHook() методе - Удалена локальная Docker инфраструктура E2E тестов
1 parent 01f0084 commit 890b671

5 files changed

Lines changed: 32 additions & 19 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ jobs:
5353
fail-fast: false
5454
matrix:
5555
php-version: [ "8.3" ]
56-
wordpress-version: [ "latest", "6.6" ]
56+
wordpress-version: [ "latest", "6.7" ]
5757
include:
5858
- wordpress-version: latest
5959
wp-version-string: "latest"
60-
- wordpress-version: "6.6"
61-
wp-version-string: "6.6"
60+
- wordpress-version: "6.7"
61+
wp-version-string: "6.7"
6262

6363
services:
6464
mysql:

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,8 @@ composer test:unit
406406

407407
Интеграционные тесты с реальным WordPress запускаются автоматически в CI:
408408

409-
- ✅ WordPress latest + PHP 8.3
410-
- ✅ WordPress 6.6 + PHP 8.3
409+
- ✅ WordPress latest (6.7+) + PHP 8.3
410+
- ✅ WordPress 6.7 + PHP 8.3
411411

412412
E2E тесты выполняются при каждом push в `main`/`develop` ветки и в pull requests.
413413

src/Scheduler.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ public function __construct()
3535
*/
3636
public function job(string $jobClass): ScheduledJob
3737
{
38+
// Проверка существования класса
39+
if (! class_exists($jobClass)) {
40+
// Логируем ошибку и возвращаем пустой ScheduledJob
41+
if (function_exists('error_log')) {
42+
error_log("WP Queue: Job class '{$jobClass}' does not exist");
43+
}
44+
45+
return new ScheduledJob($jobClass, $this);
46+
}
47+
3848
$scheduled = new ScheduledJob($jobClass, $this);
3949
$this->jobs[$jobClass] = $scheduled;
4050

@@ -155,9 +165,10 @@ protected function unschedule(string $hook): void
155165
*/
156166
protected function getHook(string $jobClass): string
157167
{
158-
$name = (new ReflectionClass($jobClass))->getShortName();
168+
// Извлекаем короткое имя класса без ReflectionClass
169+
$name = substr(strrchr($jobClass, '\\') ?: $jobClass, 1) ?: $jobClass;
159170

160-
return 'wp_queue_'.strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $name));
171+
return 'wp_queue_' . strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $name));
161172
}
162173

163174
/**

tests/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ composer test:unit
146146

147147
E2E тесты запускаются автоматически в GitHub Actions:
148148

149-
- WordPress latest + PHP 8.3
150-
- WordPress 6.6 + PHP 8.3
149+
- WordPress latest (6.7+) + PHP 8.3
150+
- WordPress 6.7 + PHP 8.3
151151

152152
Конфигурация в `.github/workflows/ci.yml`.
153153

tests/bootstrap-e2e.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,31 @@
66
* Bootstrap для E2E тестов с реальным WordPress окружением.
77
*/
88

9-
// Путь к корню WordPress
10-
$wp_root = dirname(__DIR__, 4);
9+
// Путь к корню WordPress (из переменной окружения или относительный)
10+
$wp_root = getenv('WP_CORE_DIR') ?: dirname(__DIR__, 4);
1111

1212
// Проверка наличия WordPress
13-
if (! file_exists($wp_root.'/wp-load.php')) {
14-
echo "WordPress не найден в: {$wp_root}\n";
13+
if (! file_exists($wp_root . '/wp-load.php')) {
14+
echo " INFO WordPress не найден в: {$wp_root}\n";
15+
echo " HINT Установите переменную WP_CORE_DIR или запустите тесты в CI\n";
1516
exit(1);
1617
}
1718

1819
// Загрузка WordPress
19-
require_once $wp_root.'/wp-load.php';
20+
require_once $wp_root . '/wp-load.php';
2021

21-
// Загрузка WordPress тестовой библиотеки
22-
if (file_exists($wp_root.'/wp-content/plugins/wp-queue/vendor/yoast/phpunit-polyfills/phpunitpolyfills-autoload.php')) {
23-
require_once $wp_root.'/wp-content/plugins/wp-queue/vendor/yoast/phpunit-polyfills/phpunitpolyfills-autoload.php';
22+
// Загрузка WordPress тестовой библиотеки (ищем в vendor плагина)
23+
$polyfills_path = dirname(__DIR__) . '/vendor/yoast/phpunit-polyfills/phpunitpolyfills-autoload.php';
24+
if (file_exists($polyfills_path)) {
25+
require_once $polyfills_path;
2426
}
2527

2628
// Загрузка плагина
27-
require_once dirname(__DIR__).'/wp-queue.php';
29+
require_once dirname(__DIR__) . '/wp-queue.php';
2830

2931
// Активация плагина
3032
if (! function_exists('activate_plugin')) {
31-
require_once $wp_root.'/wp-admin/includes/plugin.php';
33+
require_once $wp_root . '/wp-admin/includes/plugin.php';
3234
}
3335

3436
// Инициализация плагина

0 commit comments

Comments
 (0)