Skip to content

Commit

Permalink
Add test for missing composer json file
Browse files Browse the repository at this point in the history
  • Loading branch information
ernilambar committed Dec 26, 2024
1 parent 7721815 commit baaf55b
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ build
############

node_modules/
vendor/
/vendor/

############
## OSes
Expand Down
2 changes: 1 addition & 1 deletion includes/Checker/Checks/Plugin_Repo/File_Type_Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
/**
* Plugin Name: Test Plugin File Type Composer Files
* Plugin URI: https://github.com/WordPress/plugin-check
* Description: Some plugin description.
* Author: WordPress Performance Team
* Author URI: https://make.wordpress.org/plugins/
* License: GPLv2 or later
* License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* Text Domain: test-plugin-file-type-composer-errors
*
* @package test-plugin-file-type-composer-errors
*/

/**
* Plugin folder contains a vendor folder without composer.json file.
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

// autoload.php @generated by Composer
14 changes: 14 additions & 0 deletions tests/phpunit/tests/Checker/Checks/File_Type_Check_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,18 @@ public function test_run_with_library_core_errors() {
$this->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' ) ) );
}
}

0 comments on commit baaf55b

Please sign in to comment.