ReplayProtection::wrongCases()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace Rezzza\SecurityBundle\Tests\Units\Security\Firewall;
4
5
use mageekguy\atoum;
6
7
use Rezzza\SecurityBundle\Security\Firewall\ReplayProtection as SUT;
8
9
class ReplayProtection extends atoum\test
10
{
11
    public function test_lifetime_attribute_should_be_a_numeric()
12
    {
13
        $this
0 ignored issues
show
Bug introduced by
The method exception() does not exist on Rezzza\SecurityBundle\Te...rewall\ReplayProtection. Did you maybe mean addExceptionToScore()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
14
            ->exception(function () {
15
                $sut = new SUT(false, '2 seconds');
0 ignored issues
show
Unused Code introduced by
$sut is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
16
            })
17
                ->hasMessage('ReplayProtection lifetime should be a numeric value')
18
        ;
19
    }
20
21
    /**
22
     * @dataProvider dummyCases
23
     */
24 View Code Duplication
    public function test_disabled_state_should_accept_all_signatureTime($lifetime, $signatureTime, $currentTime)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
25
    {
26
        $this
0 ignored issues
show
Documentation Bug introduced by
The method given does not exist on object<Rezzza\SecurityBu...ewall\ReplayProtection>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
27
            ->given(
28
                $sut = new SUT(false, $lifetime)
29
            )
30
            ->when(
31
                $accepted = $sut->accept($signatureTime, $currentTime)
32
            )
33
            ->then
34
                ->boolean($accepted)
35
                    ->isTrue()
36
        ;
37
    }
38
39
    public function dummyCases()
40
    {
41
        return array(
42
            array(0, 'mlsjmsdjf', 1234),
43
            array(600, 1234, 'llskfsmldf'),
44
            array(100, 123456789, 9876543)
45
        );
46
    }
47
48
    /**
49
     * @dataProvider goodCases
50
     */
51 View Code Duplication
    public function test_it_should_accept_signatureTime_still_valid($lifetime, $signatureTime, $currentTime)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
52
    {
53
        $this
0 ignored issues
show
Documentation Bug introduced by
The method given does not exist on object<Rezzza\SecurityBu...ewall\ReplayProtection>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
54
            ->given(
55
                $sut = new SUT(true, $lifetime)
56
            )
57
            ->when(
58
                $accepted = $sut->accept($signatureTime, $currentTime)
59
            )
60
            ->then
61
                ->boolean($accepted)
62
                    ->isTrue()
63
        ;
64
    }
65
66
    public function goodCases()
67
    {
68
        return array(
69
            array(10, 1417626128, 1417626138),
70
            array(500, 1417626100, 1417626250),
71
            array(500, 1417626100, 1417626099),
72
            array(555, 1417626111, 1417626111)
73
        );
74
    }
75
76
    /**
77
     * @dataProvider wrongCases
78
     */
79 View Code Duplication
    public function test_it_should_not_accept_signatureTime_expired($lifetime, $signatureTime, $currentTime)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
80
    {
81
        $this
0 ignored issues
show
Documentation Bug introduced by
The method given does not exist on object<Rezzza\SecurityBu...ewall\ReplayProtection>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
82
            ->given(
83
                $sut = new SUT(true, $lifetime)
84
            )
85
            ->when(
86
                $accepted = $sut->accept($signatureTime, $currentTime)
87
            )
88
            ->then
89
                ->boolean($accepted)
90
                    ->isFalse()
91
        ;
92
    }
93
94
    public function wrongCases()
95
    {
96
        return array(
97
            array(10, 1417626128, 1417626139),
98
            array(500, 1417626100, 1417625100),
99
            array(555, 1417626111, 1417626679)
100
        );
101
    }
102
}
103