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
|
|||
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
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
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
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
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 |
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:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: