diff --git a/.github/workflows/cs-lint.yml b/.github/workflows/cs-lint.yml index fe4dac4a7..fbed4369f 100644 --- a/.github/workflows/cs-lint.yml +++ b/.github/workflows/cs-lint.yml @@ -37,7 +37,7 @@ jobs: uses: korelstar/xmllint-problem-matcher@v1 - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 # Validate the composer.json file. # @link https://getcomposer.org/doc/03-cli.md#validate @@ -45,11 +45,11 @@ jobs: run: composer validate --no-check-all # Install dependencies and handle caching in one go. - # @link https://github.com/marketplace/actions/install-composer-dependencies - - name: Install Composer dependencies - uses: ramsey/composer-install@v1 - + # @link https://github.com/marketplace/actions/install-php-dependencies-with-composer + - name: Install PHP Dependencies with Composer + uses: ramsey/composer-install@2.2.0 # Lint PHP. + - name: Lint PHP against parse errors run: composer lint-ci | cs2pr diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index 7a45293af..dc8366c63 100755 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -108,8 +108,8 @@ install_test_suite() { # set up testing suite mkdir -p $WP_TESTS_DIR rm -rf $WP_TESTS_DIR/{includes,data} - svn export --quiet --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes - svn export --quiet --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data + svn export --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes + svn export --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data fi if [ ! -f wp-tests-config.php ]; then diff --git a/composer.json b/composer.json index dfb2b6027..e1f47f820 100644 --- a/composer.json +++ b/composer.json @@ -16,13 +16,13 @@ }, "require-dev": { "automattic/vipwpcs": "^2.2", - "dealerdirect/phpcodesniffer-composer-installer": "^0.4.1 || ^0.5 || ^0.6.2 || ^0.7", + "dealerdirect/phpcodesniffer-composer-installer": "^1.0", "php-parallel-lint/php-parallel-lint": "^1.0", "phpcompatibility/phpcompatibility-wp": "^2.1", - "phpunit/phpunit": "^4 || ^5 || ^6 || ^7", + "phpunit/phpunit": "^9", "squizlabs/php_codesniffer": "^3.5", "wp-coding-standards/wpcs": "^2.3.0", - "yoast/phpunit-polyfills": "^0.2.0" + "yoast/phpunit-polyfills": "^2.0" }, "scripts": { "coverage": [ @@ -57,5 +57,11 @@ "support": { "issues": "https://github.com/Automattic/msm-sitemap/issues", "source": "https://github.com/Automattic/msm-sitemap" + }, + "config": { + "allow-plugins": { + "composer/installers": true, + "dealerdirect/phpcodesniffer-composer-installer": true + } } } diff --git a/tests/test-sitemap--cron.php b/tests/test-sitemap--cron.php index 82dc2c493..357603eba 100644 --- a/tests/test-sitemap--cron.php +++ b/tests/test-sitemap--cron.php @@ -31,7 +31,7 @@ class WP_Test_Sitemap_Cron extends WP_UnitTestCase { /** * Generate posts and build the sitemap */ - function setup() { + function setup(): void { if ( ! class_exists( 'MSM_Sitemap_Builder_Cron' ) ) { require dirname( dirname( __FILE__ ) ) . '/includes/msm-sitemap-builder-cron.php'; MSM_Sitemap_Builder_Cron::setup(); @@ -55,7 +55,7 @@ function setup() { /** * Remove the sample posts and the sitemap posts */ - function teardown() { + function teardown(): void { $this->test_base->posts = array(); $sitemaps = get_posts( array( 'post_type' => Metro_Sitemap::SITEMAP_CPT, @@ -98,7 +98,7 @@ function test_cron_jobs_scheduling() { $years_being_processed = (array) get_option( 'msm_years_to_process', array() ); // Validate Current Month is added to months_to_process. - $month = date( 'n', time() ); + $month = (int) date( 'n', time() ); $this->assertContains( $month, $months_being_processed, 'Initial Year Processing should use Current Month if same year' ); // fake_cron. diff --git a/tests/test-sitemap-cpt.php b/tests/test-sitemap-cpt.php index f3d403ec5..1ea608ac8 100644 --- a/tests/test-sitemap-cpt.php +++ b/tests/test-sitemap-cpt.php @@ -31,7 +31,7 @@ class WP_Test_Sitemap_CPT extends WP_UnitTestCase { /** * Initialize Test CPT */ - static function setupBeforeClass() { + static function setupBeforeClass(): void { register_post_type( self::TEST_CPT, array( @@ -55,7 +55,7 @@ static function setupBeforeClass() { /** * Initialize MSM_SiteMap_Test */ - function setup() { + function setup(): void { $this->test_base = new MSM_SiteMap_Test(); @@ -88,7 +88,7 @@ function setup() { /** * Remove the sample posts and the sitemap posts */ - function teardown() { + function teardown(): void { $this->test_base->posts = array(); $sitemaps = get_posts( array( 'post_type' => Metro_Sitemap::SITEMAP_CPT, diff --git a/tests/test-sitemap-creation.php b/tests/test-sitemap-creation.php index 41b6bbe88..3a04a67b3 100644 --- a/tests/test-sitemap-creation.php +++ b/tests/test-sitemap-creation.php @@ -32,7 +32,7 @@ class WP_Test_Sitemap_Creation extends WP_UnitTestCase { /** * Generate posts and build the sitemap */ - function setup() { + function setup(): void { $this->test_base = new MSM_SiteMap_Test(); @@ -52,7 +52,7 @@ function setup() { /** * Remove the sample posts and the sitemap posts */ - function teardown() { + function teardown(): void { $this->test_base->posts = array(); $sitemaps = get_posts( array( 'post_type' => Metro_Sitemap::SITEMAP_CPT, @@ -81,7 +81,7 @@ function test_sitemap_posts_were_created() { foreach ( $sitemaps as $i => $map_id ) { $xml = get_post_meta( $map_id, 'msm_sitemap_xml', true ); $post_id = $this->test_base->posts[ $i ]['ID']; - $this->assertContains( 'p=' . $post_id, $xml ); + $this->assertStringContainsString( 'p=' . $post_id, $xml ); $xml_struct = simplexml_load_string( $xml ); $this->assertNotEmpty( $xml_struct->url ); @@ -89,7 +89,7 @@ function test_sitemap_posts_were_created() { $this->assertNotEmpty( $xml_struct->url->lastmod ); $this->assertNotEmpty( $xml_struct->url->changefreq ); $this->assertNotEmpty( $xml_struct->url->priority ); - $this->assertContains( 'p=' . $post_id, (string) $xml_struct->url->loc ); + $this->assertStringContainsString( 'p=' . $post_id, (string) $xml_struct->url->loc ); $post = get_post( $post_id ); setup_postdata( $post ); diff --git a/tests/test-sitemap-filter.php b/tests/test-sitemap-filter.php index 42db71cca..0b1e99fbc 100644 --- a/tests/test-sitemap-filter.php +++ b/tests/test-sitemap-filter.php @@ -23,7 +23,7 @@ function test_bypass_main_query() { // Verify post_pre_query on sitemap queryvar returns empty array set_query_var( 'sitemap', 'true' ); $posts = apply_filters_ref_array( 'posts_pre_query', array( null, $wp_query ) ); - $this->assertInternalType('array', $posts); + $this->assertIsArray( $posts ); $this->assertEmpty( $posts ); } diff --git a/tests/test-sitemap-functions.php b/tests/test-sitemap-functions.php index 1ab56a48c..85398ca25 100644 --- a/tests/test-sitemap-functions.php +++ b/tests/test-sitemap-functions.php @@ -24,7 +24,7 @@ class WP_Test_Sitemap_Functions extends WP_UnitTestCase { /** * Initialize MSM_SiteMap_Test */ - function setup() { + function setup(): void { $this->test_base = new MSM_SiteMap_Test(); } @@ -32,7 +32,7 @@ function setup() { /** * Remove the sample posts and the sitemap posts */ - function teardown() { + function teardown(): void { $this->test_base->posts = array(); $sitemaps = get_posts( array( 'post_type' => Metro_Sitemap::SITEMAP_CPT, @@ -141,12 +141,12 @@ function test_check_year_has_posts() { // Add a post for last year and 5 years ago. $date = strtotime( '-1 year', time() ); $cur_day = date( 'Y', $date ) . '-' . date( 'm', $date ) . '-' . date( 'd', $date ) . ' 00:00:00'; - $prev_year = date( 'Y', $date ); + $prev_year = (int) date( 'Y', $date ); $this->test_base->create_dummy_post( $cur_day ); $date = strtotime( '-4 year', $date ); $cur_day = date( 'Y', $date ) . '-' . date( 'm', $date ) . '-' . date( 'd', $date ) . ' 00:00:00'; - $prev5_year = date( 'Y', $date ); + $prev5_year = (int) date( 'Y', $date ); $this->test_base->create_dummy_post( $cur_day ); // Verify only Years for Posts are returned. diff --git a/tests/test-sitemap-index.php b/tests/test-sitemap-index.php index f8ae43bf5..979766dbd 100644 --- a/tests/test-sitemap-index.php +++ b/tests/test-sitemap-index.php @@ -31,7 +31,7 @@ class WP_Test_Sitemap_Index extends WP_UnitTestCase { /** * Generate posts and build initial sitemaps */ - function setup() { + function setup(): void { _delete_all_posts(); $this->test_base = new MSM_SiteMap_Test(); @@ -54,7 +54,7 @@ function setup() { /** * Remove created posts, sitemaps and options */ - function teardown() { + function teardown(): void { $this->test_base->posts = array(); $sitemaps = get_posts( array( 'post_type' => Metro_Sitemap::SITEMAP_CPT, diff --git a/tests/test-sitemap-stats.php b/tests/test-sitemap-stats.php index 6feef637c..cf5d89a77 100644 --- a/tests/test-sitemap-stats.php +++ b/tests/test-sitemap-stats.php @@ -32,7 +32,7 @@ class WP_Test_Sitemap_Stats extends WP_UnitTestCase { /** * Generate posts and build initial sitemaps */ - function setup() { + function setup(): void { _delete_all_posts(); $this->test_base = new MSM_SiteMap_Test(); @@ -55,7 +55,7 @@ function setup() { /** * Remove created posts, Sitemaps and options */ - function teardown() { + function teardown(): void { $this->test_base->posts = array(); $sitemaps = get_posts( array( 'post_type' => Metro_Sitemap::SITEMAP_CPT,