Completed
Push — master ( aba493...5356ed )
by Ruud
315:38 queued 305:00
created

unit/EventListener/PasswordCheckListenerTest.php (9 issues)

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
namespace Kunstmaan\AdminBundle\Tests\EventListener;
4
5
use Kunstmaan\AdminBundle\Entity\User;
6
use Kunstmaan\AdminBundle\EventListener\PasswordCheckListener;
7
use Kunstmaan\AdminBundle\Helper\AdminRouteHelper;
8
use PHPUnit\Framework\TestCase;
9
use Symfony\Component\HttpFoundation\Request;
10
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
11
use Symfony\Component\HttpFoundation\Session\Session;
12
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
13
use Symfony\Component\Routing\RouterInterface;
14
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
15
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
16
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
17
use Symfony\Component\Translation\Translator;
18
19
class PasswordCheckListenerTest extends TestCase
20
{
21
    public function testListener()
22
    {
23
        $request = new Request([], [], [], [], [], ['REQUEST_URI' => '/en/admin/']);
24
        $auth = $this->createMock(AuthorizationCheckerInterface::class);
25
        $storage = $this->createMock(TokenStorageInterface::class);
26
        $token = $this->createMock(UsernamePasswordToken::class);
27
        $user = $user = $this->createMock(User::class);
28
        $router = $this->createMock(RouterInterface::class);
29
        $session = $this->createMock(Session::class);
30
        $flash = $this->createMock(FlashBag::class);
31
        $trans = $this->createMock(Translator::class);
32
        $adminRouteHelper = $this->createMock(AdminRouteHelper::class);
33
        $event = $this->createMock(GetResponseEvent::class);
34
35
        $event->expects($this->exactly(2))->method('getRequest')->willReturn($request);
36
        $storage->expects($this->exactly(4))->method('getToken')->willReturn($token);
37
        $auth->expects($this->exactly(1))->method('isGranted')->willReturn(true);
38
        $token->expects($this->exactly(1))->method('getUser')->willReturn($user);
39
        $user->expects($this->exactly(1))->method('isPasswordChanged')->willReturn(false);
40
        $router->expects($this->exactly(1))->method('generate')->willReturn(true);
41
        $session->expects($this->exactly(1))->method('getFlashBag')->willReturn($flash);
42
        $flash->expects($this->exactly(1))->method('add')->willReturn(true);
43
        $trans->expects($this->exactly(1))->method('trans')->willReturn(true);
44
        $adminRouteHelper->method('isAdminRoute')->will($this->returnValueMap([
45
            ['/en/admin/', true],
46
            ['/en/random', false],
47
            ['/en/admin/preview/', false],
48
        ]));
49
50
        $listener = new PasswordCheckListener($auth, $storage, $router, $session, $trans, $adminRouteHelper);
0 ignored issues
show
$auth is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...zationCheckerInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
$storage is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...\TokenStorageInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
$router is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component\Routing\RouterInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
$session is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...dation\Session\Session>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
$trans is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...on\TranslatorInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
$adminRouteHelper is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Kunstmaan\AdminBu...elper\AdminRouteHelper>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
51
        $listener->onKernelRequest($event);
0 ignored issues
show
$event is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...Event\GetResponseEvent>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
52
53
        $request = $request->duplicate([], [], [], [], [], ['REQUEST_URI' => '/en/random']);
54
        $event = $this->createMock(GetResponseEvent::class);
55
        $event->expects($this->any())->method('getRequest')->willReturn($request);
56
57
        $listener->onKernelRequest($event);
0 ignored issues
show
$event is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...Event\GetResponseEvent>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
58
59
        $request = $request->duplicate([], [], [], [], [], ['REQUEST_URI' => '/en/admin/preview/']);
60
        $event = $this->createMock(GetResponseEvent::class);
61
        $event->expects($this->any())->method('getRequest')->willReturn($request);
62
63
        $listener->onKernelRequest($event);
0 ignored issues
show
$event is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...Event\GetResponseEvent>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
64
    }
65
}
66