diff --git a/src/TestCase/WPGraphQLTestCommon.php b/src/TestCase/WPGraphQLTestCommon.php index 351d55b..12b8ffd 100644 --- a/src/TestCase/WPGraphQLTestCommon.php +++ b/src/TestCase/WPGraphQLTestCommon.php @@ -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. diff --git a/tests/codeception/wpunit/WPGraphQLTestCaseTest.php b/tests/codeception/wpunit/WPGraphQLTestCaseTest.php index 7d1b28b..c433b8d 100644 --- a/tests/codeception/wpunit/WPGraphQLTestCaseTest.php +++ b/tests/codeception/wpunit/WPGraphQLTestCaseTest.php @@ -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() { diff --git a/tests/phpunit/unit/test-wpgraphqlunittestcase.php b/tests/phpunit/unit/test-wpgraphqlunittestcase.php index 6635252..e57bb66 100644 --- a/tests/phpunit/unit/test-wpgraphqlunittestcase.php +++ b/tests/phpunit/unit/test-wpgraphqlunittestcase.php @@ -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() {