Skip to content

Commit 4ae1401

Browse files
committed
Add unit test for multiple rules in one validator
1 parent af9f51e commit 4ae1401

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

tests/Fixtures/App/Http/Controllers/TestController.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,13 @@ public function testValidator(string $foo, int $bar): string
4646
{
4747
return 'success';
4848
}
49+
50+
/**
51+
* @Query()
52+
* @Validate(for="foo", rule="starts_with:abc|ends_with:xyz")
53+
*/
54+
public function testValidatorMultiple(string $foo): string
55+
{
56+
return 'success';
57+
}
4958
}

tests/Providers/GraphQLiteServiceProviderTest.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,62 @@ public function testValidator()
103103

104104
$this->assertSame(400, $response->getStatusCode(), $response->getContent());
105105
}
106+
107+
public function testValidatorMultiple()
108+
{
109+
$response = $this->json('POST', '/graphql', ['query' => '{ testValidatorMultiple(foo:"xyzabc") }']);
110+
$response->assertJson([
111+
'errors' => [
112+
[
113+
'message' => 'The foo must start with one of the following: abc',
114+
'extensions' => [
115+
'argument' => 'foo',
116+
'category' => 'Validate'
117+
],
118+
],
119+
[
120+
'message' => 'The foo must end with one of the following: xyz',
121+
'extensions' => [
122+
'argument' => 'foo',
123+
'category' => 'Validate'
124+
],
125+
]
126+
]
127+
]);
128+
129+
$this->assertSame(400, $response->getStatusCode(), $response->getContent());
130+
$response = $this->json('POST', '/graphql', ['query' => '{ testValidatorMultiple(foo:"abcdef") }']);
131+
$response->assertJson([
132+
'errors' => [
133+
[
134+
'message' => 'The foo must end with one of the following: xyz',
135+
'extensions' => [
136+
'argument' => 'foo',
137+
'category' => 'Validate'
138+
],
139+
]
140+
]
141+
]);
142+
143+
$this->assertSame(400, $response->getStatusCode(), $response->getContent());
144+
145+
$this->assertSame(400, $response->getStatusCode(), $response->getContent());
146+
$response = $this->json('POST', '/graphql', ['query' => '{ testValidatorMultiple(foo:"uvwxyz") }']);
147+
$response->assertJson([
148+
'errors' => [
149+
[
150+
'message' => 'The foo must start with one of the following: abc',
151+
'extensions' => [
152+
'argument' => 'foo',
153+
'category' => 'Validate'
154+
],
155+
]
156+
]
157+
]);
158+
159+
$this->assertSame(400, $response->getStatusCode(), $response->getContent());
160+
161+
$response = $this->json('POST', '/graphql', ['query' => '{ testValidatorMultiple(foo:"abcxyz") }']);
162+
$this->assertSame(200, $response->getStatusCode(), $response->getContent());
163+
}
106164
}

0 commit comments

Comments
 (0)