From 3ff14a722788a1cc5db2b20fb65005914653eb0b Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Tue, 28 Feb 2023 10:14:33 -0300 Subject: [PATCH 1/2] composer update --- composer.lock | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/composer.lock b/composer.lock index 7aaf32e..1a476cf 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "a01c093b1a924ab0ba8efd6cc1ada20f", + "content-hash": "3c43372e35407116cbc96427731d3af0", "packages": [], "packages-dev": [ { @@ -13,12 +13,12 @@ "source": { "type": "git", "url": "https://github.com/10up/ElasticPress.git", - "reference": "ce6b43138066ea6d69f39def05214072a8e300da" + "reference": "4a1736bdb480175beafe8329cf36593c165156dc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/10up/ElasticPress/zipball/ce6b43138066ea6d69f39def05214072a8e300da", - "reference": "ce6b43138066ea6d69f39def05214072a8e300da", + "url": "https://api.github.com/repos/10up/ElasticPress/zipball/4a1736bdb480175beafe8329cf36593c165156dc", + "reference": "4a1736bdb480175beafe8329cf36593c165156dc", "shasum": "" }, "require": { @@ -72,7 +72,7 @@ "issues": "https://github.com/10up/ElasticPress/issues", "source": "https://github.com/10up/ElasticPress/tree/develop" }, - "time": "2023-02-20T12:38:37+00:00" + "time": "2023-02-27T20:31:25+00:00" }, { "name": "10up/phpcs-composer", @@ -80,12 +80,12 @@ "source": { "type": "git", "url": "https://github.com/10up/phpcs-composer.git", - "reference": "5f9ac994db1af9924a71b0f5663fe7f6bd59c812" + "reference": "e05d9007b332c76066ef309febea960c6dece271" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/10up/phpcs-composer/zipball/5f9ac994db1af9924a71b0f5663fe7f6bd59c812", - "reference": "5f9ac994db1af9924a71b0f5663fe7f6bd59c812", + "url": "https://api.github.com/repos/10up/phpcs-composer/zipball/e05d9007b332c76066ef309febea960c6dece271", + "reference": "e05d9007b332c76066ef309febea960c6dece271", "shasum": "" }, "require": { @@ -111,7 +111,7 @@ "issues": "https://github.com/10up/phpcs-composer/issues", "source": "https://github.com/10up/phpcs-composer/tree/master" }, - "time": "2022-11-18T18:13:03+00:00" + "time": "2023-02-24T01:59:32+00:00" }, { "name": "10up/wp_mock", @@ -147,6 +147,7 @@ "sebastian/comparator": "^4.0.8", "sempro/phpunit-pretty-print": "^1.4" }, + "default-branch": true, "type": "library", "autoload": { "psr-4": { @@ -1082,23 +1083,23 @@ }, { "name": "phpunit/php-code-coverage", - "version": "9.2.24", + "version": "9.2.25", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "2cf940ebc6355a9d430462811b5aaa308b174bed" + "reference": "0e2b40518197a8c0d4b08bc34dfff1c99c508954" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/2cf940ebc6355a9d430462811b5aaa308b174bed", - "reference": "2cf940ebc6355a9d430462811b5aaa308b174bed", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/0e2b40518197a8c0d4b08bc34dfff1c99c508954", + "reference": "0e2b40518197a8c0d4b08bc34dfff1c99c508954", "shasum": "" }, "require": { "ext-dom": "*", "ext-libxml": "*", "ext-xmlwriter": "*", - "nikic/php-parser": "^4.14", + "nikic/php-parser": "^4.15", "php": ">=7.3", "phpunit/php-file-iterator": "^3.0.3", "phpunit/php-text-template": "^2.0.2", @@ -1147,7 +1148,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.24" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.25" }, "funding": [ { @@ -1155,7 +1156,7 @@ "type": "github" } ], - "time": "2023-01-26T08:26:55+00:00" + "time": "2023-02-25T05:32:00+00:00" }, { "name": "phpunit/php-file-iterator", @@ -1400,16 +1401,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.6.3", + "version": "9.6.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "e7b1615e3e887d6c719121c6d4a44b0ab9645555" + "reference": "9125ee085b6d95e78277dc07aa1f46f9e0607b8d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/e7b1615e3e887d6c719121c6d4a44b0ab9645555", - "reference": "e7b1615e3e887d6c719121c6d4a44b0ab9645555", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/9125ee085b6d95e78277dc07aa1f46f9e0607b8d", + "reference": "9125ee085b6d95e78277dc07aa1f46f9e0607b8d", "shasum": "" }, "require": { @@ -1482,7 +1483,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.3" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.4" }, "funding": [ { @@ -1498,7 +1499,7 @@ "type": "tidelift" } ], - "time": "2023-02-04T13:37:15+00:00" + "time": "2023-02-27T13:06:37+00:00" }, { "name": "sebastian/cli-parser", From fb3c02f778b3ce1748337afd2a2464e7b7e92bc1 Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Tue, 28 Feb 2023 10:15:21 -0300 Subject: [PATCH 2/2] Lint fix tests --- tests/bootstrap.php | 2 +- .../feature/TestBooleanSearchOperators.php | 12 ++-- tests/phpunit/feature/TestCoAuthorsPlus.php | 46 ++++++------ tests/phpunit/feature/TestMetaKeyPattern.php | 70 ++++++++++++++++--- .../TestWooCommerceSubscriptionSearch.php | 8 +-- tests/phpunit/indexables/TestUser.php | 23 +----- 6 files changed, 96 insertions(+), 65 deletions(-) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 5360a50..f4a6fcd 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -112,4 +112,4 @@ function skip_translations_api() { require_once $_tests_dir . '/includes/functions.php'; require_once $_tests_dir . '/includes/bootstrap.php'; require_once __DIR__ . '/phpunit/BaseTestCase.php'; -require_once __DIR__ . '/phpunit/factory/UserFactory.php'; \ No newline at end of file +require_once __DIR__ . '/phpunit/factory/UserFactory.php'; diff --git a/tests/phpunit/feature/TestBooleanSearchOperators.php b/tests/phpunit/feature/TestBooleanSearchOperators.php index dc2fd2d..800b161 100644 --- a/tests/phpunit/feature/TestBooleanSearchOperators.php +++ b/tests/phpunit/feature/TestBooleanSearchOperators.php @@ -23,7 +23,7 @@ class TestBooleanSearchOperators extends \WP_UnitTestCase { */ public function set_up() { $instance = new ElasticPressLabs\Feature\BooleanSearchOperators(); - \ElasticPress\Features::factory()->register_feature($instance); + \ElasticPress\Features::factory()->register_feature( $instance ); } /** @@ -44,8 +44,8 @@ protected function get_feature() { public function testConstruct() { $instance = $this->get_feature(); - $this->assertEquals( 'boolean_search_operators', $instance->slug ); - $this->assertEquals( 'Boolean Search Operators', $instance->title ); + $this->assertEquals( 'boolean_search_operators', $instance->slug ); + $this->assertEquals( 'Boolean Search Operators', $instance->title ); } /** @@ -56,7 +56,7 @@ public function testConstruct() { public function testBoxSummary() { ob_start(); $this->get_feature()->output_feature_box_summary(); - $output = ob_get_clean(); + $output = ob_get_clean(); $this->assertStringContainsString( 'Allow boolean operators in search queries', $output ); } @@ -69,7 +69,7 @@ public function testBoxSummary() { public function testBoxLong() { ob_start(); $this->get_feature()->output_feature_box_long(); - $output = ob_get_clean(); + $output = ob_get_clean(); $this->assertStringContainsString( 'Allows users to search using the following boolean operators:', $output ); } @@ -80,7 +80,7 @@ public function testBoxLong() { * @since 1.2.0 */ public function testQueryUsesBooleanOperators() { - $feature = $this->get_feature(); + $feature = $this->get_feature(); $this->assertTrue( $feature->query_uses_boolean_operators( '(museum (art))' ) ); $this->assertTrue( $feature->query_uses_boolean_operators( '"american museum"' ) ); diff --git a/tests/phpunit/feature/TestCoAuthorsPlus.php b/tests/phpunit/feature/TestCoAuthorsPlus.php index 6b77247..bc7bd8f 100644 --- a/tests/phpunit/feature/TestCoAuthorsPlus.php +++ b/tests/phpunit/feature/TestCoAuthorsPlus.php @@ -23,7 +23,7 @@ class TestCoAuthorsPlus extends \WP_UnitTestCase { */ public function set_up() { $instance = new ElasticPressLabs\Feature\CoAuthorsPlus(); - \ElasticPress\Features::factory()->register_feature($instance); + \ElasticPress\Features::factory()->register_feature( $instance ); } /** @@ -40,13 +40,13 @@ protected function get_feature() { * Get protected function as public * * @since 1.1.0 - * @param string $functionName - * @param string $className + * @param string $function_name Function name + * @param string $class_name Class name * @return ReflectionClass */ - protected function get_protected_function( $functionName, $className = 'ElasticPressLabs\Feature\CoAuthorsPlus' ) { - $reflector = new \ReflectionClass( $className ); - $function = $reflector->getMethod( $functionName ); + protected function get_protected_function( $function_name, $class_name = 'ElasticPressLabs\Feature\CoAuthorsPlus' ) { + $reflector = new \ReflectionClass( $class_name ); + $function = $reflector->getMethod( $function_name ); $function->setAccessible( true ); return $function; @@ -60,8 +60,8 @@ protected function get_protected_function( $functionName, $className = 'ElasticP public function testConstruct() { $instance = $this->get_feature(); - $this->assertEquals( 'co_authors_plus', $instance->slug ); - $this->assertEquals( 'Co-Authors Plus', $instance->title ); + $this->assertEquals( 'co_authors_plus', $instance->slug ); + $this->assertEquals( 'Co-Authors Plus', $instance->title ); } /** @@ -72,7 +72,7 @@ public function testConstruct() { public function testBoxSummary() { ob_start(); $this->get_feature()->output_feature_box_summary(); - $output = ob_get_clean(); + $output = ob_get_clean(); $this->assertStringContainsString( 'Add support for the Co-Authors Plus plugin in the Admin Post List screen by Author name', $output ); } @@ -85,7 +85,7 @@ public function testBoxSummary() { public function testBoxLong() { ob_start(); $this->get_feature()->output_feature_box_long(); - $output = ob_get_clean(); + $output = ob_get_clean(); $this->assertStringContainsString( 'If using the Co-Authors Plus plugin and the Protected Content feature, enable this feature to visit the Admin Post List screen by Author name wp-admin/edit.php?author_name=<name> and see correct results.', $output ); } @@ -96,12 +96,12 @@ public function testBoxLong() { * @since 1.1.0 */ public function testFilterOutAuthorNameAndId() { - $feature = $this->get_feature(); + $feature = $this->get_feature(); $function_filter_out_author_name_and_id_from_es_filter = $this->get_protected_function( 'filter_out_author_name_and_id_from_es_filter' ); - $this->assertEquals([], $function_filter_out_author_name_and_id_from_es_filter->invokeArgs( $feature, array([]))); + $this->assertEquals( [], $function_filter_out_author_name_and_id_from_es_filter->invokeArgs( $feature, array( [] ) ) ); - $this->assertEquals('', $function_filter_out_author_name_and_id_from_es_filter->invokeArgs( $feature, array( '' ) ) ); + $this->assertEquals( '', $function_filter_out_author_name_and_id_from_es_filter->invokeArgs( $feature, array( '' ) ) ); $formatted_args = [ 'post_filter' => [ @@ -109,12 +109,12 @@ public function testFilterOutAuthorNameAndId() { 'must' => [ [ 'term' => [ - 'post_author.display_name' => [ 'test' ] - ] - ] - ] - ] - ] + 'post_author.display_name' => [ 'test' ], + ], + ], + ], + ], + ], ]; $filtered_formatted_args = $function_filter_out_author_name_and_id_from_es_filter->invokeArgs( $feature, [ $formatted_args ] ); @@ -123,8 +123,8 @@ public function testFilterOutAuthorNameAndId() { $formatted_args['post_filter']['bool']['must'][] = [ 'terms' => [ - 'post_type.raw' => [ 'post' ] - ] + 'post_type.raw' => [ 'post' ], + ], ]; $filtered_formatted_args = $function_filter_out_author_name_and_id_from_es_filter->invokeArgs( $feature, [ $formatted_args ] ); @@ -135,8 +135,8 @@ public function testFilterOutAuthorNameAndId() { $formatted_args['post_filter']['bool']['must'][] = [ 'term' => [ - 'post_author.id' => [ 1 ] - ] + 'post_author.id' => [ 1 ], + ], ]; $filtered_formatted_args = $function_filter_out_author_name_and_id_from_es_filter->invokeArgs( $feature, [ $formatted_args ] ); diff --git a/tests/phpunit/feature/TestMetaKeyPattern.php b/tests/phpunit/feature/TestMetaKeyPattern.php index 0568264..03b3de5 100644 --- a/tests/phpunit/feature/TestMetaKeyPattern.php +++ b/tests/phpunit/feature/TestMetaKeyPattern.php @@ -16,49 +16,79 @@ class TestMetaKeyPattern extends \WP_UnitTestCase { /** * Setup each test. - * - * @since 3.5 */ public function set_up() { $instance = new ElasticPressLabs\Feature\MetaKeyPattern(); - \ElasticPress\Features::factory()->register_feature($instance); + \ElasticPress\Features::factory()->register_feature( $instance ); } + /** + * Get Meta Key Pattern feature + * + * @return MetaKeyPattern + */ protected function get_feature() { return \ElasticPress\Features::factory()->get_registered_feature( 'meta_key_pattern' ); } - protected function get_private_function( $functionName, $className = 'ElasticPressLabs\Feature\MetaKeyPattern' ) { - $reflector = new \ReflectionClass( $className ); - $function = $reflector->getMethod( $functionName ); + /** + * Get protected function as public + * + * @param string $function_name Function name + * @param string $class_name Class name + * @return ReflectionClass + */ + protected function get_private_function( $function_name, $class_name = 'ElasticPressLabs\Feature\MetaKeyPattern' ) { + $reflector = new \ReflectionClass( $class_name ); + $function = $reflector->getMethod( $function_name ); $function->setAccessible( true ); return $function; } + /** + * Test constrcut + * + * @group MetaKeyPattern + */ public function testConstruct() { $instance = $this->get_feature(); - $this->assertEquals( 'meta_key_pattern', $instance->slug ); - $this->assertEquals( 'Meta Key Pattern', $instance->title ); + $this->assertEquals( 'meta_key_pattern', $instance->slug ); + $this->assertEquals( 'Meta Key Pattern', $instance->title ); } + /** + * Test the `output_feature_box_summary` method. + * + * @group MetaKeyPattern + */ public function testBoxSummary() { ob_start(); $this->get_feature()->output_feature_box_summary(); - $output = ob_get_clean(); + $output = ob_get_clean(); $this->assertStringContainsString( 'Include or exclude meta key patterns.', $output ); } + /** + * Test the `output_feature_box_long` method. + * + * @group MetaKeyPattern + */ public function testBoxLong() { ob_start(); $this->get_feature()->output_feature_box_long(); - $output = ob_get_clean(); + $output = ob_get_clean(); $this->assertStringContainsString( 'This feature will give you the most control over the metadata indexed.', $output ); } + /** + * Test the `output_feature_box_settings` method. + * + * @group MetaKeyPattern + */ public function testOutputFeatureBoxSettings() { ob_start(); $this->get_feature()->output_feature_box_settings(); @@ -68,6 +98,11 @@ public function testOutputFeatureBoxSettings() { $this->assertStringContainsString( 'Deny patterns', $output ); } + /** + * Test the `is_match` method. + * + * @group MetaKeyPattern + */ public function testIsMatch() { $feature = $this->get_feature(); $function = $this->get_private_function( 'is_match' ); @@ -78,6 +113,11 @@ public function testIsMatch() { $this->assertFalse( $function->invokeArgs( $feature, array( 'meta_key_lorem', '//' ) ) ); } + /** + * Test the `has_delimiters` method. + * + * @group MetaKeyPattern + */ public function testHasDelimiters() { $feature = $this->get_feature(); $function = $this->get_private_function( 'has_delimiters' ); @@ -88,6 +128,11 @@ public function testHasDelimiters() { $this->assertFalse( $function->invokeArgs( $feature, array( 'm' ) ) ); } + /** + * Test the `remove_delimiters` method. + * + * @group MetaKeyPattern + */ public function testRemoveDelimiters() { $feature = $this->get_feature(); $function = $this->get_private_function( 'remove_delimiters' ); @@ -96,6 +141,11 @@ public function testRemoveDelimiters() { $this->assertEmpty( $function->invokeArgs( $feature, array( '//' ) ) ); } + /** + * Test the `prepare_regex` method. + * + * @group MetaKeyPattern + */ public function testPrepareRegex() { $feature = $this->get_feature(); $function = $this->get_private_function( 'prepare_regex' ); diff --git a/tests/phpunit/feature/TestWooCommerceSubscriptionSearch.php b/tests/phpunit/feature/TestWooCommerceSubscriptionSearch.php index 516f480..0c48e89 100644 --- a/tests/phpunit/feature/TestWooCommerceSubscriptionSearch.php +++ b/tests/phpunit/feature/TestWooCommerceSubscriptionSearch.php @@ -68,7 +68,7 @@ public function testSearchOnShopSubscriptionAdmin() { * Adding the order type, so WooCommerce can iterate of items (although inexistent) */ wc_register_order_type( 'shop_subscription', [] ); - + $subscription = new \WC_Order(); $subscription->set_billing_first_name( 'findme' ); $subscription->save(); @@ -84,9 +84,9 @@ public function testSearchOnShopSubscriptionAdmin() { $query = new \WP_Query(); $args = array( - 's' => 'findme', - 'post_type' => 'shop_subscription', - 'post_status' => 'wc-pending', + 's' => 'findme', + 'post_type' => 'shop_subscription', + 'post_status' => 'wc-pending', 'has_password' => true, ); diff --git a/tests/phpunit/indexables/TestUser.php b/tests/phpunit/indexables/TestUser.php index 7720711..be9ea27 100644 --- a/tests/phpunit/indexables/TestUser.php +++ b/tests/phpunit/indexables/TestUser.php @@ -93,7 +93,7 @@ public function createAndIndexUsers() { 'user_num' => 5, 'long_key' => 'here is a text field', ], - ], + ] ); $user_2 = $this->ep_factory->user->create( @@ -688,7 +688,7 @@ public function testUserQueryOrderbyUserNicename() { * We should not use a text/string field to sort * in Elasticsearch. * - * @return void * @group user + * @return void * @group user */ public function testFormatArgsOrderByUserNicename() { $user = new \ElasticPress\Indexable\User\User(); @@ -922,7 +922,6 @@ public function testUserQueryOrderDesc() { /** * Test meta query with simple args - * */ public function testUserMetaQuerySimple() { $this->createAndIndexUsers(); @@ -954,7 +953,6 @@ public function testUserMetaQuerySimple() { /** * Test meta query with simple args and meta_compare does not equal - * */ public function testUserMetaQuerySimpleCompare() { $this->createAndIndexUsers(); @@ -974,7 +972,6 @@ public function testUserMetaQuerySimpleCompare() { /** * Test meta query with no compare - * */ public function testUserMetaQueryNoCompare() { $this->createAndIndexUsers(); @@ -998,7 +995,6 @@ public function testUserMetaQueryNoCompare() { /** * Test meta query compare equals - * */ public function testUserMetaQueryCompareEquals() { $this->createAndIndexUsers(); @@ -1023,7 +1019,6 @@ public function testUserMetaQueryCompareEquals() { /** * Test meta query with multiple statements - * */ public function testUserMetaQueryMulti() { $this->createAndIndexUsers(); @@ -1051,7 +1046,6 @@ public function testUserMetaQueryMulti() { /** * Test meta query with multiple statements and relation OR - * */ public function testUserMetaQueryMultiRelationOr() { $this->createAndIndexUsers(); @@ -1079,7 +1073,6 @@ public function testUserMetaQueryMultiRelationOr() { /** * Test meta query with multiple statements and relation AND - * */ public function testUserMetaQueryMultiRelationAnd() { $this->createAndIndexUsers(); @@ -1107,7 +1100,6 @@ public function testUserMetaQueryMultiRelationAnd() { /** * Test basic user search - * */ public function testBasicUserSearch() { $this->createAndIndexUsers(); @@ -1125,7 +1117,6 @@ public function testBasicUserSearch() { /** * Test basic user search via user login - * */ public function testBasicUserSearchUserLogin() { $this->createAndIndexUsers(); @@ -1143,7 +1134,6 @@ public function testBasicUserSearchUserLogin() { /** * Test basic user search via user url - * */ public function testBasicUserSearchUserUrl() { $this->createAndIndexUsers(); @@ -1164,7 +1154,6 @@ public function testBasicUserSearchUserUrl() { /** * Test basic user search via meta - * */ public function testBasicUserSearchMeta() { $this->createAndIndexUsers(); @@ -1301,7 +1290,6 @@ public function testIntegrateSearchQueries() { /** * Test users that does not belong to any blog. - * */ public function testUserSearchLimitedToOneBlog() { // This user does not belong to any blog. @@ -1354,7 +1342,6 @@ public function testUserSearchLimitedToOneBlog() { /** * Test user query search by user login. - * */ public function testUserQueryUserLogin() { $this->createAndIndexUsers(); @@ -1375,7 +1362,6 @@ public function testUserQueryUserLogin() { /** * Test user query search by user nicename. - * */ public function testUserQueryUserNiceName() { $this->createAndIndexUsers(); @@ -1396,7 +1382,6 @@ public function testUserQueryUserNiceName() { /** * Test user query default orderby set to asc. - * */ public function testUserQueryDefaultOrderBy() { $this->createAndIndexUsers(); @@ -1429,7 +1414,6 @@ public function testUserQueryDefaultOrderBy() { /** * Test default order set to the score when orderby is set to empty - * */ public function testUserQueryDefaultOrder() { $this->createAndIndexUsers(); @@ -1461,7 +1445,6 @@ function( $preempt, $parsed_args, $url ) { /** * Test protected meta does not index. - * */ public function testProtectedMetaNotIndex() { @@ -1482,7 +1465,6 @@ public function testProtectedMetaNotIndex() { /** * Test whitelisted meta does index. - * */ public function testProtectedWhiteListMetaIndex() { @@ -1511,7 +1493,6 @@ function( $meta_keys ) { /** * Test query_db() function. - * */ public function testQueryDb() {