Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve CLI commands tests coverage #3202

Merged
merged 8 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions includes/classes/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
use ElasticPress\Indexables as Indexables;

if ( ! defined( 'ABSPATH' ) ) {
// @codeCoverageIgnoreStart
exit; // Exit if accessed directly.
// @codeCoverageIgnoreEnd
}

/**
Expand Down Expand Up @@ -221,10 +223,7 @@ public function put_mapping( $args, $assoc_args ) {
$this->maybe_change_index_prefix( $assoc_args );
$this->connect_check();
$this->index_occurring();

if ( ! $this->put_mapping_helper( $args, $assoc_args ) ) {
exit( 1 );
}
$this->put_mapping_helper( $args, $assoc_args );
}

/**
Expand Down Expand Up @@ -286,9 +285,7 @@ private function put_mapping_helper( $args, $assoc_args ) {
if ( $result ) {
WP_CLI::success( esc_html__( 'Mapping sent', 'elasticpress' ) );
} else {
WP_CLI::error( esc_html__( 'Mapping failed', 'elasticpress' ), false );

return false;
WP_CLI::error( esc_html__( 'Mapping failed', 'elasticpress' ) );
}
}

Expand Down Expand Up @@ -322,9 +319,7 @@ private function put_mapping_helper( $args, $assoc_args ) {
if ( $result ) {
WP_CLI::success( esc_html__( 'Mapping sent', 'elasticpress' ) );
} else {
WP_CLI::error( esc_html__( 'Mapping failed', 'elasticpress' ), false );

return false;
WP_CLI::error( esc_html__( 'Mapping failed', 'elasticpress' ) );
}
}
}
Expand Down Expand Up @@ -359,9 +354,7 @@ private function put_mapping_helper( $args, $assoc_args ) {
if ( $result ) {
WP_CLI::success( esc_html__( 'Mapping sent', 'elasticpress' ) );
} else {
WP_CLI::error( esc_html__( 'Mapping failed', 'elasticpress' ), false );

return false;
WP_CLI::error( esc_html__( 'Mapping failed', 'elasticpress' ) );
}
}

Expand Down Expand Up @@ -591,6 +584,8 @@ public function epio_set_autosuggest( $args, $assoc_args ) {
add_action( 'ep_epio_wp_cli_set_autosuggest', [ $autosuggest_feature, 'epio_send_autosuggest_public_request' ] );

do_action( 'ep_epio_wp_cli_set_autosuggest', $args, $assoc_args );

WP_CLI::success( esc_html__( 'Done.', 'elasticpress' ) );
}

/**
Expand Down Expand Up @@ -629,7 +624,7 @@ public function delete_transient_on_int( $signal_no ) {
if ( SIGINT === $signal_no ) {
$this->delete_transient();
WP_CLI::log( esc_html__( 'Indexing cleaned up.', 'elasticpress' ) );
exit;
WP_CLI::halt();
}
}

Expand Down Expand Up @@ -1340,7 +1335,7 @@ public function stop_on_failed_mapping( $index_meta, $indexable, $result ) {
if ( ! $result ) {
$this->delete_transient();

exit( 1 );
WP_CLI::error( esc_html__( 'Mapping Failed.', 'elasticpress' ) );
}
}

Expand Down
2 changes: 2 additions & 0 deletions includes/classes/DeprecatedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
use \WP_CLI as WP_CLI;

if ( ! defined( 'ABSPATH' ) ) {
// @codeCoverageIgnoreStart
exit; // Exit if accessed directly.
// @codeCoverageIgnoreEnd
}

/**
Expand Down
1 change: 1 addition & 0 deletions includes/classes/IndexHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,7 @@ protected function stop_the_insanity() {
* @since 4.0.0
*/
public function clear_index_meta() {
$this->index_meta = false;
Utils\delete_option( 'ep_index_meta', false );
}

Expand Down
10 changes: 10 additions & 0 deletions includes/classes/Indexables.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ public function register( Indexable $indexable ) {
$this->registered_indexables[ $indexable->slug ] = $indexable;
}

/**
* Unregister an indexable instance
*
* @param string $slug Indexable type slug.
* @since 4.4.1
*/
public function unregister( $slug ) {
unset( $this->registered_indexables[ $slug ] );
}

/**
* Get an indexable instance given a slug
*
Expand Down
Loading