Skip to content

Commit

Permalink
fix: assertQueryError fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
kidunot89 committed Apr 30, 2024
1 parent e79c937 commit 12b1c1f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/TestCase/WPGraphQLTestCommon.php
Original file line number Diff line number Diff line change
Expand Up @@ -670,9 +670,9 @@ public static function assertQuerySuccessful( array $response, array $expected =
* @param string $message Error message.
* @return void
*/
public function assertQueryError( array $response, array $expected, $message = null ) {
$error_passing = null; // Create individual error rule evaluation flag for later use.
$data_passing = null; // Create individual data rule evaluation flag for later use.
public function assertQueryError( array $response, array $expected = [], $message = null ) {
$error_passing = null; // Create individual error rule evaluation flag for later use.
$data_passing = empty( $expected ); // Create individual data rule evaluation flag for later use.
$response_valid = static::_assertIsValidQueryResponse( $response, $message ); // Validate response shape with sub assertion.
$response_failed = in_array( 'errors', array_keys( $response ) ); // Ensure no errors thrown.

Expand Down
6 changes: 6 additions & 0 deletions tests/codeception/wpunit/WPGraphQLTestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ public function testAssertQueryError() {

// Assert response has error.
$this->assertQueryError( $response, $expected );

// Assert response has error with no expected rules.
$this->assertQueryError( $response );

// Assert response has error with no expected rules and a message.
$this->assertQueryError( $response, [], 'Query return with no errors' );
}

public function testComplexExpectedNodes() {
Expand Down
6 changes: 6 additions & 0 deletions tests/phpunit/unit/test-wpgraphqlunittestcase.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ public function test_AssertQueryError() {

// Assert response has error.
$this->assertQueryError( $response, $expected );

// Assert response has error with no expected rules.
$this->assertQueryError( $response );

// Assert response has error with no expected rules and a message.
$this->assertQueryError( $response, [], 'Query return with no errors' );
}

public function test_ComplexExpectedNodes() {
Expand Down

0 comments on commit 12b1c1f

Please sign in to comment.