diff --git a/src/TestCase/WPGraphQLTestCommon.php b/src/TestCase/WPGraphQLTestCommon.php index 707a189..12b8ffd 100644 --- a/src/TestCase/WPGraphQLTestCommon.php +++ b/src/TestCase/WPGraphQLTestCommon.php @@ -625,11 +625,11 @@ public static function assertIsValidQueryResponse( $response, $message = null ) * @param array $expected List of expected data objects. * @param string $message Error message. */ - public static function assertQuerySuccessful( array $response, array $expected, $message = null ) { + public static function assertQuerySuccessful( array $response, array $expected = [], $message = null ) { static::$actual = null; static::$last_constraint = null; - $data_passing = null; // Create individual data 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_successful = ! in_array( 'errors', array_keys( $response ) ); // Ensure no errors thrown. @@ -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 ffba321..c433b8d 100644 --- a/tests/codeception/wpunit/WPGraphQLTestCaseTest.php +++ b/tests/codeception/wpunit/WPGraphQLTestCaseTest.php @@ -87,6 +87,12 @@ public function testAssertQuerySuccessful() { // Assert query successful. $this->assertQuerySuccessful( $response, $expected ); + + // Assert query successful with no expected rules. + $this->assertQuerySuccessful( $response ); + + // Assert query successful with no expected rules. + $this->assertQuerySuccessful( $response, [], 'Query returned errors' ); } public function testAssertQueryError() { @@ -170,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 bfa88a4..e57bb66 100644 --- a/tests/phpunit/unit/test-wpgraphqlunittestcase.php +++ b/tests/phpunit/unit/test-wpgraphqlunittestcase.php @@ -82,6 +82,12 @@ public function test_AssertQuerySuccessful() { // Assert query successful. $this->assertQuerySuccessful( $response, $expected ); + + // Assert query successful with no expected rules. + $this->assertQuerySuccessful( $response ); + + // Assert query successful with no expected rules. + $this->assertQuerySuccessful( $response, [], 'Query returned errors' ); } public function test_AssertQueryError() { @@ -165,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() {