Skip to content

Commit

Permalink
Merge pull request #3202 from 10up/chore/improve-cli-commands-tests-c…
Browse files Browse the repository at this point in the history
…overage

Improve CLI commands tests coverage
  • Loading branch information
felipeelia authored Dec 16, 2022
2 parents b3f4390 + dd2cc48 commit 38a4ad1
Show file tree
Hide file tree
Showing 6 changed files with 551 additions and 83 deletions.
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 @@ -611,6 +604,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 @@ -649,7 +644,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 @@ -1376,7 +1371,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

0 comments on commit 38a4ad1

Please sign in to comment.