|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Digia\Lumen\GraphQL\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use Digia\Lumen\GraphQL\Execution\Processor; |
|
6
|
|
|
use Digia\Lumen\GraphQL\GraphQLService; |
|
7
|
|
|
use Youshido\GraphQL\Schema\Schema; |
|
8
|
|
|
use Illuminate\Contracts\Cache\Repository as CacheRepository; |
|
9
|
|
|
|
|
10
|
|
|
class GraphQLServiceTest extends TestCase |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var GraphQLService |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $service; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var CacheRepository |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $cache; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var Processor |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $processor; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @inheritdoc |
|
29
|
|
|
*/ |
|
30
|
|
|
public function setUp() |
|
31
|
|
|
{ |
|
32
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject|CacheRepository $cacheRepository */ |
|
33
|
|
|
$this->cache = $this->getMockBuilder(CacheRepository::class) |
|
|
|
|
|
|
34
|
|
|
->setMethods(['get', 'forever']) |
|
35
|
|
|
->getMockForAbstractClass(); |
|
36
|
|
|
|
|
37
|
|
|
$this->processor = new Processor(new Schema()); |
|
38
|
|
|
$this->service = new GraphQLService($this->processor, $this->cache); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
public function testGetProcessor() |
|
43
|
|
|
{ |
|
44
|
|
|
$this->cache->expects($this->any()) |
|
45
|
|
|
->method('get') |
|
46
|
|
|
->with(GraphQLService::PROCESSOR_CACHE_KEY) |
|
47
|
|
|
->willReturn($this->processor); |
|
48
|
|
|
|
|
49
|
|
|
$this->assertEquals($this->processor, $this->service->getProcessor()); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Tests that a processor instance is stored in the cache if it doesn't exist yet |
|
54
|
|
|
*/ |
|
55
|
|
|
public function testGetProcessorNotCached() |
|
56
|
|
|
{ |
|
57
|
|
|
// get() should return null |
|
58
|
|
|
$this->cache->expects($this->once()) |
|
59
|
|
|
->method('get') |
|
60
|
|
|
->willReturn(null); |
|
61
|
|
|
|
|
62
|
|
|
// forever() should be called |
|
63
|
|
|
$this->cache->expects($this->once()) |
|
64
|
|
|
->method('forever') |
|
65
|
|
|
->with(GraphQLService::PROCESSOR_CACHE_KEY); |
|
66
|
|
|
|
|
67
|
|
|
$this->service->getProcessor(); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Tests that the cache is left untouched if a cached instance exists |
|
72
|
|
|
*/ |
|
73
|
|
|
public function testGetProcessorCached() |
|
74
|
|
|
{ |
|
75
|
|
|
// get() should return Processor |
|
76
|
|
|
$this->cache->expects($this->once()) |
|
77
|
|
|
->method('get') |
|
78
|
|
|
->willReturn($this->processor); |
|
79
|
|
|
|
|
80
|
|
|
// forever() should be never be called |
|
81
|
|
|
$this->cache->expects($this->never()) |
|
82
|
|
|
->method('forever'); |
|
83
|
|
|
$processor = new Processor(new Schema()); |
|
84
|
|
|
|
|
85
|
|
|
$this->assertEquals($processor, $this->service->getProcessor()); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Tests that the cache is really cleared |
|
90
|
|
|
*/ |
|
91
|
|
|
public function testForgetProcessor() |
|
92
|
|
|
{ |
|
93
|
|
|
// forget() should be called once |
|
94
|
|
|
$this->cache->expects($this->once()) |
|
95
|
|
|
->method('forget') |
|
96
|
|
|
->with(GraphQLService::PROCESSOR_CACHE_KEY); |
|
97
|
|
|
|
|
98
|
|
|
$this->service->forgetProcessor(); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..