Skip to content

Commit d49c0f5

Browse files
committed
test: add unit test on Fields helper
1 parent 9d7c618 commit d49c0f5

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/Unit/Support/FieldsTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,34 @@ public function testGet(array $query, string $type, ?array $expected)
2626
{
2727
$this->assertEquals($expected, Fields::get(new Request(['fields' => $query]), $type));
2828
}
29+
30+
public function testGetWithContext()
31+
{
32+
Fields::through('test', function () {
33+
$this->assertEquals(null, Fields::get(new Request));
34+
$this->assertEquals(['a', 'b', 'c'], Fields::get(new Request(['fields' => ['test' => 'a,b,c']])));
35+
});
36+
}
37+
38+
public function testHasWithContext()
39+
{
40+
Fields::through('test', function () {
41+
$this->assertEquals(false, Fields::has(new Request, 'b'));
42+
$this->assertEquals(true, Fields::has(new Request(['fields' => ['test' => 'a,b,c']]), 'b'));
43+
});
44+
}
45+
46+
public function testFailGetWithoutContext()
47+
{
48+
$this->expectException(\BadMethodCallException::class);
49+
50+
Fields::get(new Request);
51+
}
52+
53+
public function testFailHasWithoutContext()
54+
{
55+
$this->expectException(\BadMethodCallException::class);
56+
57+
Fields::has(new Request, 'test');
58+
}
2959
}

0 commit comments

Comments
 (0)