Skip to content

Commit

Permalink
Fix validator tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mcg-web committed Dec 24, 2021
1 parent a2aa631 commit f8d47db
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
7 changes: 3 additions & 4 deletions src/Generator/TypeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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'];
Expand Down
20 changes: 10 additions & 10 deletions tests/Functional/Validator/InputValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}

Expand All @@ -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']);
}

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

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

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

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

Expand All @@ -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']);
}

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

Expand All @@ -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']);
}

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

Expand Down

0 comments on commit f8d47db

Please sign in to comment.