Skip to content

Commit

Permalink
Merge pull request #2223 from WordPress/feature/test-improve-code-cov…
Browse files Browse the repository at this point in the history
…erage

Tests: improve code coverage
  • Loading branch information
dingo-d committed Apr 17, 2023
2 parents c901b74 + c250289 commit f3dac10
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@ $mode = ( $a->prop = 'on' ) ? 'on' : 'off'; // Bad.

// Safeguard recognition of PHP 7.4+ null coalesce equals.
$mode = ( $a ??= 'on' ) ? 'on' : 'off';

// Live coding/parse error.
// This has to be the last test in the file.
$var = $a = $foo ) ? 'on' : 'off';
8 changes: 8 additions & 0 deletions WordPress/Tests/DB/PreparedSQLUnitTest.1.inc
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,13 @@ $wpdb->query( $wpdb->prepare( 'SELECT * FROM ' . $notwpdb?->posts . " WHERE post
$wpdb->query( "SELECT * FROM $wpdb->posts WHERE value = " . 10_000 . ";" ); // OK.
$wpdb->query( "SELECT * FROM $wpdb->posts WHERE value = " . 0o34 . ";" ); // OK.

// Not a method call.
$wpdb = new WPDB();
$foo = $wpdb->propertyAccess;
echo $wpdb::CONSTANT_NAME;

// Not an identifyable method call.
$wpdb->{$methodName}('query');

// Don't throw an error during live coding.
wpdb::prepare( "SELECT * FROM $wpdb->posts
4 changes: 4 additions & 0 deletions WordPress/Tests/DB/PreparedSQLUnitTest.2.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ $wpdb->query( <<<EOT
WHERE ID = {$foo};
EOT
); // Bad.

// Live coding.
// This needs to be the last test in a file.
$wpdb->
1 change: 1 addition & 0 deletions WordPress/Tests/Files/FileNameUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ final class FileNameUnitTest extends AbstractSniffUnitTest {
'partial-file-disable.inc' => 1,
'rule-disable.inc' => 0,
'wordpress-disable.inc' => 0,
'disable-non-matching-enable.inc' => 0,

/*
* In /FileNameUnitTests/TestFiles.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
/**
* @phpcs:disable WordPress
*/

class My_Class {}

// phpcs:enable PSR2

// phpcs:enable WordPress.Category

// phpcs:enable WordPress.Files.NotFileNameSniff
3 changes: 3 additions & 0 deletions WordPress/Tests/WP/CapitalPDangitUnitTest.1.inc
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,6 @@ enum My_Wordpress_Enum {} // Bad.
*/
namespace My\Class\WordPress;
echo Some\Enum\WordPress::ENUM_CONSTANT;

// Safeguard that the sniff doesn't act on anonymous classes.
$anon = new class() {};
3 changes: 3 additions & 0 deletions WordPress/Tests/WP/CapitalPDangitUnitTest.1.inc.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,6 @@ enum My_Wordpress_Enum {} // Bad.
*/
namespace My\Class\WordPress;
echo Some\Enum\WordPress::ENUM_CONSTANT;

// Safeguard that the sniff doesn't act on anonymous classes.
$anon = new class() {};
3 changes: 3 additions & 0 deletions WordPress/Tests/WP/DeprecatedParameterValuesUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,6 @@ get_option(default: $default, option: 'comment_whitelist');
update_option('blacklist_keys', $value);
update_option('comment_whitelist', $value);
update_option(autoload: true, value: $value, option: 'blacklist_keys');

// Live coding/parse error.
get_bloginfo( show: /*to do*/, );

0 comments on commit f3dac10

Please sign in to comment.