From baaf55b0df5733c4c34a1024beccd7f981f9b4ab Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Thu, 26 Dec 2024 11:18:44 +0545 Subject: [PATCH] Add test for missing composer json file --- .gitignore | 2 +- .../Checks/Plugin_Repo/File_Type_Check.php | 2 +- .../load.php | 17 +++++++++++++++++ .../vendor/autoload.php | 3 +++ .../Checker/Checks/File_Type_Check_Tests.php | 14 ++++++++++++++ 5 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 tests/phpunit/testdata/plugins/test-plugin-file-type-composer-errors/load.php create mode 100644 tests/phpunit/testdata/plugins/test-plugin-file-type-composer-errors/vendor/autoload.php diff --git a/.gitignore b/.gitignore index e3e404997..160702ca8 100644 --- a/.gitignore +++ b/.gitignore @@ -28,7 +28,7 @@ build ############ node_modules/ -vendor/ +/vendor/ ############ ## OSes diff --git a/includes/Checker/Checks/Plugin_Repo/File_Type_Check.php b/includes/Checker/Checks/Plugin_Repo/File_Type_Check.php index 9ac98e88f..ac4694e25 100644 --- a/includes/Checker/Checks/Plugin_Repo/File_Type_Check.php +++ b/includes/Checker/Checks/Plugin_Repo/File_Type_Check.php @@ -400,7 +400,7 @@ protected function look_for_composer_files( Check_Result $result, array $files ) $result, sprintf( /* translators: 1: directory, 2: filename */ - esc_html__( 'The "%1$s" directory exists, but "%2$s" is missing.', 'plugin-check' ), + esc_html__( 'The "%1$s" directory using composer exists, but "%2$s" file is missing.', 'plugin-check' ), '/vendor', 'composer.json' ), diff --git a/tests/phpunit/testdata/plugins/test-plugin-file-type-composer-errors/load.php b/tests/phpunit/testdata/plugins/test-plugin-file-type-composer-errors/load.php new file mode 100644 index 000000000..bd9830168 --- /dev/null +++ b/tests/phpunit/testdata/plugins/test-plugin-file-type-composer-errors/load.php @@ -0,0 +1,17 @@ +assertArrayHasKey( 0, $errors['jquery.js'][0] ); $this->assertCount( 1, wp_list_filter( $errors['jquery.js'][0][0], array( 'code' => 'library_core_files' ) ) ); } + + public function test_run_with_composer_errors() { + $check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-file-type-composer-errors/load.php' ); + $check_result = new Check_Result( $check_context ); + + $check = new File_Type_Check( File_Type_Check::TYPE_COMPOSER ); + $check->run( $check_result ); + + $warnings = $check_result->get_warnings(); + + $this->assertNotEmpty( $warnings ); + + $this->assertCount( 1, wp_list_filter( $warnings['composer.json'][0][0], array( 'code' => 'missing_composer_json_file' ) ) ); + } }