Run WordPress/phpunit-test-runner on AMIMOTO as local
This is my note for trying to run https://github.com/WordPress/phpunit-test-runner on AMIMOTO as local Prepare […]
目次
This is my note for trying to run https://github.com/WordPress/phpunit-test-runner on AMIMOTO as local
Prepare
Launch AMIMOTO AMI at first.
Prepare source code
Download and prepare the phpunit-test-runner source codes.
$ git clone https://github.com/WordPress/phpunit-test-runner.git
$ cd phpunit-test-runner
You need to configure some environment variables.
There are many variable to run test in CI or reports the test result.
So, I wrote some variables just running for the test .
$ cp .env.default .env
$ vim .env
# Path to the directory where files can be prepared before being delivered to the environment.
export WPT_PREPARE_DIR=/tmp/wp-test-runner
# Path to the directory where the WordPress develop checkout can be placed and tests can be run.
# When running tests in the same environment, set WPT_TEST_DIR to WPT_PREPARE_DIR
export WPT_TEST_DIR=/tmp/wp-test-runner
# Credentials for a database that can be written to and reset.
# WARNING!!! This database will be destroyed between tests. Only use safe database credentials.
export WPT_DB_NAME={InstanceID}
export WPT_DB_USER=wp_b8cm5ffbihc92
export WPT_DB_PASSWORD='XXXXXXXXx'
export WPT_DB_HOST=localhost
The parameters like WPT_DB_***
can check by following commands.
$ sudo cat /opt/local/{InstanceID}.json | jq ".wordpress.db"
{
"db_name": "{InstanceID}",
"user_name": "wp_b8cm5ffbihc92",
"password": "XXXXXXXXx",
"host": "localhost"
}
And finally, load your variables into scope.
$ source .env
Setup
Download test WordPress and set up by php prepare.php
commands.
$ php prepare.php
...
cd '/tmp/wp-test-runner/tests/phpunit/data/plugins/'; unzip wordpress-importer.zip; rm wordpress-importer.zip
Archive: wordpress-importer.zip
creating: wordpress-importer/
creating: wordpress-importer/languages/
inflating: wordpress-importer/languages/wordpress-importer.pot
inflating: wordpress-importer/parsers.php
inflating: wordpress-importer/readme.txt
inflating: wordpress-importer/wordpress-importer.php
Replacing variables in wp-tests-config.php
Success: Prepared environment.
All source code will be deployed at WPT_PREPARE_DIR
.
If you have some trouble, you can retry after run rm -rf ${WPT_PREPARE_DIR}
Running unit test
After run php prepare.php
, you can run PHPUnit by php test.php
$ php test.php
Environment variables pass checks.
cd '/tmp/wp-test-runner'; php phpunit.phar
sh: gs: command not found
sh: convert: command not found
sh: gs: command not found
sh: convert: command not found
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 5.7.21 by Sebastian Bergmann and contributors.
............................................................. 61 / 8046 ( 0%)
............................................................. 122 / 8046 ( 1%)
............................................................. 183 / 8046 ( 2%)
............................................................. 244 / 8046 ( 3%)
............................................................. 305 / 8046 ( 3%)
............................................................. 366 / 8046 ( 4%)
............................................................. 427 / 8046 ( 5%)
............................................................. 488 / 8046 ( 6%)
............................................................. 549 / 8046 ( 6%)
............................................................. 610 / 8046 ( 7%)
............................................................. 671 / 8046 ( 8%)
............................................................. 732 / 8046 ( 9%)
............................................................. 793 / 8046 ( 9%)
............................................................. 854 / 8046 ( 10%)
............................................................. 915 / 8046 ( 11%)
............................................................. 976 / 8046 ( 12%)
............................................................. 1037 / 8046 ( 12%)
.......
But unfortunately, the normal AMIMOTO has an error.
1) Tests_oEmbed_HTTP_Headers::test_rest_pre_serve_request_headers
PHPUnit_Framework_Exception: sh: gs: command not found
sh: convert: command not found
sh: gs: command not found
sh: convert: command not found
You should run sudo yum install ImageMagick -y
and retry to run php test.php
.
$ sudo yum install ImageMagick -y
$ php test.php
...
............................................................. 6893 / 8046 ( 85%)
............................................................. 6954 / 8046 ( 86%)
............................................................. 7015 / 8046 ( 87%)
............................................................. 7076 / 8046 ( 87%)
............................................................. 7137 / 8046 ( 88%)
............................................................. 7198 / 8046 ( 89%)
............................................................. 7259 / 8046 ( 90%)
............................................................. 7320 / 8046 ( 90%)
............................................................. 7381 / 8046 ( 91%)
............................................................. 7442 / 8046 ( 92%)
............................................................. 7503 / 8046 ( 93%)
............................................................. 7564 / 8046 ( 94%)
............................................................. 7625 / 8046 ( 94%)
............................................................. 7686 / 8046 ( 95%)
............................................................. 7747 / 8046 ( 96%)
............................................................. 7808 / 8046 ( 97%)
............................................................. 7869 / 8046 ( 97%)
............................................................. 7930 / 8046 ( 98%)
............................................................. 7991 / 8046 ( 99%)
........................................SSSSSSSSSSSSSSS 8046 / 8046 (100%)
You should really fix these slow tests (>150ms)...
1. 673ms to run Tests_WP_Site_Icon:test_insert_cropped_attachment
2. 556ms to run WP_Test_REST_Users_Controller:test_get_items_pagination_headers
3. 407ms to run Tests_Media:test_wp_calculate_image_srcset_no_date_uploads
4. 403ms to run Tests_Media:test_wp_calculate_image_srcset_no_width
5. 377ms to run WP_Test_REST_Users_Controller:test_get_items_per_page
6. 344ms to run Tests_WP_Site_Icon:test_create_attachment_object
7. 317ms to run WP_Test_REST_Posts_Controller:test_get_items_pagination_headers
8. 259ms to run WP_Test_REST_Users_Controller:test_get_additional_field_registration
9. 245ms to run WP_Test_REST_Users_Controller:test_get_items_page
10. 236ms to run Tests_Import_Import:test_double_import
...and there are 19 more above your threshold hidden from view
Time: 1.35 minutes, Memory: 442.00MB
OK, but incomplete, skipped, or risky tests!
Tests: 8046, Assertions: 34440, Skipped: 32, Risky: 8.
Succeeded!
Cleanup
Just run this command.
$ php cleanup.php
Environment variables pass checks.
rm -rf '/tmp/wp-test-runner/.git'
rm -r '/tmp/wp-test-runner'