From a139c8cbf70045be40ef2871cc5b2f9244fb8a53 Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Sat, 12 Jan 2019 06:05:55 +0000 Subject: [PATCH] Coding Standards: Fix and whitelist variable names. From the `WordPress.NamingConventions.ValidVariableName` sniff, this commit fixes/whitelists all `NotSnakeCaseMemberVar`, `MemberNotSnakeCase`, and `StringNotSnakeCase` violations. It also fixes a handful of the `NotSnakeCase` violations. See #45934. git-svn-id: https://develop.svn.wordpress.org/trunk@44573 602fd350-edb4-49c9-b593-d223f7449a82 --- phpcs.xml.dist | 54 ++++ src/wp-includes/class-wp-comment-query.php | 24 +- tests/phpunit/tests/avatar.php | 28 +- tests/phpunit/tests/functions.php | 4 +- tests/phpunit/tests/general/wpError.php | 322 ++++++++++----------- tests/phpunit/tests/http/base.php | 8 +- tests/phpunit/tests/http/curl.php | 2 +- tests/phpunit/tests/user.php | 2 + 8 files changed, 250 insertions(+), 194 deletions(-) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index ec6e8e3b28..e157c03ac5 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -11,6 +11,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/wp-includes/class-wp-comment-query.php b/src/wp-includes/class-wp-comment-query.php index 95ab3a6b35..dbf005c8fa 100644 --- a/src/wp-includes/class-wp-comment-query.php +++ b/src/wp-includes/class-wp-comment-query.php @@ -555,7 +555,7 @@ class WP_Comment_Query { preg_split( '/[,\s]/', $this->query_vars['orderby'] ); $orderby_array = array(); - $found_orderby_comment_ID = false; + $found_orderby_comment_id = false; foreach ( $ordersby as $_key => $_value ) { if ( ! $_value ) { continue; @@ -569,8 +569,8 @@ class WP_Comment_Query { $_order = $_value; } - if ( ! $found_orderby_comment_ID && in_array( $_orderby, array( 'comment_ID', 'comment__in' ) ) ) { - $found_orderby_comment_ID = true; + if ( ! $found_orderby_comment_id && in_array( $_orderby, array( 'comment_ID', 'comment__in' ) ) ) { + $found_orderby_comment_id = true; } $parsed = $this->parse_orderby( $_orderby ); @@ -593,24 +593,24 @@ class WP_Comment_Query { } // To ensure determinate sorting, always include a comment_ID clause. - if ( ! $found_orderby_comment_ID ) { - $comment_ID_order = ''; + if ( ! $found_orderby_comment_id ) { + $comment_id_order = ''; // Inherit order from comment_date or comment_date_gmt, if available. foreach ( $orderby_array as $orderby_clause ) { if ( preg_match( '/comment_date(?:_gmt)*\ (ASC|DESC)/', $orderby_clause, $match ) ) { - $comment_ID_order = $match[1]; + $comment_id_order = $match[1]; break; } } // If no date-related order is available, use the date from the first available clause. - if ( ! $comment_ID_order ) { + if ( ! $comment_id_order ) { foreach ( $orderby_array as $orderby_clause ) { if ( false !== strpos( 'ASC', $orderby_clause ) ) { - $comment_ID_order = 'ASC'; + $comment_id_order = 'ASC'; } else { - $comment_ID_order = 'DESC'; + $comment_id_order = 'DESC'; } break; @@ -618,11 +618,11 @@ class WP_Comment_Query { } // Default to DESC. - if ( ! $comment_ID_order ) { - $comment_ID_order = 'DESC'; + if ( ! $comment_id_order ) { + $comment_id_order = 'DESC'; } - $orderby_array[] = "$wpdb->comments.comment_ID $comment_ID_order"; + $orderby_array[] = "$wpdb->comments.comment_ID $comment_id_order"; } $orderby = implode( ', ', $orderby_array ); diff --git a/tests/phpunit/tests/avatar.php b/tests/phpunit/tests/avatar.php index 3722f6ec1f..898c30f296 100644 --- a/tests/phpunit/tests/avatar.php +++ b/tests/phpunit/tests/avatar.php @@ -103,21 +103,21 @@ class Tests_Avatar extends WP_UnitTestCase { $this->assertEquals( $url, $url2 ); } - protected $fakeURL; + protected $fake_url; /** * @ticket 21195 */ public function test_pre_get_avatar_url_filter() { - $this->fakeURL = 'haha wat'; + $this->fake_url = 'haha wat'; add_filter( 'pre_get_avatar_data', array( $this, 'pre_get_avatar_url_filter' ), 10, 1 ); $url = get_avatar_url( 1 ); remove_filter( 'pre_get_avatar_data', array( $this, 'pre_get_avatar_url_filter' ), 10 ); - $this->assertEquals( $url, $this->fakeURL ); + $this->assertEquals( $url, $this->fake_url ); } public function pre_get_avatar_url_filter( $args ) { - $args['url'] = $this->fakeURL; + $args['url'] = $this->fake_url; return $args; } @@ -125,16 +125,16 @@ class Tests_Avatar extends WP_UnitTestCase { * @ticket 21195 */ public function test_get_avatar_url_filter() { - $this->fakeURL = 'omg lol'; + $this->fake_url = 'omg lol'; add_filter( 'get_avatar_url', array( $this, 'get_avatar_url_filter' ), 10, 1 ); $url = get_avatar_url( 1 ); remove_filter( 'get_avatar_url', array( $this, 'get_avatar_url_filter' ), 10 ); - $this->assertEquals( $url, $this->fakeURL ); + $this->assertEquals( $url, $this->fake_url ); } public function get_avatar_url_filter( $url ) { - return $this->fakeURL; + return $this->fake_url; } /** @@ -207,37 +207,37 @@ class Tests_Avatar extends WP_UnitTestCase { } - protected $fakeIMG; + protected $fake_img; /** * @ticket 21195 */ public function test_pre_get_avatar_filter() { - $this->fakeIMG = 'YOU TOO?!'; + $this->fake_img = 'YOU TOO?!'; add_filter( 'pre_get_avatar', array( $this, 'pre_get_avatar_filter' ), 10, 1 ); $img = get_avatar( 1 ); remove_filter( 'pre_get_avatar', array( $this, 'pre_get_avatar_filter' ), 10 ); - $this->assertEquals( $img, $this->fakeIMG ); + $this->assertEquals( $img, $this->fake_img ); } public function pre_get_avatar_filter( $img ) { - return $this->fakeIMG; + return $this->fake_img; } /** * @ticket 21195 */ public function test_get_avatar_filter() { - $this->fakeURL = 'YA RLY'; + $this->fake_url = 'YA RLY'; add_filter( 'get_avatar', array( $this, 'get_avatar_filter' ), 10, 1 ); $img = get_avatar( 1 ); remove_filter( 'get_avatar', array( $this, 'get_avatar_filter' ), 10 ); - $this->assertEquals( $img, $this->fakeURL ); + $this->assertEquals( $img, $this->fake_url ); } public function get_avatar_filter( $img ) { - return $this->fakeURL; + return $this->fake_url; } /** diff --git a/tests/phpunit/tests/functions.php b/tests/phpunit/tests/functions.php index 7dcea34533..453d3c8ad8 100644 --- a/tests/phpunit/tests/functions.php +++ b/tests/phpunit/tests/functions.php @@ -7,7 +7,7 @@ class Tests_Functions extends WP_UnitTestCase { function test_wp_parse_args_object() { $x = new MockClass; $x->_baba = 5; - $x->yZ = 'baba'; + $x->yZ = 'baba'; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar $x->a = array( 5, 111, 'x' ); $this->assertEquals( array( @@ -43,7 +43,7 @@ class Tests_Functions extends WP_UnitTestCase { function test_wp_parse_args_defaults() { $x = new MockClass; $x->_baba = 5; - $x->yZ = 'baba'; + $x->yZ = 'baba'; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar $x->a = array( 5, 111, 'x' ); $d = array( 'pu' => 'bu' ); $this->assertEquals( diff --git a/tests/phpunit/tests/general/wpError.php b/tests/phpunit/tests/general/wpError.php index dde4baad8c..3fccc470c8 100644 --- a/tests/phpunit/tests/general/wpError.php +++ b/tests/phpunit/tests/general/wpError.php @@ -14,7 +14,7 @@ class Tests_WP_Error extends WP_UnitTestCase { * * @var WP_Error */ - public $WP_Error; + public $wp_error; /** * Set up. @@ -22,27 +22,27 @@ class Tests_WP_Error extends WP_UnitTestCase { public function setUp() { parent::setUp(); - $this->WP_Error = new WP_Error(); + $this->wp_error = new WP_Error(); } public function test_WP_Error_should_be_of_type_WP_Error() { - $this->assertWPError( $this->WP_Error ); + $this->assertWPError( $this->wp_error ); } public function test_WP_Error_with_default_empty_parameters_should_add_no_errors() { - $this->assertEmpty( $this->WP_Error->errors ); + $this->assertEmpty( $this->wp_error->errors ); } public function test_WP_Error_with_empty_code_should_add_no_code() { - $this->assertSame( '', $this->WP_Error->get_error_code() ); + $this->assertSame( '', $this->wp_error->get_error_code() ); } public function test_WP_Error_with_empty_code_should_add_no_message() { - $this->assertSame( '', $this->WP_Error->get_error_message() ); + $this->assertSame( '', $this->wp_error->get_error_message() ); } public function test_WP_Error_with_empty_code_should_add_no_error_data() { - $this->assertEmpty( $this->WP_Error->error_data ); + $this->assertEmpty( $this->wp_error->error_data ); } public function test_WP_Error_with_code_and_empty_message_should_add_error_with_that_code() { @@ -103,195 +103,195 @@ class Tests_WP_Error extends WP_UnitTestCase { * @covers ::get_error_codes() */ public function test_get_error_codes_with_no_errors_should_return_empty_array() { - $this->assertEmpty( $this->WP_Error->get_error_codes() ); + $this->assertEmpty( $this->wp_error->get_error_codes() ); } /** * @covers ::get_error_codes() */ public function test_get_error_codes_with_one_error_should_return_an_array_with_only_that_code() { - $this->WP_Error->add( 'code', 'message' ); + $this->wp_error->add( 'code', 'message' ); - $this->assertEqualSets( array( 'code' ), $this->WP_Error->get_error_codes() ); + $this->assertEqualSets( array( 'code' ), $this->wp_error->get_error_codes() ); } /** * @covers ::get_error_codes() */ public function test_get_error_codes_with_multiple_errors_should_return_an_array_of_those_codes() { - $this->WP_Error->add( 'code', 'message' ); - $this->WP_Error->add( 'code2', 'message2' ); + $this->wp_error->add( 'code', 'message' ); + $this->wp_error->add( 'code2', 'message2' ); $expected = array( 'code', 'code2' ); - $this->assertEqualSets( $expected, $this->WP_Error->get_error_codes() ); + $this->assertEqualSets( $expected, $this->wp_error->get_error_codes() ); } /** * @covers ::get_error_code() */ public function test_get_error_code_with_no_errors_should_return_an_empty_string() { - $this->assertSame( '', $this->WP_Error->get_error_code() ); + $this->assertSame( '', $this->wp_error->get_error_code() ); } /** * @covers ::get_error_code() */ public function test_get_error_code_with_one_error_should_return_that_error_code() { - $this->WP_Error->add( 'code', 'message' ); + $this->wp_error->add( 'code', 'message' ); - $this->assertSame( 'code', $this->WP_Error->get_error_code() ); + $this->assertSame( 'code', $this->wp_error->get_error_code() ); } /** * @covers ::get_error_code() */ public function test_get_error_code_with_multiple_errors_should_return_only_the_first_error_code() { - $this->WP_Error->add( 'code', 'message' ); - $this->WP_Error->add( 'code2', 'message2' ); + $this->wp_error->add( 'code', 'message' ); + $this->wp_error->add( 'code2', 'message2' ); - $this->assertSame( 'code', $this->WP_Error->get_error_code() ); + $this->assertSame( 'code', $this->wp_error->get_error_code() ); } /** * @covers ::get_error_messages() */ public function test_get_error_messages_with_empty_code_and_no_errors_should_return_an_empty_array() { - $this->assertEmpty( $this->WP_Error->get_error_messages() ); + $this->assertEmpty( $this->wp_error->get_error_messages() ); } /** * @covers ::get_error_messages() */ public function test_get_error_messages_with_empty_code_one_error_should_return_an_array_with_that_message() { - $this->WP_Error->add( 'code', 'message' ); + $this->wp_error->add( 'code', 'message' ); - $this->assertEqualSets( array( 'message' ), $this->WP_Error->get_error_messages() ); + $this->assertEqualSets( array( 'message' ), $this->wp_error->get_error_messages() ); } /** * @covers ::get_error_messages() */ public function test_get_error_messages_with_empty_code_multiple_errors_should_return_an_array_of_messages() { - $this->WP_Error->add( 'code', 'message' ); - $this->WP_Error->add( 'code2', 'message2' ); + $this->wp_error->add( 'code', 'message' ); + $this->wp_error->add( 'code2', 'message2' ); - $this->assertEqualSets( array( 'message', 'message2' ), $this->WP_Error->get_error_messages() ); + $this->assertEqualSets( array( 'message', 'message2' ), $this->wp_error->get_error_messages() ); } /** * @covers ::get_error_messages() */ public function test_get_error_messages_with_an_invalid_code_should_return_an_empty_array() { - $this->assertEmpty( $this->WP_Error->get_error_messages( 'code' ) ); + $this->assertEmpty( $this->wp_error->get_error_messages( 'code' ) ); } /** * @covers ::get_error_messages() */ public function test_get_error_messages_with_one_error_should_return_an_array_with_that_message() { - $this->WP_Error->add( 'code', 'message' ); + $this->wp_error->add( 'code', 'message' ); - $this->assertEqualSets( array( 'message' ), $this->WP_Error->get_error_messages( 'code' ) ); + $this->assertEqualSets( array( 'message' ), $this->wp_error->get_error_messages( 'code' ) ); } /** * @covers ::get_error_messages() */ public function test_get_error_messages_with_multiple_errors_same_code_should_return_an_array_with_all_messages() { - $this->WP_Error->add( 'code', 'message' ); - $this->WP_Error->add( 'code', 'message2' ); + $this->wp_error->add( 'code', 'message' ); + $this->wp_error->add( 'code', 'message2' ); - $this->assertequalSets( array( 'message', 'message2' ), $this->WP_Error->get_error_messages( 'code' ) ); + $this->assertequalSets( array( 'message', 'message2' ), $this->wp_error->get_error_messages( 'code' ) ); } /** * @covers ::get_error_message() */ public function test_get_error_message_with_empty_code_and_no_errors_should_return_an_empty_string() { - $this->assertSame( '', $this->WP_Error->get_error_message() ); + $this->assertSame( '', $this->wp_error->get_error_message() ); } /** * @covers ::get_error_message() */ public function test_get_error_message_with_empty_code_and_one_error_should_return_that_message() { - $this->WP_Error->add( 'code', 'message' ); + $this->wp_error->add( 'code', 'message' ); - $this->assertSame( 'message', $this->WP_Error->get_error_message() ); + $this->assertSame( 'message', $this->wp_error->get_error_message() ); } /** * @covers ::get_error_message() */ public function test_get_error_message_with_empty_code_and_multiple_errors_should_return_the_first_message() { - $this->WP_Error->add( 'code', 'message' ); - $this->WP_Error->add( 'code2', 'message2' ); + $this->wp_error->add( 'code', 'message' ); + $this->wp_error->add( 'code2', 'message2' ); - $this->assertSame( 'message', $this->WP_Error->get_error_message() ); + $this->assertSame( 'message', $this->wp_error->get_error_message() ); } /** * @covers ::get_error_message() */ public function test_get_error_message_with_empty_code_and_multiple_errors_multiple_codes_should_return_the_first_message() { - $this->WP_Error->add( 'code', 'message' ); - $this->WP_Error->add( 'code2', 'message2' ); - $this->WP_Error->add( 'code', 'message2' ); + $this->wp_error->add( 'code', 'message' ); + $this->wp_error->add( 'code2', 'message2' ); + $this->wp_error->add( 'code', 'message2' ); - $this->assertSame( 'message', $this->WP_Error->get_error_message() ); + $this->assertSame( 'message', $this->wp_error->get_error_message() ); } /** * @covers ::get_error_message() */ public function test_get_error_message_with_invalid_code_and_no_errors_should_return_empty_string() { - $this->assertSame( '', $this->WP_Error->get_error_message( 'invalid' ) ); + $this->assertSame( '', $this->wp_error->get_error_message( 'invalid' ) ); } /** * @covers ::get_error_message() */ public function test_get_error_message_with_invalid_code_and_one_error_should_return_an_empty_string() { - $this->WP_Error->add( 'code', 'message' ); + $this->wp_error->add( 'code', 'message' ); - $this->assertSame( '', $this->WP_Error->get_error_message( 'invalid' ) ); + $this->assertSame( '', $this->wp_error->get_error_message( 'invalid' ) ); } /** * @covers ::get_error_message() */ public function test_get_error_message_with_invalid_code_and_multiple_errors_should_return_an_empty_string() { - $this->WP_Error->add( 'code', 'message' ); - $this->WP_Error->add( 'code2', 'message2' ); + $this->wp_error->add( 'code', 'message' ); + $this->wp_error->add( 'code2', 'message2' ); - $this->assertSame( '', $this->WP_Error->get_error_message( 'invalid' ) ); + $this->assertSame( '', $this->wp_error->get_error_message( 'invalid' ) ); } /** * @covers ::get_error_data() */ public function test_get_error_data_with_empty_code_and_no_errors_should_evaluate_as_null() { - $this->assertSame( null, $this->WP_Error->get_error_data() ); + $this->assertSame( null, $this->wp_error->get_error_data() ); } /** * @covers ::get_error_data() */ public function test_get_error_data_with_empty_code_one_error_no_data_should_evaluate_as_null() { - $this->WP_Error->add( 'code', 'message' ); + $this->wp_error->add( 'code', 'message' ); - $this->assertSame( null, $this->WP_Error->get_error_data() ); + $this->assertSame( null, $this->wp_error->get_error_data() ); } /** * @covers ::get_error_data() */ public function test_get_error_data_with_empty_code_multiple_errors_no_data_should_evaluate_as_null() { - $this->WP_Error->add( 'code', 'message' ); - $this->WP_Error->add( 'code2', 'message2' ); + $this->wp_error->add( 'code', 'message' ); + $this->wp_error->add( 'code2', 'message2' ); - $this->assertSame( null, $this->WP_Error->get_error_data() ); + $this->assertSame( null, $this->wp_error->get_error_data() ); } /** @@ -299,9 +299,9 @@ class Tests_WP_Error extends WP_UnitTestCase { */ public function test_get_error_data_with_empty_code_and_one_error_with_data_should_return_that_data() { $expected = array( 'data-key' => 'data-value' ); - $this->WP_Error->add( 'code', 'message', $expected ); + $this->wp_error->add( 'code', 'message', $expected ); - $this->assertEqualSetsWithIndex( $expected, $this->WP_Error->get_error_data() ); + $this->assertEqualSetsWithIndex( $expected, $this->wp_error->get_error_data() ); } /** @@ -309,37 +309,37 @@ class Tests_WP_Error extends WP_UnitTestCase { */ public function test_get_error_data_with_empty_code_and_multiple_errors_different_codes_should_return_the_last_data_of_the_first_code() { $expected = array( 'data-key' => 'data-value' ); - $this->WP_Error->add( 'code', 'message', $expected ); - $this->WP_Error->add( 'code2', 'message2', 'data2' ); + $this->wp_error->add( 'code', 'message', $expected ); + $this->wp_error->add( 'code2', 'message2', 'data2' ); - $this->assertEqualSetsWithIndex( $expected, $this->WP_Error->get_error_data() ); + $this->assertEqualSetsWithIndex( $expected, $this->wp_error->get_error_data() ); } /** * @covers ::get_error_data() */ public function test_get_error_data_with_empty_code_and_multiple_errors_same_code_should_return_the_last_data_of_the_first_code() { - $this->WP_Error->add( 'code', 'message', 'data' ); - $this->WP_Error->add( 'code', 'message2', 'data2' ); - $this->WP_Error->add( 'code2', 'message2', 'data3' ); + $this->wp_error->add( 'code', 'message', 'data' ); + $this->wp_error->add( 'code', 'message2', 'data2' ); + $this->wp_error->add( 'code2', 'message2', 'data3' ); - $this->assertSame( 'data2', $this->WP_Error->get_error_data() ); + $this->assertSame( 'data2', $this->wp_error->get_error_data() ); } /** * @covers ::get_error_data() */ public function test_get_error_data_with_code_and_no_errors_should_evaluate_as_null() { - $this->assertSame( null, $this->WP_Error->get_error_data( 'code' ) ); + $this->assertSame( null, $this->wp_error->get_error_data( 'code' ) ); } /** * @covers ::get_error_data() */ public function test_get_error_data_with_code_and_one_error_with_no_data_should_evaluate_as_null() { - $this->WP_Error->add( 'code', 'message' ); + $this->wp_error->add( 'code', 'message' ); - $this->assertSame( null, $this->WP_Error->get_error_data( 'code' ) ); + $this->assertSame( null, $this->wp_error->get_error_data( 'code' ) ); } /** @@ -347,9 +347,9 @@ class Tests_WP_Error extends WP_UnitTestCase { */ public function test_get_error_data_with_code_and_one_error_with_data_should_return_that_data() { $expected = array( 'data-key' => 'data-value' ); - $this->WP_Error->add( 'code', 'message', $expected ); + $this->wp_error->add( 'code', 'message', $expected ); - $this->assertEqualSetsWithIndex( $expected, $this->WP_Error->get_error_data( 'code' ) ); + $this->assertEqualSetsWithIndex( $expected, $this->wp_error->get_error_data( 'code' ) ); } /** @@ -357,300 +357,300 @@ class Tests_WP_Error extends WP_UnitTestCase { */ public function test_get_error_data_with_code_and_multiple_errors_different_codes_should_return_the_last_stored_data_of_the_code() { $expected = array( 'data3' ); - $this->WP_Error->add( 'code', 'message', 'data' ); - $this->WP_Error->add( 'code2', 'message2', 'data2' ); - $this->WP_Error->add( 'code', 'message3', $expected ); + $this->wp_error->add( 'code', 'message', 'data' ); + $this->wp_error->add( 'code2', 'message2', 'data2' ); + $this->wp_error->add( 'code', 'message3', $expected ); - $this->assertEqualSetsWithIndex( $expected, $this->WP_Error->get_error_data( 'code' ) ); + $this->assertEqualSetsWithIndex( $expected, $this->wp_error->get_error_data( 'code' ) ); } /** * @covers ::get_error_data() */ public function test_get_error_data_with_code_and_multiple_errors_same_code_should_return_the_last_stored_data() { - $this->WP_Error->add( 'code', 'message', 'data' ); - $this->WP_Error->add( 'code', 'message2', 'data2' ); - $this->WP_Error->add( 'code2', 'message3', 'data3' ); + $this->wp_error->add( 'code', 'message', 'data' ); + $this->wp_error->add( 'code', 'message2', 'data2' ); + $this->wp_error->add( 'code2', 'message3', 'data3' ); - $this->assertSame( 'data2', $this->WP_Error->get_error_data( 'code' ) ); + $this->assertSame( 'data2', $this->wp_error->get_error_data( 'code' ) ); } /** * @covers ::has_errors() */ public function test_has_errors_with_no_errors_returns_false() { - $this->assertFalse( $this->WP_Error->has_errors() ); + $this->assertFalse( $this->wp_error->has_errors() ); } /** * @covers ::has_errors() */ public function test_has_errors_with_errors_returns_true() { - $this->WP_Error->add( 'code', 'message', 'data' ); - $this->assertTrue( $this->WP_Error->has_errors() ); + $this->wp_error->add( 'code', 'message', 'data' ); + $this->assertTrue( $this->wp_error->has_errors() ); } /** * @covers ::add() */ public function test_add_with_empty_code_empty_message_empty_data_should_add_empty_key_to_errors_array() { - $this->WP_Error->add( '', '', 'data' ); + $this->wp_error->add( '', '', 'data' ); - $this->assertArrayHasKey( '', $this->WP_Error->errors ); + $this->assertArrayHasKey( '', $this->wp_error->errors ); } /** * @covers ::add() */ public function test_add_with_empty_code_empty_message_empty_data_should_add_empty_message_to_errors_array_under_empty_key() { - $this->WP_Error->add( '', '', 'data' ); + $this->wp_error->add( '', '', 'data' ); - $this->assertEqualSetsWithIndex( array( '' => array( '' ) ), $this->WP_Error->errors ); + $this->assertEqualSetsWithIndex( array( '' => array( '' ) ), $this->wp_error->errors ); } /** * @covers ::add() */ public function test_add_with_empty_code_empty_message_empty_data_should_not_alter_data() { - $this->WP_Error->add( '', '', '' ); + $this->wp_error->add( '', '', '' ); - $this->assertEmpty( $this->WP_Error->error_data ); + $this->assertEmpty( $this->wp_error->error_data ); } /** * @covers ::add() */ public function test_add_with_empty_code_empty_message_non_empty_data_should_store_data_under_an_empty_code_key() { - $this->WP_Error->add( '', '', 'data' ); + $this->wp_error->add( '', '', 'data' ); - $this->assertEqualSetsWithIndex( array( '' => 'data' ), $this->WP_Error->error_data ); + $this->assertEqualSetsWithIndex( array( '' => 'data' ), $this->wp_error->error_data ); } /** * @covers ::add() */ public function test_add_with_code_empty_message_empty_data_should_add_error_with_code() { - $this->WP_Error->add( 'code', '' ); + $this->wp_error->add( 'code', '' ); - $this->assertSame( 'code', $this->WP_Error->get_error_code() ); + $this->assertSame( 'code', $this->wp_error->get_error_code() ); } /** * @covers ::add() */ public function test_add_with_code_empty_message_empty_data_should_add_error_with_empty_message() { - $this->WP_Error->add( 'code', '' ); + $this->wp_error->add( 'code', '' ); - $this->assertSame( '', $this->WP_Error->get_error_message( 'code' ) ); + $this->assertSame( '', $this->wp_error->get_error_message( 'code' ) ); } /** * @covers ::add() */ public function test_add_with_code_empty_message_empty_data_should_not_add_error_data() { - $this->WP_Error->add( 'code', '' ); + $this->wp_error->add( 'code', '' ); - $this->assertSame( null, $this->WP_Error->get_error_data( 'code' ) ); + $this->assertSame( null, $this->wp_error->get_error_data( 'code' ) ); } /** * @covers ::add() */ public function test_add_with_code_and_message_and_empty_data_should_should_add_error_with_that_message() { - $this->WP_Error->add( 'code', 'message' ); + $this->wp_error->add( 'code', 'message' ); - $this->assertSame( 'message', $this->WP_Error->get_error_message( 'code' ) ); + $this->assertSame( 'message', $this->wp_error->get_error_message( 'code' ) ); } /** * @covers ::add() */ public function test_add_with_code_and_message_and_empty_data_should_not_alter_stored_data() { - $this->WP_Error->add( 'code', 'message' ); + $this->wp_error->add( 'code', 'message' ); - $this->assertSame( null, $this->WP_Error->get_error_data( 'code' ) ); + $this->assertSame( null, $this->wp_error->get_error_data( 'code' ) ); } /** * @covers ::add() */ public function test_add_with_code_and_empty_message_and_data_should_add_error_with_that_code() { - $this->WP_Error->add( 'code', '', 'data' ); + $this->wp_error->add( 'code', '', 'data' ); - $this->assertSame( 'code', $this->WP_Error->get_error_code() ); + $this->assertSame( 'code', $this->wp_error->get_error_code() ); } /** * @covers ::add() */ public function test_add_with_code_and_empty_message_and_data_should_store_that_data() { - $this->WP_Error->add( 'code', '', 'data' ); + $this->wp_error->add( 'code', '', 'data' ); - $this->assertSame( 'data', $this->WP_Error->get_error_data( 'code' ) ); + $this->assertSame( 'data', $this->wp_error->get_error_data( 'code' ) ); } /** * @covers ::add() */ public function test_add_with_code_and_message_and_data_should_add_an_error_with_that_code() { - $this->WP_Error->add( 'code', 'message', 'data' ); + $this->wp_error->add( 'code', 'message', 'data' ); - $this->assertSame( 'code', $this->WP_Error->get_error_code() ); + $this->assertSame( 'code', $this->wp_error->get_error_code() ); } /** * @covers ::add() */ public function test_add_with_code_and_message_and_data_should_add_an_error_with_that_message() { - $this->WP_Error->add( 'code', 'message', 'data' ); + $this->wp_error->add( 'code', 'message', 'data' ); - $this->assertSame( 'message', $this->WP_Error->get_error_message( 'code' ) ); + $this->assertSame( 'message', $this->wp_error->get_error_message( 'code' ) ); } /** * @covers ::add() */ public function test_add_with_code_and_message_and_data_should_store_that_data() { - $this->WP_Error->add( 'code', 'message', 'data' ); + $this->wp_error->add( 'code', 'message', 'data' ); - $this->assertSame( 'data', $this->WP_Error->get_error_data( 'code' ) ); + $this->assertSame( 'data', $this->wp_error->get_error_data( 'code' ) ); } /** * @covers ::add() */ public function test_add_multiple_times_with_the_same_code_should_add_additional_messages_for_that_code() { - $this->WP_Error->add( 'code', 'message' ); - $this->WP_Error->add( 'code', 'message2' ); + $this->wp_error->add( 'code', 'message' ); + $this->wp_error->add( 'code', 'message2' ); $expected = array( 'message', 'message2' ); - $this->assertEqualSets( $expected, $this->WP_Error->get_error_messages( 'code' ) ); + $this->assertEqualSets( $expected, $this->wp_error->get_error_messages( 'code' ) ); } /** * @covers ::add() */ public function test_add_multiple_times_with_the_same_code_and_different_data_should_store_only_the_last_added_data() { - $this->WP_Error->add( 'code', 'message', 'data-bar' ); - $this->WP_Error->add( 'code', 'message2', 'data-baz' ); + $this->wp_error->add( 'code', 'message', 'data-bar' ); + $this->wp_error->add( 'code', 'message2', 'data-baz' ); - $this->assertSame( 'data-baz', $this->WP_Error->get_error_data( 'code' ) ); + $this->assertSame( 'data-baz', $this->wp_error->get_error_data( 'code' ) ); } /** * @covers ::add_data() */ public function test_add_data_with_empty_data_empty_code_should_create_orphaned_data_with_no_error() { - $this->WP_Error->add_data( '' ); + $this->wp_error->add_data( '' ); - $this->assertEmpty( $this->WP_Error->errors ); + $this->assertEmpty( $this->wp_error->errors ); } /** * @covers ::add_data() */ public function test_add_data_with_empty_data_empty_code_no_errors_should_create_data_under_an_empty_code_key() { - $this->WP_Error->add_data( '' ); + $this->wp_error->add_data( '' ); - $this->assertEqualSets( array( '' => '' ), $this->WP_Error->error_data ); + $this->assertEqualSets( array( '' => '' ), $this->wp_error->error_data ); } /** * @covers ::add_data() */ public function test_add_data_with_data_empty_code_and_one_error_should_store_the_data_under_that_code() { - $this->WP_Error->add( 'code', 'message' ); - $this->WP_Error->add_data( 'data' ); + $this->wp_error->add( 'code', 'message' ); + $this->wp_error->add_data( 'data' ); - $this->assertSame( 'data', $this->WP_Error->get_error_data( 'code' ) ); + $this->assertSame( 'data', $this->wp_error->get_error_data( 'code' ) ); } /** * @covers ::add_data() */ public function test_add_data_with_data_empty_code_and_multiple_errors_with_different_codes_should_store_it_under_the_first_code() { - $this->WP_Error->add( 'code', 'message' ); - $this->WP_Error->add( 'code2', 'message2' ); + $this->wp_error->add( 'code', 'message' ); + $this->wp_error->add( 'code2', 'message2' ); - $this->WP_Error->add_data( 'data' ); + $this->wp_error->add_data( 'data' ); - $this->assertSame( 'data', $this->WP_Error->get_error_data( 'code' ) ); + $this->assertSame( 'data', $this->wp_error->get_error_data( 'code' ) ); } /** * @covers ::add_data() */ public function test_add_data_with_data_empty_code_and_multiple_errors_with_same_code_should_store_it_under_the_first_code() { - $this->WP_Error->add( 'code', 'message' ); - $this->WP_Error->add( 'code2', 'message2' ); - $this->WP_Error->add( 'code', 'message3' ); + $this->wp_error->add( 'code', 'message' ); + $this->wp_error->add( 'code2', 'message2' ); + $this->wp_error->add( 'code', 'message3' ); - $this->WP_Error->add_data( 'data' ); + $this->wp_error->add_data( 'data' ); - $this->assertSame( 'data', $this->WP_Error->get_error_data( 'code' ) ); + $this->assertSame( 'data', $this->wp_error->get_error_data( 'code' ) ); } /** * @covers ::add_data() */ public function test_add_data_with_data_and_code_and_no_errors_should_create_orphaned_data_with_no_error() { - $this->WP_Error->add_data( 'data', 'code' ); + $this->wp_error->add_data( 'data', 'code' ); - $this->assertEmpty( $this->WP_Error->errors ); + $this->assertEmpty( $this->wp_error->errors ); } /** * @covers ::add_data() */ public function test_add_data_with_data_and_code_no_errors_should_create_data_under_that_code_key() { - $this->WP_Error->add_data( 'data', 'code' ); + $this->wp_error->add_data( 'data', 'code' ); - $this->assertEqualSets( array( 'code' => 'data' ), $this->WP_Error->error_data ); + $this->assertEqualSets( array( 'code' => 'data' ), $this->wp_error->error_data ); } /** * @covers ::add_data() */ public function test_add_data_with_data_and_code_one_error_different_code_should_create_orphaned_data_with_no_error() { - $this->WP_Error->add( 'code', 'message' ); + $this->wp_error->add( 'code', 'message' ); - $this->WP_Error->add_data( 'data', 'code2' ); + $this->wp_error->add_data( 'data', 'code2' ); - $this->assertEqualSetsWithIndex( array( 'code' => array( 'message' ) ), $this->WP_Error->errors ); + $this->assertEqualSetsWithIndex( array( 'code' => array( 'message' ) ), $this->wp_error->errors ); } /** * @covers ::add_data() */ public function test_add_data_with_data_and_code_one_error_different_code_should_create_data_under_that_code_key() { - $this->WP_Error->add( 'code', 'message' ); + $this->wp_error->add( 'code', 'message' ); - $this->WP_Error->add_data( 'data', 'code2' ); + $this->wp_error->add_data( 'data', 'code2' ); - $this->assertEqualSetsWithIndex( array( 'code2' => 'data' ), $this->WP_Error->error_data ); + $this->assertEqualSetsWithIndex( array( 'code2' => 'data' ), $this->wp_error->error_data ); } /** * @covers ::add_data() */ public function test_add_data_with_data_and_code_should_add_data() { - $this->WP_Error->add( 'code', 'message' ); + $this->wp_error->add( 'code', 'message' ); - $this->WP_Error->add_data( 'data', 'code' ); + $this->wp_error->add_data( 'data', 'code' ); - $this->assertSame( 'data', $this->WP_Error->get_error_data( 'code' ) ); + $this->assertSame( 'data', $this->wp_error->get_error_data( 'code' ) ); } /** * @covers ::remove() */ public function test_remove_with_no_errors_should_affect_nothing() { - $before = $this->WP_Error->errors; + $before = $this->wp_error->errors; - $this->WP_Error->remove( 'code' ); + $this->wp_error->remove( 'code' ); - $after = $this->WP_Error->errors; + $after = $this->wp_error->errors; $this->assertEqualSetsWithIndex( $before, $after ); } @@ -659,11 +659,11 @@ class Tests_WP_Error extends WP_UnitTestCase { * @covers ::remove() */ public function test_remove_empty_code_no_errors_should_affect_nothing() { - $before = $this->WP_Error->errors; + $before = $this->wp_error->errors; - $this->WP_Error->remove( '' ); + $this->wp_error->remove( '' ); - $after = $this->WP_Error->errors; + $after = $this->wp_error->errors; $this->assertEqualSetsWithIndex( $before, $after ); } @@ -672,13 +672,13 @@ class Tests_WP_Error extends WP_UnitTestCase { * @covers ::remove() */ public function test_remove_empty_code_and_one_error_with_empty_string_code_should_remove_error() { - $before = $this->WP_Error->errors; + $before = $this->wp_error->errors; - $this->WP_Error->add( '', 'message' ); + $this->wp_error->add( '', 'message' ); - $this->WP_Error->remove( '' ); + $this->wp_error->remove( '' ); - $after = $this->WP_Error->errors; + $after = $this->wp_error->errors; $this->assertEqualSetsWithIndex( $before, $after ); } @@ -687,35 +687,35 @@ class Tests_WP_Error extends WP_UnitTestCase { * @covers ::remove() */ public function test_remove_empty_code_and_one_error_with_empty_string_code_should_remove_error_data() { - $this->WP_Error->add( '', 'message', 'data' ); + $this->wp_error->add( '', 'message', 'data' ); - $this->WP_Error->remove( '' ); + $this->wp_error->remove( '' ); - $after = $this->WP_Error->error_data; + $after = $this->wp_error->error_data; - $this->assertEmpty( $this->WP_Error->error_data ); + $this->assertEmpty( $this->wp_error->error_data ); } /** * @covers ::remove() */ public function test_remove_should_remove_the_error_with_the_given_code() { - $this->WP_Error->add( 'code', 'message' ); + $this->wp_error->add( 'code', 'message' ); - $this->WP_Error->remove( 'code' ); + $this->wp_error->remove( 'code' ); - $this->assertEmpty( $this->WP_Error->errors ); + $this->assertEmpty( $this->wp_error->errors ); } /** * @covers ::remove() */ public function test_remove_should_remove_the_error_data_associated_with_the_given_code() { - $this->WP_Error->add( 'code', 'message', 'data' ); + $this->wp_error->add( 'code', 'message', 'data' ); - $this->WP_Error->remove( 'code' ); + $this->wp_error->remove( 'code' ); - $this->assertEmpty( $this->WP_Error->error_data ); + $this->assertEmpty( $this->wp_error->error_data ); } } diff --git a/tests/phpunit/tests/http/base.php b/tests/phpunit/tests/http/base.php index ad6027e58d..011870f836 100644 --- a/tests/phpunit/tests/http/base.php +++ b/tests/phpunit/tests/http/base.php @@ -13,7 +13,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { // You can use your own version of data/WPHTTP-testcase-redirection-script.php here. var $redirection_script = 'http://api.wordpress.org/core/tests/1.0/redirection.php'; - var $fileStreamUrl = 'http://s.w.org/screenshots/3.9/dashboard.png'; + var $file_stream_url = 'http://s.w.org/screenshots/3.9/dashboard.png'; protected $http_request_args; @@ -254,7 +254,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { } function test_file_stream() { - $url = $this->fileStreamUrl; + $url = $this->file_stream_url; $size = 153204; $res = wp_remote_request( $url, @@ -282,7 +282,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { * @ticket 26726 */ function test_file_stream_limited_size() { - $url = $this->fileStreamUrl; + $url = $this->file_stream_url; $size = 10000; $res = wp_remote_request( $url, @@ -311,7 +311,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { * @ticket 31172 */ function test_request_limited_size() { - $url = $this->fileStreamUrl; + $url = $this->file_stream_url; $size = 10000; $res = wp_remote_request( diff --git a/tests/phpunit/tests/http/curl.php b/tests/phpunit/tests/http/curl.php index a5b24f467a..f64cace2b7 100644 --- a/tests/phpunit/tests/http/curl.php +++ b/tests/phpunit/tests/http/curl.php @@ -15,7 +15,7 @@ class Tests_HTTP_curl extends WP_HTTP_UnitTestCase { public function test_http_api_curl_stream_parameter_is_a_reference() { add_action( 'http_api_curl', array( $this, '_action_test_http_api_curl_stream_parameter_is_a_reference' ), 10, 3 ); wp_remote_request( - $this->fileStreamUrl, + $this->file_stream_url, array( 'stream' => true, 'timeout' => 30, diff --git a/tests/phpunit/tests/user.php b/tests/phpunit/tests/user.php index 4f9fa2ba1b..c6b4d8b7e9 100644 --- a/tests/phpunit/tests/user.php +++ b/tests/phpunit/tests/user.php @@ -199,6 +199,7 @@ class Tests_User extends WP_UnitTestCase { * @ticket 20043 */ public function test_user_unset() { + // phpcs:disable WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar $user = new WP_User( self::$author_id ); // Test custom fields @@ -207,6 +208,7 @@ class Tests_User extends WP_UnitTestCase { unset( $user->customField ); $this->assertFalse( isset( $user->customField ) ); return $user; + // phpcs:enable } /**