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
Branch v2 (a88462)
by Hilari
02:38
created

FeatureContext::iShouldRetrieveTheRedisCacheObject()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4285
cc 2
eloc 3
nc 2
nop 0
1
<?php
2
3
use Behat\Behat\Context\SnippetAcceptingContext;
4
use Cmp\Cache\Backend\RedisCache;
5
6
/**
7
 * Class FeatureContext
8
 */
9
class FeatureContext implements SnippetAcceptingContext
10
{
11
    /**
12
     * @var \Redis
13
     */
14
    private $redis;
15
16
    /**
17
     * @var RedisCache
18
     */
19
    private $backend;
20
21
    /**
22
     * @var string
23
     */
24
    private $result;
25
26
    /**
27
     * FeatureContext constructor.
28
     */
29
    public function __construct()
30
    {
31
        $this->redis = new \Redis();
32
        $this->redis->connect($_SERVER['REDIS_HOST'], 6379);
33
        $this->backend = new RedisCache($this->redis);
34
    }
35
36
    /**
37
     * @BeforeScenario
38
     */
39
    public function reset()
40
    {
41
        $this->redis->flushDB();
42
    }
43
44
    /**
45
     * @Given I store a an item in the cache
46
     */
47
    public function iStoreAAnItemInTheCache()
48
    {
49
        $this->backend->set('foo', 'bar');
50
    }
51
52
    /**
53
     * @When I retrieve it
54
     */
55
    public function whenIRetrieved()
56
    {
57
        $this->result = $this->backend->demand('foo');
58
    }
59
60
    /**
61
     * @Then I should get the same item
62
     */
63
    public function iShouldGetTheSameItem()
64
    {
65
        if ($this->result !== 'bar') {
66
            throw new \RuntimeException("The retrieve item is not the same");
67
        }
68
    }
69
70
    /**
71
     * @param $timeToLive
72
     *
73
     * @Given I store a an item in the cache for :timeToLive second
74
     */
75
    public function iStoreAAnItemInTheCacheForSecond($timeToLive)
76
    {
77
        $this->backend->set('foo', 'bar', $timeToLive);
78
    }
79
80
    /**
81
     * @param $seconds
82
     *
83
     * @When I wait :seconds seconds
84
     */
85
    public function iWaitSeconds($seconds)
86
    {
87
        sleep($seconds);
88
    }
89
90
    /**
91
     * @Then I should not be able to retrieve it
92
     */
93
    public function iShouldNotBeAbleToRetrieveIt()
94
    {
95
        if ($this->backend->has('foo')) {
96
            throw new \RuntimeException("Redis still has the item stored");
97
        }
98
    }
99
100
    /**
101
     * @When I delete the item from the cache
102
     */
103
    public function iDeleteTheItemFromTheCache()
104
    {
105
        $this->backend->delete('foo');
106
    }
107
108
    /**
109
     * @When I flush all the items item from the cache
110
     */
111
    public function iFlushAllTheItemsItemFromTheCache()
112
    {
113
        $this->backend->flush();
114
    }
115
116
    /**
117
     * @When I request a new redis cache instance to the factory
118
     */
119
    public function iRequestANewRedisCacheInstanceToTheFactory()
120
    {
121
        $redis = (new \Cmp\Cache\Factory\CacheBuilder())
122
            ->withRedisCacheFromParams($_SERVER['REDIS_HOST'], 6379, 1)
123
            ->build();
124
125
        if (!$redis instanceof RedisCache) {
126
            throw new RuntimeException("The factory could not create a RedisCache");
127
        }
128
    }
129
130
    /**
131
     * @Given I have the connection parameters for redis
132
     * @Then I should receive a redis cache already connected
133
     */
134
    public function doNothing()
135
    {
136
137
    }
138
}
139