Skip to content

Commit

Permalink
devops: Unit tests updated
Browse files Browse the repository at this point in the history
  • Loading branch information
kidunot89 committed May 14, 2024
1 parent e6e9b23 commit 1afdcf1
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/Constraint/QueryConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/Constraint/QueryErrorConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
5 changes: 3 additions & 2 deletions src/Constraint/QuerySuccessfulConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ 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;
}

// Return true if no validation rules provided.
if ( empty( $this->validationRules ) ) {
return true;
}


// Check validation rules.
$passed = true;
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/codeception/wpunit/QueryConstraintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/unit/test-queryconstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 1afdcf1

Please sign in to comment.