Skip to content

Commit f8d47db

Browse files
committed
Fix validator tests
1 parent a2aa631 commit f8d47db

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

src/Generator/TypeBuilder.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
use function reset;
5050
use function rtrim;
5151
use function strtolower;
52-
use function substr;
5352

5453
/**
5554
* Service that exposes a single method `build` called for each GraphQL
@@ -531,7 +530,7 @@ private function buildValidationRules(Validation $validationConfig): GeneratorIn
531530
$array = Collection::assoc();
532531

533532
if (null !== $validationConfig->link) {
534-
if (str_contains($validationConfig->link, '::')) {
533+
if (!str_contains($validationConfig->link, '::')) {
535534
// e.g. App\Entity\Droid
536535
$array->addItem('link', $validationConfig->link);
537536
} else {
@@ -911,9 +910,9 @@ private function normalizeLink(string $link): array
911910
{
912911
[$fqcn, $classMember] = explode('::', $link);
913912

914-
if ('$' === $classMember[0]) {
913+
if (str_starts_with($classMember, '$')) {
915914
return [$fqcn, ltrim($classMember, '$'), 'property'];
916-
} elseif (')' === substr($classMember, -1)) {
915+
} elseif (str_ends_with($classMember, ')')) {
917916
return [$fqcn, rtrim($classMember, '()'), 'getter'];
918917
} else {
919918
return [$fqcn, $classMember, 'member'];

tests/Functional/Validator/InputValidatorTest.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testNoValidation(): void
3030

3131
$result = $this->executeGraphQLRequest($query);
3232

33-
$this->assertTrue(empty($result['errors']));
33+
$this->assertArrayNotHasKey('errors', $result);
3434
$this->assertTrue($result['data']['noValidation']);
3535
}
3636

@@ -47,7 +47,7 @@ public function testSimpleValidationPasses(): void
4747

4848
$result = $this->executeGraphQLRequest($query);
4949

50-
$this->assertTrue(empty($result['errors']));
50+
$this->assertArrayNotHasKey('errors', $result);
5151
$this->assertTrue($result['data']['simpleValidation']);
5252
}
5353

@@ -82,7 +82,7 @@ public function testLinkedConstraintsValidationPasses(): void
8282

8383
$result = $this->executeGraphQLRequest($query);
8484

85-
$this->assertTrue(empty($result['errors']));
85+
$this->assertArrayNotHasKey('errors', $result);
8686
$this->assertTrue($result['data']['linkedConstraintsValidation']);
8787
}
8888

@@ -128,7 +128,7 @@ public function testCollectionValidationPasses(): void
128128

129129
$result = $this->executeGraphQLRequest($query);
130130

131-
$this->assertTrue(empty($result['errors']));
131+
$this->assertArrayNotHasKey('errors', $result);
132132
$this->assertTrue($result['data']['collectionValidation']);
133133
}
134134

@@ -189,7 +189,7 @@ public function testCascadeValidationWithGroupsPasses(): void
189189

190190
$result = $this->executeGraphQLRequest($query);
191191

192-
$this->assertTrue(empty($result['errors']));
192+
$this->assertArrayNotHasKey('errors', $result);
193193
$this->assertTrue($result['data']['cascadeValidationWithGroups']);
194194
}
195195

@@ -249,7 +249,7 @@ public function testExpressionVariablesAccessible(): void
249249

250250
$result = $this->executeGraphQLRequest($query);
251251

252-
$this->assertTrue(empty($result['errors']));
252+
$this->assertArrayNotHasKey('errors', $result);
253253
$this->assertTrue($result['data']['expressionVariablesValidation']);
254254
}
255255

@@ -266,7 +266,7 @@ public function testAutoValidationAutoThrowPasses(): void
266266

267267
$result = $this->executeGraphQLRequest($query);
268268

269-
$this->assertTrue(empty($result['errors']));
269+
$this->assertArrayNotHasKey('errors', $result);
270270
$this->assertTrue($result['data']['autoValidationAutoThrow']);
271271
}
272272

@@ -296,7 +296,7 @@ public function testAutoValidationNoThrowNoErrors(): void
296296
$query = 'mutation { autoValidationNoThrow(username: "Andrew") }';
297297
$result = $this->executeGraphQLRequest($query);
298298

299-
$this->assertTrue(empty($result['errors']));
299+
$this->assertArrayNotHasKey('errors', $result);
300300
$this->assertTrue(false === $result['data']['autoValidationNoThrow']);
301301
}
302302

@@ -309,7 +309,7 @@ public function testAutoValidationNoThrowHasErrors(): void
309309
$query = 'mutation { autoValidationNoThrow(username: "Tim") }';
310310
$result = $this->executeGraphQLRequest($query);
311311

312-
$this->assertTrue(empty($result['errors']));
312+
$this->assertArrayNotHasKey('errors', $result);
313313
$this->assertTrue(true === $result['data']['autoValidationNoThrow']);
314314
}
315315

@@ -341,7 +341,7 @@ public function testAutoValidationAutoThrowWithGroupsPasses(): void
341341

342342
$result = $this->executeGraphQLRequest($query);
343343

344-
$this->assertTrue(empty($result['errors']));
344+
$this->assertArrayNotHasKey('errors', $result);
345345
$this->assertTrue($result['data']['autoValidationAutoThrowWithGroups']);
346346
}
347347

0 commit comments

Comments
 (0)