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
Pull Request — master (#13)
by Christian
01:36
created

testRemoveFormProtection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * (c) Christian Gripp <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Core23\AntiSpamBundle\Tests\Provider;
11
12
use Core23\AntiSpamBundle\Provider\SessionTimeProvider;
13
use Core23\AntiSpamBundle\Provider\TimeProviderInterface;
14
use DateTime;
15
use PHPUnit\Framework\TestCase;
16
use Prophecy\Argument;
17
use Symfony\Component\HttpFoundation\Session\Session;
18
19
final class SessionTimeProviderTest extends TestCase
20
{
21
    public function testCreateFromString(): void
22
    {
23
        $session = $this->prophesize(Session::class);
24
        $session->set('antispam_foobar', Argument::type(DateTime::class))
25
            ->shouldBeCalled()
26
        ;
27
28
        $provider = new SessionTimeProvider($session->reveal());
29
        $provider->createFormProtection('foobar');
30
    }
31
32
    public function testIsValid(): void
33
    {
34
        $session  = $this->prepareValidSessionKey();
35
36
        $provider = new SessionTimeProvider($session->reveal());
37
38
        static::assertTrue($provider->isValid('foobar', []));
39
    }
40
41
    public function testIsValidWithMinTime(): void
42
    {
43
        $session  = $this->prepareValidSessionKey();
44
45
        $provider = new SessionTimeProvider($session->reveal());
46
47
        static::assertTrue($provider->isValid('foobar', [
48
            'min' => 10,
49
        ]));
50
    }
51
52
    public function testIsValidWithMaxTime(): void
53
    {
54
        $session  = $this->prepareValidSessionKey();
55
56
        $provider = new SessionTimeProvider($session->reveal());
57
58
        static::assertTrue($provider->isValid('foobar', [
59
            'max' => 60,
60
        ]));
61
    }
62
63
    public function testIsInvalid(): void
64
    {
65
        $session = $this->prophesize(Session::class);
66
        $session->has('antispam_foobar')
67
            ->willReturn(false)
68
        ;
69
70
        $provider = new SessionTimeProvider($session->reveal());
71
72
        static::assertFalse($provider->isValid('foobar', []));
73
    }
74
75
    public function testIsInvalidBecauseOfMinTime(): void
76
    {
77
        $session  = $this->prepareValidSessionKey();
78
79
        $provider = new SessionTimeProvider($session->reveal());
80
        static::assertFalse($provider->isValid('foobar', [
81
            'min' => 60,
82
        ]));
83
    }
84
85
    public function testIsInvalidBecauseOfMaxTime(): void
86
    {
87
        $session  = $this->prepareValidSessionKey();
88
        $provider = new SessionTimeProvider($session->reveal());
89
90
        static::assertFalse($provider->isValid('foobar', [
91
            'max' => 10,
92
        ]));
93
    }
94
95
    public function testRemoveFormProtection(): void
96
    {
97
        $session = $this->prophesize(Session::class);
98
        $session->remove('antispam_foobar')
99
            ->shouldBeCalled()
100
        ;
101
102
        $provider = new SessionTimeProvider($session->reveal());
103
        $provider->removeFormProtection('foobar');
104
    }
105
106
    private function prepareValidSessionKey()
107
    {
108
        $session = $this->prophesize(Session::class);
109
        $session->has('antispam_foobar')
110
            ->willReturn(true)
111
        ;
112
        $session->get('antispam_foobar')
113
            ->willReturn(new DateTime('- 15 seconds'))
114
        ;
115
116
        return $session;
117
    }
118
}
119