Skip to content

Commit 2e88973

Browse files
committed
Add test for missing composer json file
1 parent 7721815 commit 2e88973

File tree

5 files changed

+38
-2
lines changed

5 files changed

+38
-2
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ build
2828
############
2929

3030
node_modules/
31-
vendor/
31+
/vendor/
3232

3333
############
3434
## OSes

includes/Checker/Checks/Plugin_Repo/File_Type_Check.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ public function get_categories() {
7676
*
7777
* @throws Exception Thrown when the check fails with a critical error (unrelated to any errors detected as part of
7878
* the check).
79+
*
80+
* @SuppressWarnings(PHPMD.NPathComplexity)
7981
*/
8082
protected function check_files( Check_Result $result, array $files ) {
8183
if ( $this->flags & self::TYPE_COMPRESSED ) {
@@ -400,7 +402,7 @@ protected function look_for_composer_files( Check_Result $result, array $files )
400402
$result,
401403
sprintf(
402404
/* translators: 1: directory, 2: filename */
403-
esc_html__( 'The "%1$s" directory exists, but "%2$s" is missing.', 'plugin-check' ),
405+
esc_html__( 'The "%1$s" directory using composer exists, but "%2$s" file is missing.', 'plugin-check' ),
404406
'/vendor',
405407
'composer.json'
406408
),
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Plugin Name: Test Plugin File Type Composer Files
4+
* Plugin URI: https://github.com/WordPress/plugin-check
5+
* Description: Some plugin description.
6+
* Author: WordPress Performance Team
7+
* Author URI: https://make.wordpress.org/plugins/
8+
* License: GPLv2 or later
9+
* License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10+
* Text Domain: test-plugin-file-type-composer-errors
11+
*
12+
* @package test-plugin-file-type-composer-errors
13+
*/
14+
15+
/**
16+
* Plugin folder contains a vendor folder without composer.json file.
17+
*/
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
// autoload.php @generated by Composer

tests/phpunit/tests/Checker/Checks/File_Type_Check_Tests.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,18 @@ public function test_run_with_library_core_errors() {
150150
$this->assertArrayHasKey( 0, $errors['jquery.js'][0] );
151151
$this->assertCount( 1, wp_list_filter( $errors['jquery.js'][0][0], array( 'code' => 'library_core_files' ) ) );
152152
}
153+
154+
public function test_run_with_composer_errors() {
155+
$check_context = new Check_Context( UNIT_TESTS_PLUGIN_DIR . 'test-plugin-file-type-composer-errors/load.php' );
156+
$check_result = new Check_Result( $check_context );
157+
158+
$check = new File_Type_Check( File_Type_Check::TYPE_COMPOSER );
159+
$check->run( $check_result );
160+
161+
$warnings = $check_result->get_warnings();
162+
163+
$this->assertNotEmpty( $warnings );
164+
165+
$this->assertCount( 1, wp_list_filter( $warnings['composer.json'][0][0], array( 'code' => 'missing_composer_json_file' ) ) );
166+
}
153167
}

0 commit comments

Comments
 (0)