From 1afdcf11bbf6abe06efb16ec5ec00629316730b3 Mon Sep 17 00:00:00 2001 From: Geoff Taylor Date: Tue, 14 May 2024 17:52:42 -0400 Subject: [PATCH] devops: Unit tests updated --- src/Constraint/QueryConstraint.php | 4 ++-- src/Constraint/QueryErrorConstraint.php | 4 ++-- src/Constraint/QuerySuccessfulConstraint.php | 5 +++-- tests/codeception/wpunit/QueryConstraintTest.php | 2 +- tests/phpunit/unit/test-queryconstraint.php | 2 +- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Constraint/QueryConstraint.php b/src/Constraint/QueryConstraint.php index a3cf7aa..ae85556 100644 --- a/src/Constraint/QueryConstraint.php +++ b/src/Constraint/QueryConstraint.php @@ -580,7 +580,7 @@ protected function findSubstring( $haystack, $needle, $search_type ) { public function matches($response): bool { // Ensure response is valid. if ( ! $this->responseIsValid( $response ) ) { - $this->error_message = 'GraphQL response is invalid.'; + $this->error_message = 'GraphQL response is invalid'; return false; } @@ -597,7 +597,7 @@ public function failureDescription($other): string { } if ( ! empty( $this->error_details ) ) { - $output .= ": \n\n\t•" . implode( "\n\n\t• ", $this->error_details ); + $output .= ": \n\n\t• " . implode( "\n\n\t• ", $this->error_details ); } return $output; diff --git a/src/Constraint/QueryErrorConstraint.php b/src/Constraint/QueryErrorConstraint.php index ffa293d..f69f3e2 100644 --- a/src/Constraint/QueryErrorConstraint.php +++ b/src/Constraint/QueryErrorConstraint.php @@ -22,7 +22,7 @@ public function matches($response): bool { // Throw if response has errors. if ( ! array_key_exists( 'errors', $response ) ) { - $this->error_message = 'No errors was thrown during the previous GraphQL requested. May need to use "--debug" flag to see contents of previous request.'; + $this->error_message = "No errors was thrown during the previous GraphQL requested. \n Use \"--debug\" flag to see contents of previous request."; return false; } @@ -56,7 +56,7 @@ public function matches($response): bool { } if ( ! $data_passed || ! $error_passed) { - $this->error_message = 'The GraphQL response failed one or more of the expected validation rules.'; + $this->error_message = 'The GraphQL response failed the following steps in validation'; return false; } diff --git a/src/Constraint/QuerySuccessfulConstraint.php b/src/Constraint/QuerySuccessfulConstraint.php index b3af2f7..1510572 100644 --- a/src/Constraint/QuerySuccessfulConstraint.php +++ b/src/Constraint/QuerySuccessfulConstraint.php @@ -24,7 +24,7 @@ public function matches($response): bool { // Throw if response has errors. if ( array_key_exists( 'errors', $response ) ) { - $this->error_message = 'An error was thrown during the previous GraphQL requested. May need to use "--debug" flag to see contents of previous request.'; + $this->error_message = "An error was thrown during the previous GraphQL requested. \n Use \"--debug\" flag to see contents of previous request."; return false; } @@ -32,6 +32,7 @@ public function matches($response): bool { if ( empty( $this->validationRules ) ) { return true; } + // Check validation rules. $passed = true; @@ -42,7 +43,7 @@ public function matches($response): bool { } if ( ! $passed ) { - $this->error_message = 'The GraphQL response failed one or more of the expected validation rules.'; + $this->error_message = 'The GraphQL response failed the following steps in validation'; return false; } diff --git a/tests/codeception/wpunit/QueryConstraintTest.php b/tests/codeception/wpunit/QueryConstraintTest.php index d5b6104..aff3024 100644 --- a/tests/codeception/wpunit/QueryConstraintTest.php +++ b/tests/codeception/wpunit/QueryConstraintTest.php @@ -84,7 +84,7 @@ public function testFailureDescription() { $constraint = new QueryConstraint($this->logger); $response = [4, 5, 6]; $this->assertFalse($constraint->matches($response)); - $this->assertEquals("GraphQL response failed validation: \n\n\t• The GraphQL query response must be provided as an associative array.", $constraint->failureDescription($response)); + $this->assertEquals("GraphQL response is invalid: \n\n\t• The GraphQL query response must be provided as an associative array.", $constraint->failureDescription($response)); } public function testToString() { diff --git a/tests/phpunit/unit/test-queryconstraint.php b/tests/phpunit/unit/test-queryconstraint.php index 151ed3f..27888bf 100644 --- a/tests/phpunit/unit/test-queryconstraint.php +++ b/tests/phpunit/unit/test-queryconstraint.php @@ -84,7 +84,7 @@ public function test_FailureDescription() { $constraint = new QueryConstraint($this->logger); $response = [4, 5, 6]; $this->assertFalse($constraint->matches($response)); - $this->assertEquals("GraphQL response failed validation: \n\n\t• The GraphQL query response must be provided as an associative array.", $constraint->failureDescription($response)); + $this->assertEquals("GraphQL response is invalid: \n\n\t• The GraphQL query response must be provided as an associative array.", $constraint->failureDescription($response)); } public function test_ToString() {