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
Push — master ( 20f11e...3e0ce4 )
by
unknown
13s queued 10s
created

tests/Provider/SessionTimeProviderTest.php (5 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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 DateTime;
14
use PHPUnit\Framework\TestCase;
15
use Prophecy\Argument;
16
use Prophecy\Prophecy\ObjectProphecy;
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());
0 ignored issues
show
The method reveal does only exist in Prophecy\Prophecy\ObjectProphecy, but not in Symfony\Component\HttpFoundation\Session\Session.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
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());
0 ignored issues
show
The method reveal does only exist in Prophecy\Prophecy\ObjectProphecy, but not in Symfony\Component\HttpFoundation\Session\Session.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
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());
0 ignored issues
show
The method reveal does only exist in Prophecy\Prophecy\ObjectProphecy, but not in Symfony\Component\HttpFoundation\Session\Session.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
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());
0 ignored issues
show
The method reveal does only exist in Prophecy\Prophecy\ObjectProphecy, but not in Symfony\Component\HttpFoundation\Session\Session.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
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());
0 ignored issues
show
The method reveal does only exist in Prophecy\Prophecy\ObjectProphecy, but not in Symfony\Component\HttpFoundation\Session\Session.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
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
    /**
107
     * @return ObjectProphecy|Session
108
     */
109
    private function prepareValidSessionKey()
110
    {
111
        $session = $this->prophesize(Session::class);
112
        $session->has('antispam_foobar')
113
            ->willReturn(true)
114
        ;
115
        $session->get('antispam_foobar')
116
            ->willReturn(new DateTime('- 15 seconds'))
117
        ;
118
119
        return $session;
120
    }
121
}
122