Итак, я пытаюсь создать несколько модульных тестов в WordPress, и я установил PHPUnit 6.5.5 (пробовал разные версии вплоть до 7. *, последняя из которых поддерживается WP).
Сгенерированный phpunit. * Файл 1032 * .dist выглядит следующим образом:
<?xml version="1.0"?>
<phpunit
bootstrap="tests/bootstrap.php"
backupGlobals="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
>
<testsuites>
<testsuite name="default">
<directory prefix="test-" suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
Папка test является папкой по умолчанию с bootstrap. php и test-sample. php file:
tests
-- bootstrap.php
-- test-sample.php
Однако, когда я нахожусь в каталоге моего плагина и запускаю phpunit
, я получаю Никаких тестов не выполнено .
Когда я добавляю файл теста под каталогом как:
<file>tests/test-sample.php</file>
и затем запустите phpunit
, я вижу, что тест запущен.
Разве он не должен автоматически определять каталог и файлы в комплекте тестов без необходимости записи каждого файла теста один за другим в XML?
РЕДАКТИРОВАТЬ: phpunit -v
выход:
$ phpunit -v
Installing...
Running as single site... To run multisite, use -c tests/phpunit/multisite.xml
Not running ajax tests. To execute these, use --group ajax.
Not running ms-files tests. To execute these, use --group ms-files.
Not running external-http tests. To execute these, use --group external-http.
PHPUnit 6.5.5 by Sebastian Bergmann and contributors.
Runtime: PHP 7.3.14-1+ubuntu18.04.1+deb.sury.org+1
Configuration: /vagrant/Plugins/Framework/phpunit.xml.dist
Time: 1 second, Memory: 26.00MB
РЕДАКТИРОВАТЬ 2: bootstrap. php содержимое файла:
<?php
/**
* PHPUnit bootstrap file
*/
$_tests_dir = getenv( 'WP_TESTS_DIR' );
if ( ! $_tests_dir ) {
$_tests_dir = rtrim( sys_get_temp_dir(), '/\\' ) . '/wordpress-tests-lib';
}
if ( ! file_exists( $_tests_dir . '/includes/functions.php' ) ) {
echo "Could not find $_tests_dir/includes/functions.php, have you run bin/install-wp-tests.sh ?" . PHP_EOL; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
exit( 1 );
}
// Give access to tests_add_filter() function.
require_once $_tests_dir . '/includes/functions.php';
/**
* Manually load the plugin being tested.
*/
function _manually_load_plugin() {
require realpath(dirname(__FILE__) . '/../..') . '/myplugin/myplugin.php';
}
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
// Start up the WP testing environment.
require $_tests_dir . '/includes/bootstrap.php';