frozzare / wp-test-suite
轻松运行WordPress测试
v1.1.1
2017-02-24 12:29 UTC
Requires
- php: ^5.6 || ^7.0
- phpunit/phpunit: ~5.0
README
您不需要为每个插件添加bootstrap.php
,只需安装此包并指向bootstrap.php
即可。对于小型插件,这应该足够。如果您需要更高级的功能,这个包可能不适合您的项目。
安装
composer require frozzare/wp-test-suite
示例
示例.travis.yml
language: php php: - 5.4 - 5.5 - 5.6 env: - WP_VERSION=latest WP_MULTISITE=0 install: - travis_retry composer install --no-interaction --prefer-source before_script: - bash vendor/frozzare/wp-test-suite/bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 $WP_VERSION script: vendor/bin/phpunit
示例phpunit.xml.dist
<phpunit bootstrap="vendor/frozzare/wp-test-suite/bootstrap.php" backupGlobals="false" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" > <php> <const name="WTS_PLUGIN_FILE_NAME" value="simple-gtm.php" /> </php> <testsuites> <testsuite name="Simple GTM Test Suite"> <directory suffix=".php">./tests/</directory> </testsuite> </testsuites> <logging> <log type="coverage-clover" target="./tmp/clover.xml" charset="UTF-8" /> </logging> </phpunit>
使用WordPress Test Suite与自己的tests/bootstrap.php
的示例
require __DIR__ . '/../vendor/autoload.php'; WP_Test_Suite::load_plugins( [ __DIR__ . '/../simple-gtm.php' ] ); WP_Test_Suite::run();
文档
没有bootstrap.php
install-wp-tests.sh
此包包含install-wp-tests.sh
,路径为
vendor/frozzare/wp-test-suite/bin/install-wp-tests.sh
WTS_PLUGIN_FILE_NAME
使用此常量,您无需创建自己的bootstrap.php
。只需在您的phpunit.xml.dist
中包含WTS_PLUGIN_FILE_NAME
常量,并指定应加载的插件文件名。
带有bootstrap.php
WP_Test_Suite::load_plugins
要加载的插件路径数组或插件路径字符串。
WP_Test_Suite::load_files
要加载的文件路径数组或文件路径字符串。
WP_Test_Suite::set_test_root
设置新的测试根路径。它将尝试从以下位置自动加载:
WP_DEVELOP_DIR/tests/phpunit
/tmp/wordpress-develop/tests/phpunit
/tmp/wordpress-tests-lib
/srv/www/wordpress-develop/tests/phpunit
/srv/www/wordpress-develop/public_html/tests/phpunit
许可证
MIT © Fredrik Forsmo