-
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathCache.php
More file actions
41 lines (31 loc) · 1.34 KB
/
Cache.php
File metadata and controls
41 lines (31 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
use Pest\TypeCoverage\Support\Cache;
use PHPStan\Analyser\Error;
beforeEach(function () {
$this->cache = Cache::instance();
$this->cache->flush();
});
afterEach(function () {
$this->cache->flush();
});
test('it persists and retrieves cached results', function () {
$file = __DIR__.'/../Fixtures/All.php';
$error = new Error('Test error', $file, 10);
$this->cache->persist($file, [$file, [$error], []]);
expect($this->cache->has($file))->toBeTrue()
->and($this->cache->get($file))->toBeArray()
->and($this->cache->get($file)[0])->toBe($file)
->and($this->cache->get($file)[1])->toHaveCount(1)
->and($this->cache->get($file)[1][0])->toBeInstanceOf(Error::class)
->and($this->cache->get($file)[1][0]->getMessage())->toBe('Test error');
});
test('it persists and retrieves errors containing PhpParser node metadata', function () {
$file = __DIR__.'/../Fixtures/All.php';
$nodeName = new PhpParser\Node\Name('Tests\Fixtures\All');
$error = new Error('Type mismatch', $file, 10, metadata: ['type' => $nodeName]);
$this->cache->persist($file, [$file, [$error], []]);
$cached = $this->cache->get($file);
expect($cached[1])->toHaveCount(1)
->and($cached[1][0])->toBeInstanceOf(Error::class)
->and($cached[1][0]->getMessage())->toBe('Type mismatch');
});