Passed
Branch master (d64ad0)
by Machiel
02:58
created

ArrayStoreTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 38.46 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 20
loc 52
rs 10
c 0
b 0
f 0

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
use CheatCodes\GuzzleHsts\ArrayStore;
3
use PHPUnit\Framework\TestCase;
4
5
class ArrayStoreTest extends TestCase
6
{
7
    /**
8
     * @var ArrayStore
9
     */
10
    private $store;
11
12
    public function setUp()
13
    {
14
        $this->store = new ArrayStore();
15
    }
16
17
    public function testSet()
18
    {
19
        $this->store->set('example.com', 60, ['foo' => 'bar']);
20
21
        $this->assertEquals(['foo' => 'bar'], $this->store->get('example.com'));
22
    }
23
24
    public function testOverwrite()
25
    {
26
        $this->store->set('example.com', 60, ['foo' => 'bar']);
27
28
        $this->assertEquals(['foo' => 'bar'], $this->store->get('example.com'));
29
30
        $this->store->set('example.com', 60, ['foo' => 'asd']);
31
32
        $this->assertEquals(['foo' => 'asd'], $this->store->get('example.com'));
33
    }
34
35
    public function testExpire()
36
    {
37
        $this->store->set('example.com', 3, ['foo' => 'bar']);
38
39
        $this->assertNotFalse($this->store->get('example.com'));
40
41
        sleep(4);
42
43
        $this->assertFalse($this->store->get('example.com'));
44
    }
45
46
    public function testDelete()
47
    {
48
        $this->store->set('example.com', 60, ['foo' => 'bar']);
49
50
        $this->assertNotFalse($this->store->get('example.com'));
51
52
        $this->store->delete('example.com');
53
54
        $this->assertFalse($this->store->get('example.com'));
55
    }
56
}
57