diff --git a/src/Generator/TypeBuilder.php b/src/Generator/TypeBuilder.php index 523a51928..18b1983c3 100644 --- a/src/Generator/TypeBuilder.php +++ b/src/Generator/TypeBuilder.php @@ -49,7 +49,6 @@ use function reset; use function rtrim; use function strtolower; -use function substr; /** * Service that exposes a single method `build` called for each GraphQL @@ -531,7 +530,7 @@ private function buildValidationRules(Validation $validationConfig): GeneratorIn $array = Collection::assoc(); if (null !== $validationConfig->link) { - if (str_contains($validationConfig->link, '::')) { + if (!str_contains($validationConfig->link, '::')) { // e.g. App\Entity\Droid $array->addItem('link', $validationConfig->link); } else { @@ -911,9 +910,9 @@ private function normalizeLink(string $link): array { [$fqcn, $classMember] = explode('::', $link); - if ('$' === $classMember[0]) { + if (str_starts_with($classMember, '$')) { return [$fqcn, ltrim($classMember, '$'), 'property']; - } elseif (')' === substr($classMember, -1)) { + } elseif (str_ends_with($classMember, ')')) { return [$fqcn, rtrim($classMember, '()'), 'getter']; } else { return [$fqcn, $classMember, 'member']; diff --git a/tests/Functional/Validator/InputValidatorTest.php b/tests/Functional/Validator/InputValidatorTest.php index 4af2d1ca1..58cbcd742 100644 --- a/tests/Functional/Validator/InputValidatorTest.php +++ b/tests/Functional/Validator/InputValidatorTest.php @@ -30,7 +30,7 @@ public function testNoValidation(): void $result = $this->executeGraphQLRequest($query); - $this->assertTrue(empty($result['errors'])); + $this->assertArrayNotHasKey('errors', $result); $this->assertTrue($result['data']['noValidation']); } @@ -47,7 +47,7 @@ public function testSimpleValidationPasses(): void $result = $this->executeGraphQLRequest($query); - $this->assertTrue(empty($result['errors'])); + $this->assertArrayNotHasKey('errors', $result); $this->assertTrue($result['data']['simpleValidation']); } @@ -82,7 +82,7 @@ public function testLinkedConstraintsValidationPasses(): void $result = $this->executeGraphQLRequest($query); - $this->assertTrue(empty($result['errors'])); + $this->assertArrayNotHasKey('errors', $result); $this->assertTrue($result['data']['linkedConstraintsValidation']); } @@ -128,7 +128,7 @@ public function testCollectionValidationPasses(): void $result = $this->executeGraphQLRequest($query); - $this->assertTrue(empty($result['errors'])); + $this->assertArrayNotHasKey('errors', $result); $this->assertTrue($result['data']['collectionValidation']); } @@ -189,7 +189,7 @@ public function testCascadeValidationWithGroupsPasses(): void $result = $this->executeGraphQLRequest($query); - $this->assertTrue(empty($result['errors'])); + $this->assertArrayNotHasKey('errors', $result); $this->assertTrue($result['data']['cascadeValidationWithGroups']); } @@ -249,7 +249,7 @@ public function testExpressionVariablesAccessible(): void $result = $this->executeGraphQLRequest($query); - $this->assertTrue(empty($result['errors'])); + $this->assertArrayNotHasKey('errors', $result); $this->assertTrue($result['data']['expressionVariablesValidation']); } @@ -266,7 +266,7 @@ public function testAutoValidationAutoThrowPasses(): void $result = $this->executeGraphQLRequest($query); - $this->assertTrue(empty($result['errors'])); + $this->assertArrayNotHasKey('errors', $result); $this->assertTrue($result['data']['autoValidationAutoThrow']); } @@ -296,7 +296,7 @@ public function testAutoValidationNoThrowNoErrors(): void $query = 'mutation { autoValidationNoThrow(username: "Andrew") }'; $result = $this->executeGraphQLRequest($query); - $this->assertTrue(empty($result['errors'])); + $this->assertArrayNotHasKey('errors', $result); $this->assertTrue(false === $result['data']['autoValidationNoThrow']); } @@ -309,7 +309,7 @@ public function testAutoValidationNoThrowHasErrors(): void $query = 'mutation { autoValidationNoThrow(username: "Tim") }'; $result = $this->executeGraphQLRequest($query); - $this->assertTrue(empty($result['errors'])); + $this->assertArrayNotHasKey('errors', $result); $this->assertTrue(true === $result['data']['autoValidationNoThrow']); } @@ -341,7 +341,7 @@ public function testAutoValidationAutoThrowWithGroupsPasses(): void $result = $this->executeGraphQLRequest($query); - $this->assertTrue(empty($result['errors'])); + $this->assertArrayNotHasKey('errors', $result); $this->assertTrue($result['data']['autoValidationAutoThrowWithGroups']); }