diff --git a/tests/phpunit/tests/Checker/Checks/File_Type_Check_Tests.php b/tests/phpunit/tests/Checker/Checks/File_Type_Check_Tests.php index 41ea389b6..72a04febe 100644 --- a/tests/phpunit/tests/Checker/Checks/File_Type_Check_Tests.php +++ b/tests/phpunit/tests/Checker/Checks/File_Type_Check_Tests.php @@ -131,30 +131,31 @@ public function test_run_with_badly_named_errors() { public function test_run_with_duplicated_named_errors() { // Initialize the Check_Context with a plugin path that mimics the directory structure. $check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-file-type-badly-named-files-errors/load.php' ); - + // Create an empty Check_Result instance for this context. $check_result = new Check_Result( $check_context ); // Initialize the File_Type_Check instance. $check = new File_Type_Check(); - // Use reflection to make check_files accessible. - $reflection = new \ReflectionClass( $check ); - $checkFilesMethod = $reflection->getMethod('check_files'); - $checkFilesMethod->setAccessible(true); + // Use reflection to make protected method accessible. + $reflection = new ReflectionClass( $check ); + $checkFilesMethod = $reflection->getMethod( 'look_for_badly_named_files' ); + $checkFilesMethod->setAccessible( true ); // Define the custom file list with duplicate names as they would appear in a plugin directory. - $customFiles = [ - UNIT_TESTS_PLUGIN_DIR . 'test-plugin-file-type-badly-named-files-errors/custom-file.php', - UNIT_TESTS_PLUGIN_DIR . 'test-plugin-file-type-badly-named-files-errors/Custom-File.php', - UNIT_TESTS_PLUGIN_DIR . 'test-plugin-file-type-badly-named-files-errors/custom-FILE.php' - ]; + $customFiles = array( + UNIT_TESTS_PLUGIN_DIR . 'test-plugin-file-type-badly-named-files-errors/custom-file.php', + UNIT_TESTS_PLUGIN_DIR . 'test-plugin-file-type-badly-named-files-errors/Custom-File.php', + UNIT_TESTS_PLUGIN_DIR . 'test-plugin-file-type-badly-named-files-errors/custom-FILE.php', + ); - // Invoke check_files with the Check_Result instance and custom file list. - $result = $checkFilesMethod->invoke($check, $check_result, $customFiles); + // Invoke method with the Check_Result instance and custom file list. + $result = $checkFilesMethod->invoke( $check, $check_result, $customFiles ); + + $errors = $check_result->get_errors(); - // Assert that check_files handles the custom file list with duplicates correctly. - $this->assertTrue($result->has_errors(), "The check_files method should detect errors for duplicate file names."); + $this->assertCount( 1, wp_list_filter( $errors['custom-file.php'][0][0], array( 'code' => 'duplicated_files' ) ) ); } public function test_run_with_library_core_errors() {