From 4271f1aeca533be3dacdcd68d2f71b1e29929706 Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Wed, 7 Aug 2019 11:54:22 +0000 Subject: [PATCH] Build Tools: Switch all Travis PHPUnit jobs over to Docker-based PHP. Additionally, there are a handful of related minor changes in this commit: - `.travis.yml` has been tidied up a little. - [45745] was incorrectly marking Travis jobs as passed when some PHPUnit runs failed. - Add the `LOCAL_PHP_MEMCACHED` environment variable, for enabling Memcached. - Add the `env:pull` NPM script, for refreshing Docker images. See #47767. git-svn-id: https://develop.svn.wordpress.org/trunk@45762 602fd350-edb4-49c9-b593-d223f7449a82 --- .env | 3 + .travis.yml | 70 ++++++++++----------- package.json | 2 + tests/phpunit/includes/object-cache.php | 2 +- tests/phpunit/tests/ajax/CustomizeMenus.php | 4 +- tools/local-env/docker-compose.scripts.yml | 2 + tools/local-env/docker-compose.yml | 1 + 7 files changed, 43 insertions(+), 41 deletions(-) diff --git a/.env b/.env index fda527930dbf0..63ae0f19629e1 100644 --- a/.env +++ b/.env @@ -18,6 +18,9 @@ LOCAL_PHP=latest # Whether or not to enable XDebug. LOCAL_PHP_XDEBUG=false +# Whether or not to enable Memcached. +LOCAL_PHP_MEMCACHED=false + # The MySQL version to use. See https://hub.docker.com/_/mysql/ for valid versions. LOCAL_MYSQL=5.7 diff --git a/.travis.yml b/.travis.yml index 15ed25bd35ca1..4e083c87e9955 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,43 +17,38 @@ cache: env: global: - - LOCAL_DIR=build + - LOCAL_DIR: build matrix: include: - env: WP_TRAVISCI=test:e2e + name: E2E Tests - env: WP_TRAVISCI=travis:phpcs + name: PHP Linting - env: WP_TRAVISCI=travis:js + name: JS Tests - env: LOCAL_PHP=7.3-fpm WP_TRAVISCI=test:php - - php: 7.3 - dist: trusty - env: WP_TRAVIS_OBJECT_CACHE=true WP_TRAVISCI=travis:phpunit - services: memcached + name: "PHPUnit Tests: PHP 7.3" + - env: LOCAL_PHP=7.3-fpm LOCAL_PHP_MEMCACHED=true WP_TRAVISCI=test:php + name: "PHPUnit Tests: PHP 7.3 with Memcached" - env: LOCAL_PHP=7.2-fpm WP_TRAVISCI=test:php + name: "PHPUnit Tests: PHP 7.2" - env: LOCAL_PHP=7.1-fpm WP_TRAVISCI=test:php + name: "PHPUnit Tests: PHP 7.1" - env: LOCAL_PHP=7.0-fpm WP_TEST_REPORTER=true WP_TRAVISCI=test:php + name: "PHPUnit Tests: PHP 7.0" - env: LOCAL_PHP=5.6-fpm WP_TRAVISCI=test:php - - php: 7.4snapshot - dist: trusty - env: WP_TRAVISCI=travis:phpunit - - php: nightly - dist: trusty - env: WP_TRAVISCI=travis:phpunit + name: "PHPUnit Tests: PHP 5.6" + - env: LOCAL_PHP=7.4-fpm WP_TRAVISCI=test:php + name: "PHPUnit Tests: PHP 7.4" + - env: LOCAL_PHP=8.0-fpm WP_TRAVISCI=test:php + name: "PHPUnit Tests: PHP 8.0" allow_failures: - - php: 7.4snapshot - - php: nightly + - env: LOCAL_PHP=7.4-fpm WP_TRAVISCI=test:php + - env: LOCAL_PHP=8.0-fpm WP_TRAVISCI=test:php fast_finish: true before_install: -- | - if [[ "$WP_TRAVISCI" == "travis:phpunit" ]]; then - mysql -u root -e "CREATE DATABASE wordpress_tests;" - cp wp-tests-config-sample.php wp-tests-config.php - sed -i "s/youremptytestdbnamehere/wordpress_tests/" wp-tests-config.php - sed -i "s/yourusernamehere/root/" wp-tests-config.php - sed -i "s/yourpasswordhere//" wp-tests-config.php - travis_retry svn checkout https://plugins.svn.wordpress.org/wordpress-importer/tags/0.6.3/ tests/phpunit/data/plugins/wordpress-importer - fi - | if [[ "$WP_TRAVISCI" == "test:php" ]]; then cp wp-tests-config-sample.php wp-tests-config.php @@ -61,6 +56,7 @@ before_install: sed -i "s/yourusernamehere/root/" wp-tests-config.php sed -i "s/yourpasswordhere/password/" wp-tests-config.php sed -i "s/localhost/mysql/" wp-tests-config.php + echo "define( 'FS_METHOD', 'direct' );" >> wp-tests-config.php travis_retry svn checkout https://plugins.svn.wordpress.org/wordpress-importer/tags/0.6.3/ tests/phpunit/data/plugins/wordpress-importer fi - | @@ -68,11 +64,6 @@ before_install: curl -L https://github.com/docker/compose/releases/download/1.24.0/docker-compose-`uname -s`-`uname -m` > docker-compose chmod +x docker-compose sudo mv docker-compose /usr/local/bin -- | - if [[ "$WP_TRAVIS_OBJECT_CACHE" == "true" ]]; then - cp tests/phpunit/includes/object-cache.php src/wp-content/object-cache.php - echo "extension = memcached.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini - fi before_script: - | @@ -107,19 +98,22 @@ before_script: if [[ "$WP_TRAVISCI" == "test:e2e" ]] || [[ "$WP_TRAVISCI" == "test:php" ]]; then npm run env:start npm run build + docker-compose -f tools/local-env/docker-compose.yml run --rm mysql mysql --version + docker-compose -f tools/local-env/docker-compose.yml run --rm php php --version + docker-compose -f tools/local-env/docker-compose.yml run --rm php php -m + docker-compose -f tools/local-env/docker-compose.yml -f tools/local-env/docker-compose.scripts.yml run --rm phpunit phpunit --version + fi +- | + if [[ "$LOCAL_PHP_MEMCACHED" == "true" ]]; then + cp tests/phpunit/includes/object-cache.php build/wp-content/object-cache.php + docker run --name memcached --net local-env_wpdevnet -d memcached fi - | if [[ "$WP_TRAVISCI" == "test:e2e" ]]; then npm run env:install fi -- mysql --version -- phpenv versions -- php --version -- php -m - npm --version - node --version -- which phpunit -- phpunit --version - curl --version - git --version - svn --version @@ -130,11 +124,11 @@ script: if [[ "$WP_TRAVISCI" == "test:e2e" ]]; then npm run test:e2e elif [[ "$WP_TRAVISCI" == "test:php" ]]; then - npm run test:php -- -- -- --verbose -c phpunit.xml.dist - npm run test:php -- -- -- --verbose -c phpunit.xml.dist --group ajax - npm run test:php -- -- -- --verbose -c tests/phpunit/multisite.xml - npm run test:php -- -- -- --verbose -c tests/phpunit/multisite.xml --group ms-files - npm run test:php -- -- -- --verbose -c phpunit.xml.dist --group external-http + npm run test:php -- -- -- --verbose -c phpunit.xml.dist && + npm run test:php -- -- -- --verbose -c phpunit.xml.dist --group ajax && + npm run test:php -- -- -- --verbose -c tests/phpunit/multisite.xml && + npm run test:php -- -- -- --verbose -c tests/phpunit/multisite.xml --group ms-files && + npm run test:php -- -- -- --verbose -c phpunit.xml.dist --group external-http && npm run test:php -- -- -- --verbose -c phpunit.xml.dist --group restapi-jsclient else npm run grunt $WP_TRAVISCI diff --git a/package.json b/package.json index 023b269d489e8..8ab2c53cea799 100644 --- a/package.json +++ b/package.json @@ -147,6 +147,8 @@ "env:cli": "dotenv npm run env:__cli-next", "env:__cli-next": "docker-compose -f ./tools/local-env/docker-compose.yml -f ./tools/local-env/docker-compose.scripts.yml run --rm cli", "env:logs": "docker-compose -f ./tools/local-env/docker-compose.yml -f ./tools/local-env/docker-compose.scripts.yml logs", + "env:pull": "dotenv npm run env:__pull-next", + "env:__pull-next": "docker-compose -f ./tools/local-env/docker-compose.yml -f ./tools/local-env/docker-compose.scripts.yml pull", "test:e2e": "dotenv npm run test:__e2e-next", "test:__e2e-next": "cross-var cross-env WP_BASE_URL=http://localhost:$LOCAL_PORT wp-scripts test-e2e --config tests/e2e/jest.config.js", "test:php": "dotenv npm run test:__php-next", diff --git a/tests/phpunit/includes/object-cache.php b/tests/phpunit/includes/object-cache.php index 8fcc4f9261309..c97ccb8d6484b 100644 --- a/tests/phpunit/includes/object-cache.php +++ b/tests/phpunit/includes/object-cache.php @@ -835,7 +835,7 @@ public function __construct( $persistent_id = null ) { if ( isset( $memcached_servers ) ) { $this->servers = $memcached_servers; } else { - $this->servers = array( array( '127.0.0.1', 11211 ) ); + $this->servers = array( array( 'memcached', 11211 ) ); } $this->addServers( $this->servers ); diff --git a/tests/phpunit/tests/ajax/CustomizeMenus.php b/tests/phpunit/tests/ajax/CustomizeMenus.php index bca0bdcc6471d..bb092cdad43fb 100644 --- a/tests/phpunit/tests/ajax/CustomizeMenus.php +++ b/tests/phpunit/tests/ajax/CustomizeMenus.php @@ -54,7 +54,7 @@ function test_ajax_load_available_items_cap_check( $role, $expected_results ) { if ( 'administrator' !== $role ) { // If we're not an admin, we should get a wp_die(-1). - $this->setExpectedException( 'WPAjaxDieStopException' ); + $this->setExpectedException( 'WPAjaxDieStopException', '-1' ); } wp_set_current_user( self::factory()->user->create( array( 'role' => $role ) ) ); @@ -443,7 +443,7 @@ function test_ajax_search_available_items_caps_check( $role, $expected_results ) if ( 'administrator' !== $role ) { // If we're not an admin, we should get a wp_die(-1). - $this->setExpectedException( 'WPAjaxDieStopException' ); + $this->setExpectedException( 'WPAjaxDieStopException', '-1' ); } wp_set_current_user( self::factory()->user->create( array( 'role' => $role ) ) ); diff --git a/tools/local-env/docker-compose.scripts.yml b/tools/local-env/docker-compose.scripts.yml index 1f42a5261b907..f5a51535453e4 100644 --- a/tools/local-env/docker-compose.scripts.yml +++ b/tools/local-env/docker-compose.scripts.yml @@ -13,6 +13,7 @@ services: environment: LOCAL_PHP_XDEBUG: ${LOCAL_PHP_XDEBUG-false} + LOCAL_PHP_MEMCACHED: ${LOCAL_PHP_MEMCACHED-false} volumes: - ../../:/var/www @@ -31,6 +32,7 @@ services: environment: LOCAL_PHP_XDEBUG: ${LOCAL_PHP_XDEBUG-false} + LOCAL_PHP_MEMCACHED: ${LOCAL_PHP_MEMCACHED-false} volumes: - ./phpunit-config.ini:/usr/local/etc/php/conf.d/phpunit-config.ini diff --git a/tools/local-env/docker-compose.yml b/tools/local-env/docker-compose.yml index 32021df1df9ee..ddbec7fe47572 100644 --- a/tools/local-env/docker-compose.yml +++ b/tools/local-env/docker-compose.yml @@ -38,6 +38,7 @@ services: environment: LOCAL_PHP_XDEBUG: ${LOCAL_PHP_XDEBUG-false} + LOCAL_PHP_MEMCACHED: ${LOCAL_PHP_MEMCACHED-false} volumes: - ./php-config.ini:/usr/local/etc/php/conf.d/php-config.ini