diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..6249c04 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,9 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [0.1.0-alpha] + +- Still in development. [#1](https://github.com/renatonascalves/elasticsearch-buddypress/issues/1) diff --git a/README.md b/README.md new file mode 100644 index 0000000..c487ea6 --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +# Elasticsearch BuddyPress + +[![Project Status: Active.](https://www.repostatus.org/badges/latest/concept.svg)](https://www.repostatus.org/#concept) + +Elasticsearch BuddyPress is an integration of the BuddyPress plugin with Elasticsearch using the common/popular plugins: [ElasticPress](https://github.com/10up/ElasticPress), [SearchPress](https://github.com/alleyinteractive/searchpress), and [VIP Enterprise Search](https://docs.wpvip.com/enterprise-search/). + +## Overview + +Currently, the goal of this plugin is purely educational. Joining my experience with BuddyPress and Elasticsearch to create something useful. But it is also mostly an experiment at this point. Not ready for live sites/communities, yet. + +I'm currently working on the implementation design (by using an Adapter, also known as Wrapper, Design pattern), by adding support for the Groups components for the [ElasticPress](https://github.com/10up/ElasticPress) plugin. + +## Requirements + +* [PHP](https://www.php.net/) >= 8.3+ +* [WordPress](https://wordpress.org/) >= 6.5+ +* [BuddyPress](https://buddypress.org/) >= latest +* [ElasticPress](https://github.com/10up/ElasticPress) >= latest +* [Elasticsearch](https://www.elastic.co/) >= 7.15+ + +## Example + +Here is an example of how to query groups using the `ep_integrate` parameter: + +```php +$args = [ "ep_integrate" => true ]; + +BP_Groups_Group::get( $args ); +``` diff --git a/composer.json b/composer.json index 0f99545..28c4487 100644 --- a/composer.json +++ b/composer.json @@ -55,14 +55,12 @@ "phpstan/extension-installer": "^1.1", "phpstan/phpstan": "^1.10", "szepeviktor/phpstan-wordpress": "^1.3", - "wpackagist-plugin/elasticpress": "^4.6" + "wpackagist-plugin/elasticpress": "^5.0" }, "scripts": { "phpcs": "phpcs . --basepath=.", "phpcbf": "phpcbf . --basepath=.", - "phpstan": [ - "phpstan analyze --ansi --memory-limit=1G" - ], + "phpstan": "phpstan analyze --ansi --memory-limit=1G", "phpunit": "pest", "test_multi": "WP_MULTISITE=1 pest" }, @@ -110,6 +108,7 @@ "*.xml", "*.dist", "*.cache", + "CHANGELOG.md", ".editorconfig", ".gitignore", ".deployignore", diff --git a/elasticsearch-buddypress.php b/elasticsearch-buddypress.php index 086cb5e..39b0ccb 100755 --- a/elasticsearch-buddypress.php +++ b/elasticsearch-buddypress.php @@ -19,12 +19,12 @@ * Requires PHP: 8.3 * Requires WP: 6.1 * Tested up to: 6.5.2 - * Requires Plugins: buddypress + * Requires Plugins: buddypress, elasticpress * License: GPL-3.0-or-later * License URI: https://www.gnu.org/licenses/gpl-3.0.html */ -declare( strict_types=1 ); +declare(strict_types=1); namespace Elasticsearch\BuddyPress; diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 6e8fb1d..1e97357 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -3,6 +3,7 @@ parameters: paths: - elasticsearch-buddypress.php - src/ + - tests/ scanDirectories: - ../buddypress/ - ../elasticpress/ diff --git a/src/Adapters/Adapter.php b/src/Adapters/Adapter.php index 2b8b71f..6a57f77 100644 --- a/src/Adapters/Adapter.php +++ b/src/Adapters/Adapter.php @@ -5,7 +5,7 @@ * @package Elasticsearch\BuddyPress */ -declare( strict_types=1 ); +declare(strict_types=1); namespace Elasticsearch\BuddyPress\Adapters; diff --git a/src/Adapters/ElasticPress/ElasticPress.php b/src/Adapters/ElasticPress/ElasticPress.php index 12cd26a..e2c32b8 100644 --- a/src/Adapters/ElasticPress/ElasticPress.php +++ b/src/Adapters/ElasticPress/ElasticPress.php @@ -5,7 +5,7 @@ * @package Elasticsearch\BuddyPress */ -declare( strict_types=1 ); +declare(strict_types=1); namespace Elasticsearch\BuddyPress\Adapters\ElasticPress; @@ -66,7 +66,7 @@ public function missing_notice(): void {

- +

$enabled, }; } - - /** - * Output feature box long. - * - * @todo Implement this method. - */ - public function output_feature_box_long(): void {} } diff --git a/src/Adapters/ElasticPress/Features/Groups/GroupFormatArgs.php b/src/Adapters/ElasticPress/Features/Groups/GroupFormatArgs.php index 070e411..e61aed8 100644 --- a/src/Adapters/ElasticPress/Features/Groups/GroupFormatArgs.php +++ b/src/Adapters/ElasticPress/Features/Groups/GroupFormatArgs.php @@ -5,7 +5,7 @@ * @package Elasticsearch\BuddyPress */ -declare( strict_types=1 ); +declare(strict_types=1); namespace Elasticsearch\BuddyPress\Adapters\ElasticPress\Features\Groups; @@ -20,10 +20,49 @@ */ class GroupFormatArgs extends FormatArgs { + /** + * Format query args. + * + * @return array + */ + public function format(): array { + + // Bail if no query args. + if ( empty( $this->query_args ) ) { + return []; + } + + $es_query_args = [ + 'from' => (int) ( $this->query_args['per_page'] * ( $this->query_args['page'] - 1 ) ), + 'size' => (int) $this->query_args['per_page'] ?: 20, + 'track_total_hits' => true, + ]; + + $this->parse_sort(); + $this->maybe_set_filters(); + $this->maybe_set_search_fields(); + $this->maybe_set_fields(); + + if ( $this->query ) { + $es_query_args['query'] = $this->query->toArray(); + } + + if ( $this->sorts ) { + $es_query_args['sort'] = $this->sorts->toArray(); + } + + if ( $this->fields ) { + $es_query_args['_source'] = $this->fields; + } + + return $es_query_args; + } + /** * Parse sort options. */ private function parse_sort(): void { + // phpcs:disable Squiz.PHP.CommentedOutCode.Found // @todo support randon query. /** * Order by 'rand' support @@ -140,9 +179,9 @@ private function maybe_set_filters(): void { // @todo add support. if ( ! empty( $this->query_args['meta_query'] ) ) { /** - * Filters the meta keys to be excluded from group searches . + * Filters the meta keys to be excluded from group searches. * - * @param array $exclude_meta_keys Meta keys to be excluded . + * @param string[] $exclude_meta_keys Meta keys to be excluded. */ $exclude_meta_keys = apply_filters( 'elasticsearch_buddypress_group_query_excluded_meta_keys', [] ); @@ -177,44 +216,7 @@ private function maybe_set_fields(): void { case 'ids': $this->fields( [ 'ID' ] ); break; - } - } - - /** - * Format query args. - * - * @return array - */ - public function format(): array { - // Bail if no query args. - if ( empty( $this->query_args ) ) { - return []; } - - $es_query_args = [ - 'from' => (int) ( $this->query_args['per_page'] * ( $this->query_args['page'] - 1 ) ), - 'size' => (int) $this->query_args['per_page'] ?: 20, - 'track_total_hits' => true, - ]; - - $this->parse_sort(); - $this->maybe_set_filters(); - $this->maybe_set_search_fields(); - $this->maybe_set_fields(); - - if ( $this->query ) { - $es_query_args['query'] = $this->query->toArray(); - } - - if ( $this->sorts ) { - $es_query_args['sort'] = $this->sorts->toArray(); - } - - if ( $this->fields ) { - $es_query_args['_source'] = $this->fields; - } - - return $es_query_args; } } diff --git a/src/Adapters/ElasticPress/Features/Groups/Indexable.php b/src/Adapters/ElasticPress/Features/Groups/Indexable.php index 535ef3e..82db6be 100644 --- a/src/Adapters/ElasticPress/Features/Groups/Indexable.php +++ b/src/Adapters/ElasticPress/Features/Groups/Indexable.php @@ -5,14 +5,14 @@ * @package Elasticsearch\BuddyPress */ -declare( strict_types=1 ); +declare(strict_types=1); namespace Elasticsearch\BuddyPress\Adapters\ElasticPress\Features\Groups; +use WP_Taxonomy; use WP_Term; use WP_User; -use WP_Taxonomy; -use WP_Error; +use BP_Groups_Group; use ElasticPress\Indexable as EP_Indexable; /** @@ -84,7 +84,7 @@ public function prepare_document( $group_id ): array|false { $last_activity = $group->date_created; } - $document = [ + $group_document = [ 'ID' => $group->id, 'group_id' => $group->id, 'group_creator' => $this->prepare_creator_data( $group->creator_id ), @@ -98,8 +98,8 @@ public function prepare_document( $group_id ): array|false { 'meta' => $this->prepare_meta_types( $this->prepare_meta( $group->id ) ), 'name' => $group->name, 'parent_id' => $group->parent_id, - 'permalink' => bp_get_group_url( $group ), - 'terms' => $this->prepapre_terms( $group->id ), + 'permalink' => bp_get_group_url( $group ), // why say this value? + 'terms' => $this->prepare_terms( $group->id ), 'slug' => $group->slug, 'status' => $group->status, 'total_member_count' => absint( groups_get_groupmeta( $group->id, 'total_member_count', true ) ), @@ -108,10 +108,10 @@ public function prepare_document( $group_id ): array|false { /** * Filter the group document for indexing. * - * @param array $document Group document. - * @param int $group_id Group ID. + * @param array $group_document Group document. + * @param BP_Groups_Group $group Group object. */ - return apply_filters( 'elasticsearch_buddypress_group_sync_args', $document, $group_id ); + return apply_filters( 'elasticsearch_buddypress_group_sync_args', $group_document, $group ); } /** @@ -148,7 +148,7 @@ public function prepare_creator_data( int $creator_id ): array { * @param int $group_id Group ID. * @return array */ - public function prepapre_terms( int $group_id ): array { + public function prepare_terms( int $group_id ): array { $selected_taxonomies = $this->get_indexable_group_taxonomies(); if ( empty( $selected_taxonomies ) ) { @@ -167,19 +167,21 @@ public function prepapre_terms( int $group_id ): array { foreach ( $selected_taxonomies as $taxonomy ) { $object_terms = bp_get_object_terms( $group_id, $taxonomy->name ); - if ( ! $object_terms || $object_terms instanceof WP_Error ) { + if ( ! $object_terms || ! is_array( $object_terms ) ) { continue; } $formatted_terms = []; foreach ( $object_terms as $term ) { - if ( ! isset( $formatted_terms[ $term->term_id ] ) ) { - $formatted_terms[ $term->term_id ] = $this->get_formatted_term( $term ); + if ( isset( $formatted_terms[ $term->term_id ] ) ) { + continue; + } + + $formatted_terms[ $term->term_id ] = $this->get_formatted_term( $term ); - if ( $allow_hierarchy ) { - $formatted_terms = $this->get_parent_terms( $formatted_terms, $term, $taxonomy->name, $group_id ); - } + if ( $allow_hierarchy ) { + $formatted_terms = $this->get_parent_terms( $formatted_terms, $term, $taxonomy->name, $group_id ); } } @@ -213,10 +215,10 @@ public function prepare_meta( int $group_id ): array { /** * Filter index-able private meta. * - * Allows for specifying private meta keys that may be indexed in the same manor as public meta keys. + * Allows for specifying private meta keys that may be indexed in the same manner as public meta keys. * - * @param array $keys Array of index-able private meta keys. - * @param int $group_id Group ID to be indexed. + * @param string[] $keys Array of index-able private meta keys. + * @param int $group_id Group ID to be indexed. */ $allowed_protected_keys = (array) apply_filters( 'elasticsearch_buddypress_prepare_group_meta_allowed_protected_keys', [], $group_id ); @@ -225,19 +227,22 @@ public function prepare_meta( int $group_id ): array { * * Allows for specifying public meta keys that should be excluded from the ElasticPress index. * - * @param array $keys Array of public meta keys to exclude from index. - * @param int $group_id Group ID to be indexed. + * @param string[] $keys Array of public meta keys to exclude from index. + * @param int $group_id Group ID to be indexed. */ $excluded_public_keys = (array) apply_filters( 'elasticsearch_buddypress_prepare_group_meta_excluded_public_keys', $excluded_keys, $group_id ); foreach ( $meta as $key => $value ) { - $allow_index = false; - if ( is_protected_meta( $key ) && in_array( $key, $allowed_protected_keys, true ) ) { - $allow_index = true; - } elseif ( ! in_array( $key, $excluded_public_keys, true ) ) { - $allow_index = true; - } + $allow_index = match ( true ) { + // If the key is a protected key and is allowed, allow indexing it. + is_protected_meta( $key ) && in_array( $key, $allowed_protected_keys, true ) => true, + + // If the key is not in the excluded public keys, allow indexing it. + ! in_array( $key, $excluded_public_keys, true ) => true, + + default => false, + }; /** * Filter whether to index a specific group meta key. @@ -246,7 +251,7 @@ public function prepare_meta( int $group_id ): array { * * @param bool $allow_index Whether to index the meta key. * @param string $key Meta key. - * @param int $group_id Group ID. + * @param int $group_id Group ID to be indexed. */ $allow_index = (bool) apply_filters( 'elasticsearch_buddypress_allow_index_group_meta_key', $allow_index, $key, $group_id ); @@ -272,7 +277,7 @@ public function query_db( $args ): array { $bp = buddypress(); $defaults = [ - 'number' => 350, + 'number' => 100, 'offset' => 0, 'orderby' => 'date_created', 'order' => 'DESC', @@ -334,7 +339,7 @@ private function get_indexable_group_taxonomies(): array { $validated_taxonomies = []; foreach ( $selected_taxonomies as $selected_taxonomy ) { - // If we get a taxonomy name, we need to convert it to taxonomy object. + // If we get a taxonomy name, we need to convert it into a taxonomy object. if ( ! $selected_taxonomy instanceof WP_Taxonomy && taxonomy_exists( (string) $selected_taxonomy ) ) { $selected_taxonomy = get_taxonomy( $selected_taxonomy ); @@ -389,7 +394,6 @@ private function get_parent_terms( array $terms, WP_Term $term, string $taxonomy if ( ! isset( $terms[ $parent_term->term_id ] ) ) { $terms[ $parent_term->term_id ] = $this->get_formatted_term( $parent_term ); - } return $this->get_parent_terms( $terms, $parent_term, $taxonomy_name, $group_id ); diff --git a/src/Adapters/ElasticPress/Features/Groups/QueryIntegration.php b/src/Adapters/ElasticPress/Features/Groups/QueryIntegration.php index a042da6..84a3dfb 100644 --- a/src/Adapters/ElasticPress/Features/Groups/QueryIntegration.php +++ b/src/Adapters/ElasticPress/Features/Groups/QueryIntegration.php @@ -5,7 +5,7 @@ * @package Elasticsearch\BuddyPress */ -declare( strict_types=1 ); +declare(strict_types=1); namespace Elasticsearch\BuddyPress\Adapters\ElasticPress\Features\Groups; @@ -15,7 +15,7 @@ /** * Groups query integration class. */ -class QueryIntegration { +readonly class QueryIntegration { /** * Setup actions and filters. @@ -23,7 +23,6 @@ class QueryIntegration { * @param string $indexable_slug Indexable slug. */ public function __construct( private string $indexable_slug ) { - $this->indexable_slug = $indexable_slug; /** * Filter whether to enable query integration during indexing. @@ -37,31 +36,50 @@ public function __construct( private string $indexable_slug ) { return; } - add_filter( 'bp_groups_get_paged_groups_sql', [ $this, 'maybe_filter_query' ], 10, 3 ); + add_filter( 'bp_after_bp_groups_group_get_parse_args', [ $this, 'maybe_filter_bp_groups_group_get_parse_args' ] ); + + add_filter( 'bp_groups_get_paged_groups_sql', [ $this, 'maybe_filter_pagination_query' ], 10, 3 ); add_filter( 'bp_groups_get_total_groups_sql', [ $this, 'maybe_filter_total_groups_sql' ], 10, 3 ); } + /** + * Filters the parsed arguments for the get method. + * + * @param array $parsed_args Array of parsed arguments. + * @return array + */ + public function maybe_filter_bp_groups_group_get_parse_args( $parsed_args ): array { + + // Check if we are on the groups component. + // @todo this might be too broad. We might need to check for specific group queries instead. + if ( bp_is_groups_component() ) { + $parsed_args['ep_integrate'] = true; + } + + return $parsed_args; + } + /** * Filters the SQL used to retrieve group results. * - * @param string $paged_groups_sql Concatenated SQL statement. - * @param array $sql Array of SQL parts before concatenation. - * @param array $r Array of parsed arguments for the get method. + * @param string $groups_sql Concatenated SQL statement. + * @param array $sql Array of SQL parts for the query. + * @param array $r Array of parsed arguments. * @return string */ - public function maybe_filter_query( $paged_groups_sql, $sql, $r ): string { + public function maybe_filter_pagination_query( $groups_sql, $sql, $r ): string { $group_indexable = Indexables::factory()->get( $this->indexable_slug ); /** * Filter whether to skip group query integration. * - * @param bool $skip Whether to skip group query integration. Default false. - * @param array $r Array of parsed arguments for the get method. + * @param bool $skip Whether to skip group query integration. Defaults to `false`. + * @param array $r Array of parsed arguments. */ $skip_group_query_integration = apply_filters( 'elasticsearch_buddypress_skip_group_query_integration', false, $r ); if ( ! $group_indexable->elasticpress_enabled( $r ) || true === $skip_group_query_integration ) { - return $paged_groups_sql; + return $groups_sql; } $formatted_args = $group_indexable->format_args( $r ); @@ -70,8 +88,8 @@ public function maybe_filter_query( $paged_groups_sql, $sql, $r ): string { ? $group_indexable->query_es( $formatted_args, $r ) : $static_results; - if ( false === $ep_query ) { - return $paged_groups_sql; + if ( empty( $ep_query ) || empty( $ep_query['found_documents']['value'] ?? 0 ) ) { + return $groups_sql; } $this->static_results( $formatted_args, $ep_query ); @@ -88,7 +106,7 @@ public function maybe_filter_query( $paged_groups_sql, $sql, $r ): string { $ids = 0; } - return "SELECT DISTINCT g.id FROM {$bp->groups->table_name} g WHERE g.id IN ({$ids})"; + return sprintf( 'SELECT DISTINCT g.id FROM %s g WHERE g.id IN (%s)', $bp->groups->table_name, $ids ); } /** @@ -109,8 +127,8 @@ public function maybe_filter_total_groups_sql( $total_groups_sql, $sql, $r ): st /** * Filter whether to skip group query integration. * - * @param bool $skip Whether to skip group query integration. - * @param array $r Array of parsed arguments. + * @param bool $skip Whether to skip group query integration. Defaults to `false`. + * @param array $r Array of parsed arguments. */ $skip_group_query_integration = apply_filters( 'elasticsearch_buddypress_skip_group_query_integration', false, $r ); @@ -123,6 +141,10 @@ public function maybe_filter_total_groups_sql( $total_groups_sql, $sql, $r ): st // Get from static cache if available. $cached = $this->static_results( $formatted_args ); + if ( empty( $cached ) ) { + return $total_groups_sql; + } + return $wpdb->prepare( 'SELECT %d', absint( $cached['found_documents']['value'] ?? 0 ) ); } @@ -130,7 +152,7 @@ public function maybe_filter_total_groups_sql( $total_groups_sql, $sql, $r ): st * Get or/and set static cached results. * * @param array $formatted_args Formatted arguments. - * @param array|null $ep_query EP query. Default null. + * @param array|null $ep_query EP query. Defaults to `null`. * @return array|null */ protected function static_results( array $formatted_args, ?array $ep_query = null ): ?array { diff --git a/src/Adapters/ElasticPress/Features/Groups/SyncManager.php b/src/Adapters/ElasticPress/Features/Groups/SyncManager.php index 900579d..7e5facd 100644 --- a/src/Adapters/ElasticPress/Features/Groups/SyncManager.php +++ b/src/Adapters/ElasticPress/Features/Groups/SyncManager.php @@ -7,7 +7,7 @@ * @package Elasticsearch\BuddyPress */ -declare( strict_types=1 ); +declare(strict_types=1); namespace Elasticsearch\BuddyPress\Adapters\ElasticPress\Features\Groups; diff --git a/src/Adapters/ElasticPress/Features/Groups/mapping.php b/src/Adapters/ElasticPress/Features/Groups/mapping.php index 4ab42cf..1edd1a0 100644 --- a/src/Adapters/ElasticPress/Features/Groups/mapping.php +++ b/src/Adapters/ElasticPress/Features/Groups/mapping.php @@ -5,7 +5,7 @@ * @package Elasticsearch\BuddyPress */ -declare( strict_types=1 ); +declare(strict_types=1); return [ 'settings' => [ diff --git a/src/Adapters/FormatArgs.php b/src/Adapters/FormatArgs.php index 349859c..b0295cf 100644 --- a/src/Adapters/FormatArgs.php +++ b/src/Adapters/FormatArgs.php @@ -5,7 +5,7 @@ * @package Elasticsearch\BuddyPress */ -declare( strict_types=1 ); +declare(strict_types=1); namespace Elasticsearch\BuddyPress\Adapters; diff --git a/src/Controller.php b/src/Controller.php index 1ae4886..f0e8a30 100644 --- a/src/Controller.php +++ b/src/Controller.php @@ -5,7 +5,7 @@ * @package Elasticsearch\BuddyPress */ -declare( strict_types=1 ); +declare(strict_types=1); namespace Elasticsearch\BuddyPress; diff --git a/src/Factory.php b/src/Factory.php index b2f45d1..a38ac61 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -5,7 +5,7 @@ * @package Elasticsearch\BuddyPress */ -declare( strict_types=1 ); +declare(strict_types=1); namespace Elasticsearch\BuddyPress; diff --git a/src/Interfaces/Formatter.php b/src/Interfaces/Formatter.php index c07da02..2c69b92 100644 --- a/src/Interfaces/Formatter.php +++ b/src/Interfaces/Formatter.php @@ -5,7 +5,7 @@ * @package Elasticsearch\BuddyPress */ -declare( strict_types=1 ); +declare(strict_types=1); namespace Elasticsearch\BuddyPress\Interfaces; diff --git a/src/Interfaces/Hookable.php b/src/Interfaces/Hookable.php index 21447db..17264b0 100644 --- a/src/Interfaces/Hookable.php +++ b/src/Interfaces/Hookable.php @@ -5,7 +5,7 @@ * @package Elasticsearch\BuddyPress */ -declare( strict_types=1 ); +declare(strict_types=1); namespace Elasticsearch\BuddyPress\Interfaces; diff --git a/src/Registry.php b/src/Registry.php index ea37e86..83bccfb 100644 --- a/src/Registry.php +++ b/src/Registry.php @@ -5,7 +5,7 @@ * @package Elasticsearch\BuddyPress */ -declare( strict_types=1 ); +declare(strict_types=1); namespace Elasticsearch\BuddyPress; diff --git a/tests/Adapters/ElasticPress/ApiTest.php b/tests/Adapters/ElasticPress/ApiTest.php index 02f93f7..9e2640a 100644 --- a/tests/Adapters/ElasticPress/ApiTest.php +++ b/tests/Adapters/ElasticPress/ApiTest.php @@ -6,7 +6,7 @@ * @package Elasticsearch\BuddyPress\Tests */ -declare( strict_types=1 ); +declare(strict_types=1); namespace Elasticsearch\BuddyPress\Tests; @@ -14,7 +14,7 @@ it( 'gets Elasticsearch version', - function () { + function (): void { expect( Elasticsearch::factory()->get_elasticsearch_version( true ) )-> toBeString(); } @@ -22,7 +22,7 @@ function () { it( 'gets the ep_host value', - function () { + function (): void { expect( get_option( 'ep_host' ) )->toBe( 'http://localhost:9200' ); } ); diff --git a/tests/Adapters/ElasticPress/GroupTest.php b/tests/Adapters/ElasticPress/GroupTest.php index 90d2c56..6b8483d 100644 --- a/tests/Adapters/ElasticPress/GroupTest.php +++ b/tests/Adapters/ElasticPress/GroupTest.php @@ -5,13 +5,13 @@ * @package Elasticsearch\BuddyPress\Tests */ -declare( strict_types=1 ); +declare(strict_types=1); namespace Elasticsearch\BuddyPress\Tests; test( 'buddypress groups is active', - function () { - expect( bp_is_active( 'groups' ) )->toBe( true ); + function (): void { + expect( bp_is_active( 'groups' ) )->toBeTrue(); } ); diff --git a/tests/Includes/bootstrap-functions.php b/tests/Includes/bootstrap-functions.php index c323347..c27ed6f 100644 --- a/tests/Includes/bootstrap-functions.php +++ b/tests/Includes/bootstrap-functions.php @@ -5,7 +5,7 @@ * @package Elasticsearch\BuddyPress\Tests */ -declare( strict_types=1 ); +declare(strict_types=1); namespace Elasticsearch\BuddyPress\Tests; @@ -104,7 +104,7 @@ function elasticsearch_bootup(): void { } /** - * Make sure we only test on 1 shard because any more will lead to inconsitent results. + * Make sure we only test on 1 shard because any more will lead to inconsistent results. * * @return int */ diff --git a/tests/Includes/define-constants.php b/tests/Includes/define-constants.php index a51be0b..6424f26 100644 --- a/tests/Includes/define-constants.php +++ b/tests/Includes/define-constants.php @@ -6,7 +6,7 @@ * @package Elasticsearch\BuddyPress\Tests */ -declare( strict_types=1 ); +declare(strict_types=1); if ( ! defined( 'BP_TESTS_DIR' ) ) { define( 'BP_TESTS_DIR', dirname( __FILE__, 4 ) . '/buddypress/tests/phpunit' ); diff --git a/tests/TestCases/AdapterUnitTestCase.php b/tests/TestCases/AdapterUnitTestCase.php index 0d8f0da..4f00226 100644 --- a/tests/TestCases/AdapterUnitTestCase.php +++ b/tests/TestCases/AdapterUnitTestCase.php @@ -5,7 +5,7 @@ * @package Elasticsearch\BuddyPress\Tests */ -declare( strict_types=1 ); +declare(strict_types=1); namespace Elasticsearch\BuddyPress\Tests\TestCases; @@ -14,19 +14,4 @@ /** * AdapterUnitTestCase class. */ -abstract class AdapterUnitTestCase extends Test_Case { - - /** - * Set up the test case. - */ - public function set_up(): void { - parent::set_up(); - } - - /** - * Tear down the test case. - */ - public function tear_down(): void { - parent::tear_down(); - } -} +abstract class AdapterUnitTestCase extends Test_Case {} diff --git a/tests/TestCases/ElasticPressTestCase.php b/tests/TestCases/ElasticPressTestCase.php index bfb13d5..f909a94 100644 --- a/tests/TestCases/ElasticPressTestCase.php +++ b/tests/TestCases/ElasticPressTestCase.php @@ -5,12 +5,9 @@ * @package Elasticsearch\BuddyPress\Tests */ -declare( strict_types=1 ); - namespace Elasticsearch\BuddyPress\Tests\TestCases; /** * ElasticPressTestCase class. */ -class ElasticPressTestCase extends AdapterUnitTestCase { -} +class ElasticPressTestCase extends AdapterUnitTestCase {} diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 84b1393..1e1c5fd 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -6,7 +6,7 @@ * @package Elasticsearch\BuddyPress\Tests */ -declare( strict_types=1 ); +declare(strict_types=1); namespace Elasticsearch\BuddyPress\Tests; @@ -30,7 +30,6 @@ function () { ) ->loaded( function () { - // @todo This is not playing nice with Mantle. // Load BuddyPress. require_once BP_TESTS_DIR . '/includes/loader.php'; @@ -49,10 +48,6 @@ function () { // Activate all components. tests_add_filter( 'bp_is_active', '__return_true' ); - // @todo This is not playing nice with Mantle. - // echo "Loading BuddyPress testcases...\n"; - // require_once BP_TESTS_DIR . '/includes/testcase.php'; - // Loading testcases. uses( ElasticPressTestCase::class )->in( 'Adapters/ElasticPress' ); } diff --git a/tests/multisite.xml b/tests/multisite.xml deleted file mode 100644 index 9ecf3d7..0000000 --- a/tests/multisite.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - .// - - -