diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml new file mode 100644 index 000000000..bf2e9ac29 --- /dev/null +++ b/.github/workflows/testing.yml @@ -0,0 +1,146 @@ +name: Testing + +on: pull_request + +jobs: + + unit: #----------------------------------------------------------------------- + name: Unit test / PHP ${{ matrix.php }} + strategy: + fail-fast: false + matrix: + php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0'] + runs-on: ubuntu-latest + + steps: + - name: Check out source code + uses: actions/checkout@v2 + + - name: Check existence of composer.json file + id: check_files + uses: andstor/file-existence-action@v1 + with: + files: "composer.json, phpunit.xml.dist" + + - name: Set up PHP environment + if: steps.check_files.outputs.files_exists == 'true' + uses: shivammathur/setup-php@v2 + with: + php-version: '${{ matrix.php }}' + coverage: none + tools: composer,cs2pr + + - name: Get Composer cache Directory + if: steps.check_files.outputs.files_exists == 'true' + id: composer-cache + run: | + echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Use Composer cache + if: steps.check_files.outputs.files_exists == 'true' + uses: actions/cache@master + with: + path: ${{ steps['composer-cache'].outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-composer- + + - name: Install dependencies + if: steps.check_files.outputs.files_exists == 'true' + run: COMPOSER_ROOT_VERSION=dev-master composer install --prefer-dist --no-progress --no-suggest + + - name: Setup problem matcher to provide annotations for PHPUnit + if: steps.check_files.outputs.files_exists == 'true' + run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + + - name: Run PHPUnit + if: steps.check_files.outputs.files_exists == 'true' + run: composer phpunit + + functional: #---------------------------------------------------------------------- + name: Functional - WP ${{ matrix.wp }} on PHP ${{ matrix.php }} + strategy: + fail-fast: false + matrix: + php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4'] + wp: ['latest'] + test: ["composer behat || composer behat-rerun"] + include: + - php: '5.6' + wp: 'trunk' + test: "composer behat || composer behat-rerun" + - php: '7.4' + wp: 'trunk' + test: "composer behat || composer behat-rerun" + - php: '5.6' + wp: '3.7' + test: "composer behat || composer behat-rerun || true" + runs-on: ubuntu-latest + + services: + mysql: + image: mysql:5.7 + env: + MYSQL_DATABASE: wp_cli_test + MYSQL_USER: root + MYSQL_ROOT_PASSWORD: root + ports: + - 3306 + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + + steps: + - name: Check out source code + uses: actions/checkout@v2 + + - name: Check existence of composer.json & behat.yml files + id: check_files + uses: andstor/file-existence-action@v1 + with: + files: "composer.json, behat.yml" + + - name: Set up PHP envirnoment + uses: shivammathur/setup-php@v2 + with: + php-version: '${{ matrix.php }}' + extensions: mysql, zip + coverage: none + tools: composer + + - name: Get Composer cache Directory + if: steps.check_files.outputs.files_exists == 'true' + id: composer-cache + run: | + echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Use Composer cache + if: steps.check_files.outputs.files_exists == 'true' + uses: actions/cache@master + with: + path: ${{ steps['composer-cache'].outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-composer- + + - name: Install dependencies + if: steps.check_files.outputs.files_exists == 'true' + run: COMPOSER_ROOT_VERSION=dev-master composer install --prefer-dist --no-progress --no-suggest + + - name: Start MySQL server + if: steps.check_files.outputs.files_exists == 'true' + run: sudo service mysql start + + - name: Prepare test database + if: steps.check_files.outputs.files_exists == 'true' + run: | + export MYQSL_HOST=127.0.0.1 + export MYSQL_TCP_PORT=${{ job.services.mysql.ports['3306'] }} + mysql -e 'CREATE DATABASE IF NOT EXISTS wp_cli_test;' -uroot -proot + mysql -e 'GRANT ALL PRIVILEGES ON wp_cli_test.* TO "wp_cli_test"@"127.0.0.1" IDENTIFIED BY "password1"' -uroot -proot + mysql -e 'GRANT ALL PRIVILEGES ON wp_cli_test_scaffold.* TO "wp_cli_test"@"127.0.0.1" IDENTIFIED BY "password1"' -uroot -proot + + - name: Run Behat + if: steps.check_files.outputs.files_exists == 'true' + env: + WP_VERSION: '${{ matrix.wp }}' + run: ${{ matrix.test }} + diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 45dc08339..000000000 --- a/.travis.yml +++ /dev/null @@ -1,83 +0,0 @@ -os: linux -dist: xenial - -language: php -php: 7.4 - -services: - - mysql - -notifications: - email: - on_success: never - on_failure: change - -branches: - only: - - master - -cache: - directories: - - $HOME/.composer/cache - -env: - global: - - PATH="$TRAVIS_BUILD_DIR/vendor/bin:$PATH" - - WP_CLI_BIN_DIR="$TRAVIS_BUILD_DIR/vendor/bin" - -before_install: - - | - # Remove Xdebug for a huge performance increase: - if [ -f ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini ]; then - phpenv config-rm xdebug.ini - else - echo "xdebug.ini does not exist" - fi - - | - # Raise PHP memory limit to 2048MB - echo 'memory_limit = 2048M' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini - - composer validate - -install: - - composer install - - composer prepare-tests - -script: - - composer phpunit - - composer behat || composer behat-rerun - -jobs: - include: - - stage: test - php: nightly - env: WP_VERSION=trunk - - stage: test - php: 7.4 - env: WP_VERSION=latest - - stage: test - php: 7.3 - env: WP_VERSION=latest - - stage: test - php: 7.2 - env: WP_VERSION=latest - - stage: test - php: 7.1 - env: WP_VERSION=latest - - stage: test - php: 7.0 - env: WP_VERSION=latest - - stage: test - php: 5.6 - env: WP_VERSION=latest - - stage: test - php: 5.6 - env: WP_VERSION=3.7.11 - dist: trusty - - stage: test - php: 5.6 - env: WP_VERSION=trunk - - allow_failures: - - stage: test - php: nightly - env: WP_VERSION=trunk diff --git a/composer.json b/composer.json index 48103fd87..be7e9ecaa 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "require": { "ext-json": "*", "composer/composer": ">=1.2.0 <1.7.0 || ^1.7.1 || ^2.0.0", - "wp-cli/wp-cli": "dev-master" + "wp-cli/wp-cli": "~2.5" }, "require-dev": { "wp-cli/scaffold-command": "^1 || ^2", diff --git a/features/package.feature b/features/package.feature index 72271d95f..12f14b4ec 100644 --- a/features/package.feature +++ b/features/package.feature @@ -57,7 +57,7 @@ Feature: Manage WP-CLI packages When I run `wp --require=bad-command.php package list` Then STDERR should be empty - @require-php-7.0 + @require-php-7.2 Scenario: Revert the WP-CLI packages composer.json when fail to install/uninstall a package due to memory limit Given an empty directory When I try `{INVOKE_WP_CLI_WITH_PHP_ARGS--dmemory_limit=10M -ddisable_functions=ini_set} package install danielbachhuber/wp-cli-reset-post-date-command` @@ -96,7 +96,7 @@ Feature: Manage WP-CLI packages {MYPACKAGES_COMPOSER_JSON} """ - @require-php-7.0 + @require-php-7.2 Scenario: Revert the WP-CLI packages composer.json when fail to install/uninstall a package due to memory limit Given an empty directory When I try `{INVOKE_WP_CLI_WITH_PHP_ARGS--dmemory_limit=10M -ddisable_functions=ini_set} package install danielbachhuber/wp-cli-reset-post-date-command` diff --git a/tests/test-composer-json.php b/tests/test-composer-json.php index c9bbea222..dcb214c0b 100644 --- a/tests/test-composer-json.php +++ b/tests/test-composer-json.php @@ -3,20 +3,21 @@ use WP_CLI\Utils; use WP_CLI\ExitException; use WP_CLI\Loggers\Execution; +use WP_CLI\Tests\TestCase; require_once VENDOR_DIR . '/wp-cli/wp-cli/php/utils.php'; require_once VENDOR_DIR . '/wp-cli/wp-cli/php/class-wp-cli.php'; require_once VENDOR_DIR . '/wp-cli/wp-cli/php/class-wp-cli-command.php'; -class ComposerJsonTest extends PHPUnit_Framework_TestCase { +class ComposerJsonTest extends TestCase { private $logger = null; private $prev_logger = null; private $prev_capture_exit = null; private $temp_dir = null; - public function setUp() { - parent::setUp(); + public function set_up() { + parent::set_up(); // Save and set logger. $class_wp_cli_logger = new \ReflectionProperty( 'WP_CLI', 'logger' ); @@ -36,7 +37,7 @@ public function setUp() { mkdir( $this->temp_dir ); } - public function tearDown() { + public function tear_down() { // Restore logger. WP_CLI::set_logger( $this->prev_logger ); @@ -47,7 +48,7 @@ public function tearDown() { rmdir( $this->temp_dir ); - parent::tearDown(); + parent::tear_down(); } public function test_create_default_composer_json() { diff --git a/tests/test-json-manipulator.php b/tests/test-json-manipulator.php index 05916f1be..add2727a7 100644 --- a/tests/test-json-manipulator.php +++ b/tests/test-json-manipulator.php @@ -11,8 +11,9 @@ */ use WP_CLI\JsonManipulator; // WP_CLI +use WP_CLI\Tests\TestCase; -class JsonManipulatorTest extends \PHPUnit_Framework_TestCase +class JsonManipulatorTest extends TestCase { /**