Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
rebeccahum committed Nov 26, 2024
1 parent a58a8b9 commit 2ee3412
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
6 changes: 3 additions & 3 deletions includes/classes/Elasticsearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -1735,9 +1735,9 @@ public function add_elasticpress_version_to_user_agent( $user_agent ) {
* @param array $query Query to log.
*/
protected function add_query_log( $query ) {
$wp_debug = defined( 'WP_DEBUG' ) && WP_DEBUG;
$wp_ep_debug = defined( 'WP_EP_DEBUG' ) && WP_EP_DEBUG;
$wp_debug = defined( 'WP_DEBUG' ) && WP_DEBUG;
$wp_ep_debug = defined( 'WP_EP_DEBUG' ) && WP_EP_DEBUG;

/**
* Filter query logging. Don't log anything to the queries property when true.
*
Expand Down
26 changes: 26 additions & 0 deletions tests/php/TestQueryLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,32 @@ public function testIsQueryErrorWithStatusCode( $expected, $status_code ) {
$this->assertSame( $expected, $method->invokeArgs( $query_logger, [ $query ] ) );
}

/**
* Test the ep_disable_query_logging filter
*
* @group queryLogger
*/
public function testEpDisableQueryLoggingFilter() {
$query_logger = $this->getMockBuilder( QueryLogger::class )
->setMethods( [ 'add_query_log' ] )

Check failure on line 516 in tests/php/TestQueryLogger.php

View workflow job for this annotation

GitHub Actions / PHP Lint

Tabs must be used to indent lines; spaces are not allowed
->getMock();

Check failure on line 517 in tests/php/TestQueryLogger.php

View workflow job for this annotation

GitHub Actions / PHP Lint

Tabs must be used to indent lines; spaces are not allowed

// Add the `queries` property to the mock object
$reflection = new \ReflectionClass( $query_logger );
$property = $reflection->getProperty( 'queries' );

Check warning on line 521 in tests/php/TestQueryLogger.php

View workflow job for this annotation

GitHub Actions / PHP Lint

Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space
$property->setAccessible( true );
$property->setValue( $query_logger, [] );

add_filter( 'ep_disable_query_logging', '__return_true' );

$query_logger->add_query_log( [ 'query' => 'test' ] );
$queries = $property->getValue( $query_logger );

$this->assertEmpty( $queries );

remove_filter( 'ep_disable_query_logging', '__return_true' );
}

/**
* Data provider for the testMaybeLogDeleteIndex method
*
Expand Down

0 comments on commit 2ee3412

Please sign in to comment.