Skip to content

Commit a37c7de

Browse files
committed
Improving code coverage
1 parent 6d454e8 commit a37c7de

File tree

2 files changed

+82
-2
lines changed

2 files changed

+82
-2
lines changed

Tests/FunctionalTest.php

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ public function testLoginQuery(): void
222222
mutation login {
223223
login(userName: "foo", password: "bar") {
224224
userName
225+
roles
225226
}
226227
}']);
227228

@@ -232,7 +233,10 @@ public function testLoginQuery(): void
232233
$this->assertSame([
233234
'data' => [
234235
'login' => [
235-
'userName' => 'foo'
236+
'userName' => 'foo',
237+
'roles' => [
238+
'ROLE_USER'
239+
]
236240
]
237241
]
238242
], $result);
@@ -298,6 +302,14 @@ public function testForceLoginNoSession(): void
298302
$kernel->boot();
299303
}
300304

305+
public function testForceMeNoSecurity(): void
306+
{
307+
$kernel = new GraphqliteTestingKernel(false, 'off', false, 'on');
308+
$this->expectException(GraphQLException::class);
309+
$this->expectExceptionMessage('In order to enable the "me" query (via the graphqlite.security.enable_me parameter), you need to install the security bundle.');
310+
$kernel->boot();
311+
}
312+
301313
public function testForceLoginNoSecurity(): void
302314
{
303315
$kernel = new GraphqliteTestingKernel(true, 'on', false);
@@ -306,6 +318,63 @@ public function testForceLoginNoSecurity(): void
306318
$kernel->boot();
307319
}
308320

321+
/*public function testAutoMeNoSecurity(): void
322+
{
323+
$kernel = new GraphqliteTestingKernel(true, null, false);
324+
$kernel->boot();
325+
326+
$session = new Session(new MockArraySessionStorage());
327+
$container = $kernel->getContainer();
328+
$container->set('session', $session);
329+
330+
$request = Request::create('/graphql', 'POST', ['query' => '
331+
{
332+
me {
333+
userName
334+
roles
335+
}
336+
}
337+
']);
338+
339+
$response = $kernel->handle($request);
340+
341+
$result = json_decode($response->getContent(), true);
342+
343+
$this->assertSame([
344+
'data' => [
345+
'me' => [
346+
'userName' => 'anon.',
347+
'roles' => [],
348+
]
349+
]
350+
], $result);
351+
}*/
352+
353+
public function testAllOff(): void
354+
{
355+
$kernel = new GraphqliteTestingKernel(true, 'off', true, 'off');
356+
$kernel->boot();
357+
358+
$session = new Session(new MockArraySessionStorage());
359+
$container = $kernel->getContainer();
360+
$container->set('session', $session);
361+
362+
$request = Request::create('/graphql', 'POST', ['query' => '
363+
{
364+
me {
365+
userName
366+
roles
367+
}
368+
}
369+
']);
370+
371+
$response = $kernel->handle($request);
372+
373+
$result = json_decode($response->getContent(), true);
374+
375+
$this->assertSame('Cannot query field "me" on type "Query".', $result['errors'][0]['message']);
376+
}
377+
309378
private function logIn(ContainerInterface $container)
310379
{
311380
// put a token into the storage so the final calls can function

Tests/GraphqliteTestingKernel.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,18 @@ class GraphqliteTestingKernel extends Kernel
3333
* @var bool
3434
*/
3535
private $enableSecurity;
36+
/**
37+
* @var string|null
38+
*/
39+
private $enableMe;
3640

37-
public function __construct(bool $enableSession = true, ?string $enableLogin = null, bool $enableSecurity = true)
41+
public function __construct(bool $enableSession = true, ?string $enableLogin = null, bool $enableSecurity = true, ?string $enableMe = null)
3842
{
3943
parent::__construct('test', true);
4044
$this->enableSession = $enableSession;
4145
$this->enableLogin = $enableLogin;
4246
$this->enableSecurity = $enableSecurity;
47+
$this->enableMe = $enableMe;
4348
}
4449

4550
public function registerBundles()
@@ -115,6 +120,12 @@ public function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
115120
];
116121
}
117122

123+
if ($this->enableMe) {
124+
$graphqliteConf['security'] = [
125+
'enable_me' => $this->enableMe,
126+
];
127+
}
128+
118129
$container->loadFromExtension('graphqlite', $graphqliteConf);
119130
});
120131
$confDir = $this->getProjectDir().'/Tests/Fixtures/config';

0 commit comments

Comments
 (0)