• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wp-graphql / wp-graphql-testcase / #250

14 May 2024 09:52PM UTC coverage: 79.076% (-1.3%) from 80.342%
#250

push

web-flow
Merge 1afdcf11b into 743e920b2

19 of 38 new or added lines in 3 files covered. (50.0%)

2 existing lines in 2 files now uncovered.

291 of 368 relevant lines covered (79.08%)

3.19 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

81.25
/src/Constraint/QuerySuccessfulConstraint.php
1
<?php
2
/**
3
 * QuerySuccessfulConstraint 
4
 *
5
 * Assertion validating successful WPGraphQL query response.
6
 * @since v3.0.0
7
 * @package Tests\WPGraphQL\Constraint
8
 */
9

10
namespace Tests\WPGraphQL\Constraint;
11

12
use PHPUnit\Framework\Exception;
13

14
class QuerySuccessfulConstraint extends QueryConstraint {
15

16
    /**
17
     * {@inheritDoc}
18
     */
19
    public function matches($response): bool {
20
        // Ensure response is valid.
21
        if ( ! $this->responseIsValid( $response ) ) {
8✔
22
            return false;
1✔
23
        }
24

25
        // Throw if response has errors.
26
        if ( array_key_exists( 'errors', $response ) ) {
7✔
27
            $this->error_message = "An error was thrown during the previous GraphQL requested. \n Use \"--debug\" flag to see contents of previous request.";
2✔
28
            return false;
2✔
29
        }
30

31
        // Return true if no validation rules provided.
32
        if ( empty( $this->validationRules ) ) {
5✔
33
            return true;
2✔
34
        }
35
        
36

37
        // Check validation rules.
38
        $passed = true;
4✔
39
        foreach( $this->validationRules as $expected_data ) {
4✔
40
            if ( ! $this->expectedDataFound( $response, $expected_data ) ) {
4✔
41
                $passed = false;
×
42
            }
43
        }
44

45
        if ( ! $passed ) {
4✔
NEW
46
            $this->error_message = 'The GraphQL response failed the following steps in validation';
×
UNCOV
47
            return false;
×
48
        }
49

50
        return true;
4✔
51
    }
52

53
    /**
54
     * {@inheritDoc}
55
     */
56
    public function toString(): string {
57
        return 'is a successful WPGraphQL response with no errors.';
1✔
58
    }
59
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc