|  | 
| 1 | 1 | <?php | 
| 2 | 2 | namespace GraphQL\Tests\Validator; | 
| 3 | 3 | 
 | 
|  | 4 | +use GraphQL\Error\Error; | 
|  | 5 | +use GraphQL\Language\AST\NodeKind; | 
|  | 6 | +use GraphQL\Language\Parser; | 
|  | 7 | +use GraphQL\Validator\DocumentValidator; | 
| 4 | 8 | use GraphQL\Validator\Rules\QueryComplexity; | 
|  | 9 | +use GraphQL\Validator\ValidationContext; | 
| 5 | 10 | 
 | 
| 6 | 11 | class QueryComplexityTest extends AbstractQuerySecurityTest | 
| 7 | 12 | { | 
| @@ -149,6 +154,38 @@ public function testTypeNameMetaFieldQuery() | 
| 149 | 154 |         $this->assertTypeNameMetaFieldQuery(3); | 
| 150 | 155 |     } | 
| 151 | 156 | 
 | 
|  | 157 | +    public function testSkippedWhenThereAreOtherValidationErrors() | 
|  | 158 | +    { | 
|  | 159 | +        $query = 'query MyQuery { human(name: INVALID_VALUE) { dogs {name} } }'; | 
|  | 160 | + | 
|  | 161 | +        $reportedError = new Error("OtherValidatorError"); | 
|  | 162 | +        $otherRule = function(ValidationContext $context) use ($reportedError) { | 
|  | 163 | +            return [ | 
|  | 164 | +                NodeKind::OPERATION_DEFINITION => [ | 
|  | 165 | +                    'leave' => function() use ($context, $reportedError) { | 
|  | 166 | +                        $context->reportError($reportedError); | 
|  | 167 | +                    } | 
|  | 168 | +                ] | 
|  | 169 | +            ]; | 
|  | 170 | +        }; | 
|  | 171 | + | 
|  | 172 | +        $errors = DocumentValidator::validate( | 
|  | 173 | +            QuerySecuritySchema::buildSchema(), | 
|  | 174 | +            Parser::parse($query), | 
|  | 175 | +            [$otherRule, $this->getRule(1)] | 
|  | 176 | +        ); | 
|  | 177 | + | 
|  | 178 | +        $this->assertEquals(1, count($errors)); | 
|  | 179 | +        $this->assertSame($reportedError, $errors[0]); | 
|  | 180 | + | 
|  | 181 | +        $this->setExpectedException('GraphQL\Error\Error'); | 
|  | 182 | +        DocumentValidator::validate( | 
|  | 183 | +            QuerySecuritySchema::buildSchema(), | 
|  | 184 | +            Parser::parse($query), | 
|  | 185 | +            [$this->getRule(1)] | 
|  | 186 | +        ); | 
|  | 187 | +    } | 
|  | 188 | + | 
| 152 | 189 |     private function assertDocumentValidators($query, $queryComplexity, $startComplexity) | 
| 153 | 190 |     { | 
| 154 | 191 |         for ($maxComplexity = $startComplexity; $maxComplexity >= 0; --$maxComplexity) { | 
|  | 
0 commit comments