GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( b0e03a...4af0c2 )
by Tobias
02:50
created

CachePluginTest::testPluginMiss()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 22
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Geocoder package.
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license    MIT License
11
 */
12
13
namespace Geocoder\Plugin\Tests\Plugin;
14
15
use Cache\Adapter\Void\VoidCachePool;
16
use Geocoder\Plugin\Plugin\CachePlugin;
17
use Geocoder\Query\GeocodeQuery;
18
use Geocoder\Query\Query;
19
use PHPUnit\Framework\TestCase;
20
21
class CachePluginTest extends TestCase
22
{
23
    public function testPluginMiss()
24
    {
25
        $ttl = 4711;
26
        $query = GeocodeQuery::create('foo');
27
        $queryString = sha1($query->__toString());
28
        $cache = $this->getMockBuilder(VoidCachePool::class)
29
            ->disableOriginalConstructor()
30
            ->setMethods(['get', 'set'])
31
            ->getMock();
32
33
        $cache->expects($this->once())
34
            ->method('get')
35
            ->with('v4'.$queryString)
36
            ->willReturn(null);
37
        $cache->expects($this->once())
38
            ->method('set')
39
            ->with('v4'.$queryString, 'result', $ttl)
40
            ->willReturn(true);
41
42
        $first = function (Query $query) {
0 ignored issues
show
Unused Code introduced by
The parameter $query is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
43
            $this->fail('Plugin should not restart the chain');
44
        };
45
        $next = function (Query $query) {
0 ignored issues
show
Unused Code introduced by
The parameter $query is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
46
            return 'result';
47
        };
48
49
        $plugin = new CachePlugin($cache, $ttl);
50
        $this->assertEquals('result', $plugin->handleQuery($query, $next, $first));
51
    }
52
53
    public function testPluginHit()
54
    {
55
        $query = GeocodeQuery::create('foo');
56
        $queryString = sha1($query->__toString());
57
        $cache = $this->getMockBuilder(VoidCachePool::class)
58
            ->disableOriginalConstructor()
59
            ->setMethods(['get', 'set'])
60
            ->getMock();
61
62
        $cache->expects($this->once())
63
            ->method('get')
64
            ->with('v4'.$queryString)
65
            ->willReturn('result');
66
        $cache->expects($this->never())->method('set');
67
68
        $first = function (Query $query) {
0 ignored issues
show
Unused Code introduced by
The parameter $query is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
69
            $this->fail('Plugin should not restart the chain');
70
        };
71
        $next = function (Query $query) {
0 ignored issues
show
Unused Code introduced by
The parameter $query is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
72
            $this->fail('Plugin not call $next on cache hit');
73
        };
74
75
        $plugin = new CachePlugin($cache);
76
        $this->assertEquals('result', $plugin->handleQuery($query, $next, $first));
77
    }
78
}
79