diff --git a/.github/workflows/php-test-plugins.yml b/.github/workflows/php-test-plugins.yml index 4e58a117a1..5aae802fb9 100644 --- a/.github/workflows/php-test-plugins.yml +++ b/.github/workflows/php-test-plugins.yml @@ -41,13 +41,17 @@ jobs: strategy: fail-fast: false matrix: - php: ['8.2', '8.1', '8.0', '7.4', '7.3', '7.2'] + php: ['8.1', '8.0', '7.4', '7.3', '7.2'] wp: [ 'latest' ] + coverage: [false] include: - php: '7.4' wp: '6.5' - php: '8.3' wp: 'trunk' + - php: '8.2' + wp: 'latest' + coverage: true env: WP_ENV_PHP_VERSION: ${{ matrix.php }} WP_ENV_CORE: ${{ matrix.wp == 'trunk' && 'WordPress/WordPress' || format( 'https://wordpress.org/wordpress-{0}.zip', matrix.wp ) }} @@ -68,6 +72,34 @@ jobs: - name: Composer Install run: npm run wp-env run tests-cli -- --env-cwd="wp-content/plugins/$(basename $(pwd))" composer install --no-interaction --no-progress - name: Running single site unit tests - run: npm run test-php + run: | + if [ "${{ matrix.coverage }}" == "true" ]; then + npm run test-php -- --coverage-clover=coverage-${{ github.sha }}.xml + else + npm run test-php + fi - name: Running multisite unit tests - run: npm run test-php-multisite + run: | + if [ "${{ matrix.coverage }}" == "true" ]; then + npm run test-php-multisite -- --coverage-clover=coverage-multisite-${{ github.sha }}.xml + else + npm run test-php-multisite + fi + - name: Upload single site coverage reports to Codecov + if: ${{ matrix.coverage == true }} + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: coverage-${{ github.sha }}.xml + flags: single + name: ${{ matrix.php }}-single-site-coverage + fail_ci_if_error: true + - name: Upload multisite coverage reports to Codecov + if: ${{ matrix.coverage == true }} + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: coverage-multisite-${{ github.sha }}.xml + flags: multisite + name: ${{ matrix.php }}-multisite-coverage + fail_ci_if_error: true diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000000..94ce322661 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,15 @@ +codecov: + notify: + require_ci_to_pass: yes +coverage: + status: + project: + default: + target: auto + threshold: 80% + base: auto + informational: true + patch: + default: + threshold: 80% + informational: true diff --git a/composer.json b/composer.json index 9d9ea27a1d..1503fcf405 100644 --- a/composer.json +++ b/composer.json @@ -89,7 +89,7 @@ "lint:web-worker-offloading": "@lint -- ./plugins/web-worker-offloading --standard=./plugins/web-worker-offloading/phpcs.xml.dist", "lint:webp-uploads": "@lint -- ./plugins/webp-uploads --standard=./plugins/webp-uploads/phpcs.xml.dist", "phpstan": "phpstan analyse --memory-limit=2048M", - "test": "phpunit", + "test": "phpunit --strict-coverage", "test-multisite": [ "WP_MULTISITE=1 phpunit --exclude-group=ms-excluded" ], diff --git a/plugins/webp-uploads/tests/test-load.php b/plugins/webp-uploads/tests/test-load.php index c9c8f0d32f..69ff75be07 100644 --- a/plugins/webp-uploads/tests/test-load.php +++ b/plugins/webp-uploads/tests/test-load.php @@ -43,6 +43,10 @@ static function ( string $filename ) { /** * Don't create the original mime type for JPEG images. * + * @covers ::wp_get_attachment_metadata + * @covers ::wp_get_original_image_path + * @covers ::get_post_mime_type + * @dataProvider data_provider_supported_image_types * @dataProvider data_provider_supported_image_types_with_threshold */ public function test_it_should_not_create_the_original_mime_type_for_jpeg_images( string $image_type, bool $above_big_image_size = false ): void { @@ -89,6 +93,9 @@ static function () { /** * Create the original mime type for WebP images. + * + * @covers ::wp_get_attachment_metadata + * @covers ::get_post_mime_type */ public function test_it_should_create_the_original_mime_type_as_well_with_all_the_available_sources_for_the_specified_mime(): void { update_option( 'perflab_generate_webp_and_jpeg', false ); @@ -119,6 +126,8 @@ public function test_it_should_create_the_original_mime_type_as_well_with_all_th /** * Create JPEG and output format for JPEG images, if perflab_generate_webp_and_jpeg option set. * + * @covers ::wp_get_attachment_metadata + * @covers ::get_post_mime_type * @dataProvider data_provider_supported_image_types */ public function test_it_should_create_jpeg_and_webp_for_jpeg_images_if_generate_webp_and_jpeg_set( string $image_type ): void { @@ -155,6 +164,9 @@ public function test_it_should_create_jpeg_and_webp_for_jpeg_images_if_generate_ /** * Don't create the sources property if no transform is provided. + * + * @covers ::wp_get_attachment_metadata + * @covers ::assertArrayNotHasKey */ public function test_it_should_not_create_the_sources_property_if_no_transform_is_provided(): void { add_filter( 'webp_uploads_upload_image_mime_transforms', '__return_empty_array' ); @@ -174,6 +186,8 @@ public function test_it_should_not_create_the_sources_property_if_no_transform_i /** * Create the sources property when no transform is available + * + * @covers ::wp_get_attachment_metadata */ public function test_it_should_create_the_sources_property_when_no_transform_is_available(): void { add_filter( @@ -199,6 +213,9 @@ static function () { /** * Not create the sources property if the mime is not specified on the transforms images + * + * @covers ::wp_get_attachment_metadata + * @covers ::assertArrayNotHasKey */ public function test_it_should_not_create_the_sources_property_if_the_mime_is_not_specified_on_the_transforms_images(): void { add_filter( @@ -223,6 +240,9 @@ static function () { /** * Create a WebP version with all the required properties + * + * @covers ::wp_get_attachment_metadata + * @covers ::assertFileExists */ public function test_it_should_create_a_webp_version_with_all_the_required_properties(): void { $attachment_id = self::factory()->attachment->create_upload_object( @@ -249,6 +269,8 @@ public function test_it_should_create_a_webp_version_with_all_the_required_prope /** * Create the full size images when no size is available + * + * @covers ::wp_get_attachment_metadata */ public function test_it_should_create_the_full_size_images_when_no_size_is_available(): void { add_filter( 'intermediate_image_sizes', '__return_empty_array' ); @@ -265,6 +287,9 @@ public function test_it_should_create_the_full_size_images_when_no_size_is_avail /** * Remove `scaled` suffix from the generated filename + * + * @covers ::get_attached_file + * @covers ::wp_get_attachment_metadata */ public function test_it_should_remove_scaled_suffix_from_the_generated_filename(): void { // Create JPEG and WebP to check for scaled suffix. @@ -290,6 +315,9 @@ static function () { /** * Remove the generated webp images when the attachment is deleted + * + * @covers ::get_attached_file + * @covers ::wp_get_attachment_metadata */ public function test_it_should_remove_the_generated_webp_images_when_the_attachment_is_deleted(): void { $attachment_id = self::factory()->attachment->create_upload_object( @@ -323,6 +351,9 @@ public function test_it_should_remove_the_generated_webp_images_when_the_attachm /** * Remove the attached WebP version if the attachment is force deleted + * + * @covers ::wp_delete_attachment + * @covers ::wp_get_attachment_metadata */ public function test_it_should_remove_the_attached_webp_version_if_the_attachment_is_force_deleted(): void { $attachment_id = self::factory()->attachment->create_upload_object( @@ -348,6 +379,9 @@ public function test_it_should_remove_the_attached_webp_version_if_the_attachmen /** * Remove full size images when no size image exists + * + * @covers ::wp_delete_attachment + * @covers ::wp_get_attachment_metadata */ public function test_it_should_remove_full_size_images_when_no_size_image_exists(): void { add_filter( 'intermediate_image_sizes', '__return_empty_array' ); @@ -371,6 +405,10 @@ public function test_it_should_remove_full_size_images_when_no_size_image_exists /** * Remove the attached WebP version if the attachment is force deleted after edit. + * + * @covers ::wp_delete_attachment + * @covers ::wp_get_attachment_metadata + * @covers ::get_post_meta */ public function test_it_should_remove_the_backup_sizes_and_sources_if_the_attachment_is_deleted_after_edit(): void { $attachment_id = self::factory()->attachment->create_upload_object( @@ -403,6 +441,7 @@ public function test_it_should_remove_the_backup_sizes_and_sources_if_the_attach /** * Avoid the change of URLs of images that are not part of the media library * + * @covers ::webp_uploads_update_image_references * @group webp_uploads_update_image_references */ public function test_it_should_avoid_the_change_of_urls_of_images_that_are_not_part_of_the_media_library(): void { @@ -417,6 +456,7 @@ public function test_it_should_avoid_the_change_of_urls_of_images_that_are_not_p /** * Avoid replacing not existing attachment IDs * + * @covers ::webp_uploads_update_image_references * @group webp_uploads_update_image_references */ public function test_it_should_avoid_replacing_not_existing_attachment_i_ds(): void { @@ -431,6 +471,7 @@ public function test_it_should_avoid_replacing_not_existing_attachment_i_ds(): v /** * Prevent replacing a WebP image * + * @covers ::webp_uploads_update_image_references * @group webp_uploads_update_image_references */ public function test_it_should_prevent_replacing_a_webp_image(): void { @@ -459,6 +500,8 @@ public function test_it_should_prevent_replacing_a_webp_image(): void { /** * Prevent replacing a jpg image if the image does not have the target class name + * + * @covers ::webp_uploads_update_image_references */ public function test_it_should_prevent_replacing_a_jpg_image_if_the_image_does_not_have_the_target_class_name(): void { $attachment_id = self::factory()->attachment->create_upload_object( @@ -476,6 +519,8 @@ public function test_it_should_prevent_replacing_a_jpg_image_if_the_image_does_n /** * Replace references to a JPG image to a WebP version * + * @covers ::webp_uploads_img_tag_update_mime_type + * @covers ::webp_uploads_update_image_references * @dataProvider provider_replace_images_with_different_extensions * @group webp_uploads_update_image_references */ @@ -504,6 +549,8 @@ public function test_it_should_replace_references_to_a_jpg_image_to_a_webp_versi /** * Should not replace jpeg images in the content if other mime types are disabled via filter. * + * @covers ::webp_uploads_img_tag_update_mime_type + * @covers ::webp_uploads_update_image_references * @dataProvider provider_replace_images_with_different_extensions * @group webp_uploads_update_image_references */ @@ -533,6 +580,9 @@ public function provider_replace_images_with_different_extensions(): Generator { /** * Replace all the images including the full size image + * + * @covers ::webp_uploads_img_tag_update_mime_type + * @covers ::webp_uploads_update_image_references */ public function test_it_should_replace_all_the_images_including_the_full_size_image(): void { // Create JPEG and WebP to check replacement of JPEG => WebP. @@ -560,6 +610,8 @@ public function test_it_should_replace_all_the_images_including_the_full_size_im /** * Prevent replacing an image with no available sources * + * @covers ::webp_uploads_img_tag_update_mime_type + * @covers ::webp_uploads_update_image_references * @group webp_uploads_update_image_references */ public function test_it_should_prevent_replacing_an_image_with_no_available_sources(): void { @@ -576,6 +628,8 @@ public function test_it_should_prevent_replacing_an_image_with_no_available_sour /** * Prevent update not supported images with no available sources * + * @covers ::webp_uploads_img_tag_update_mime_type + * @covers ::webp_uploads_update_image_references * @dataProvider data_provider_not_supported_webp_images * @group webp_uploads_update_image_references */ @@ -628,6 +682,8 @@ static function () { /** * Tests that we can force generating jpeg subsizes using the webp_uploads_upload_image_mime_transforms filter. + * + * @covers \Test_WebP_Uploads_Load::opt_in_to_jpeg_and_webp */ public function test_it_should_preserve_jpeg_subsizes_using_transform_filter(): void { // Create JPEG and WebP. @@ -648,6 +704,8 @@ public function test_it_should_preserve_jpeg_subsizes_using_transform_filter(): /** * Allow the upload of an image if at least one editor supports the image type * + * @covers ::wp_image_editor_supports + * @covers ::set_post_thumbnail * @dataProvider data_provider_supported_image_types * * @group current1 @@ -690,6 +748,8 @@ static function ( $editors ) { /** * Replace the featured image to the proper type when requesting the featured image. * + * @covers ::get_the_post_thumbnail + * @covers ::set_post_thumbnail * @dataProvider data_provider_supported_image_types */ public function test_it_should_replace_the_featured_image_to_webp_when_requesting_the_featured_image( string $image_type ): void { @@ -740,6 +800,7 @@ public function data_provider_supported_image_types_with_threshold(): array { /** * Prevent replacing an image if image was uploaded via external source or plugin. * + * @covers ::webp_uploads_update_image_references * @group webp_uploads_update_image_references */ public function test_it_should_prevent_replacing_an_image_uploaded_via_external_source(): void { @@ -762,6 +823,9 @@ static function () { /** * The image with the smaller filesize should be used when webp_uploads_discard_larger_generated_images is set to true. + * + * @covers ::webp_uploads_img_tag_update_mime_type + * @covers ::webp_uploads_update_image_references */ public function test_it_should_create_webp_when_webp_is_smaller_than_jpegs(): void { // Create JPEG and WebP. @@ -801,6 +865,9 @@ public function test_it_should_create_webp_when_webp_is_smaller_than_jpegs(): vo /** * The image with the smaller filesize should be used when webp_uploads_discard_larger_generated_images is set to true. + * + * @covers ::webp_uploads_img_tag_update_mime_type + * @covers ::webp_uploads_update_image_references */ public function test_it_should_create_webp_for_full_size_which_is_smaller_in_webp_format(): void { // Create JPEG and WebP. @@ -828,6 +895,9 @@ public function test_it_should_create_webp_for_full_size_which_is_smaller_in_web /** * The image with the smaller filesize should be used when webp_uploads_discard_larger_generated_images is set to true. + * + * @covers ::webp_uploads_img_tag_update_mime_type + * @covers ::webp_uploads_update_image_references */ public function test_it_should_create_webp_for_some_sizes_which_are_smaller_in_webp_format(): void { // Create JPEG and WebP.