AttemptsCounterTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 70
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testAddActionOverwrite() 0 7 1
A prepare() 0 3 1
A testGetActionNonexistent() 0 9 2
A testAddActionAndGetAction() 0 5 1
A testAddActionNoOverwrite() 0 7 1
1
<?php
2
3
namespace kdn\attemptsCounter;
4
5
/**
6
 * Class AttemptsCounterTest.
7
 * @package kdn\attemptsCounter
8
 * @uses \kdn\attemptsCounter\Action
9
 */
10
class AttemptsCounterTest extends TestCase
11
{
12
    /**
13
     * @var AttemptsCounter
14
     */
15
    protected $counter;
16
17
    /**
18
     * @before
19
     */
20
    protected function prepare()
21
    {
22
        $this->counter = new AttemptsCounter();
23
    }
24
25
    /**
26
     * @covers \kdn\attemptsCounter\AttemptsCounter::addAction
27
     * @covers \kdn\attemptsCounter\AttemptsCounter::getAction
28
     * @small
29
     */
30
    public function testAddActionAndGetAction()
31
    {
32
        $actionName = 'foo';
33
        $action = new Action($actionName, 1);
34
        $this->assertSame($action, $this->counter->addAction($action)->getAction($actionName));
35
    }
36
37
    /**
38
     * @covers \kdn\attemptsCounter\AttemptsCounter::addAction
39
     * @covers \kdn\attemptsCounter\AttemptsCounter::getAction
40
     * @small
41
     */
42
    public function testAddActionOverwrite()
43
    {
44
        $actionName = 'foo';
45
        $action = new Action($actionName, 1);
46
        $this->assertSame(
47
            $action,
48
            $this->counter->addAction((new Action($actionName, 2)))->addAction($action)->getAction($actionName)
49
        );
50
    }
51
52
    /**
53
     * @covers \kdn\attemptsCounter\AttemptsCounter::addAction
54
     * @covers \kdn\attemptsCounter\AttemptsCounter::getAction
55
     * @small
56
     */
57
    public function testAddActionNoOverwrite()
58
    {
59
        $actionName = 'foo';
60
        $action = new Action($actionName, 1);
61
        $this->assertSame(
62
            $action,
63
            $this->counter->addAction($action)->addAction((new Action($actionName, 2)), false)->getAction($actionName)
64
        );
65
    }
66
67
    /**
68
     * @covers \kdn\attemptsCounter\AttemptsCounter::getAction
69
     * @small
70
     */
71
    public function testGetActionNonexistent()
72
    {
73
        $actualErrorMessage = null;
74
        try {
75
            $this->counter->getAction('baz');
76
        } catch (Exception $e) {
77
            $actualErrorMessage = $e->getMessage();
78
        }
79
        $this->assertEquals('Unknown action name "baz" specified.', $actualErrorMessage);
80
    }
81
}
82