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\AdminLocaleListener; |
||
7 | use Kunstmaan\AdminBundle\Helper\AdminRouteHelper; |
||
8 | use PHPUnit\Framework\TestCase; |
||
9 | use Symfony\Component\HttpFoundation\Request; |
||
10 | use Symfony\Component\HttpKernel\Event\GetResponseEvent; |
||
11 | use Symfony\Component\HttpKernel\KernelEvents; |
||
12 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
||
13 | use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; |
||
14 | use Symfony\Component\Translation\TranslatorInterface; |
||
15 | |||
16 | class AdminLocaleListenerTest extends TestCase |
||
17 | { |
||
18 | public function testListener() |
||
19 | { |
||
20 | $request = new Request([], [], [], [], [], ['REQUEST_URI' => '/en/admin/']); |
||
21 | $storage = $this->createMock(TokenStorageInterface::class); |
||
22 | $trans = $this->createMock(TranslatorInterface::class); |
||
23 | $adminRouteHelper = $this->createMock(AdminRouteHelper::class); |
||
24 | $event = $this->createMock(GetResponseEvent::class); |
||
25 | $token = $this->createMock(UsernamePasswordToken::class); |
||
26 | $user = $this->createMock(User::class); |
||
27 | |||
28 | $storage->expects($this->exactly(3))->method('getToken')->willReturn($token); |
||
29 | $token->expects($this->exactly(3))->method('getProviderKey')->willReturn('main'); |
||
30 | $token->expects($this->once())->method('getUser')->willReturn($user); |
||
31 | $event->expects($this->any())->method('getRequest')->willReturn($request); |
||
32 | $user->expects($this->once())->method('getAdminLocale')->willReturn(null); |
||
33 | $trans->expects($this->once())->method('setLocale')->willReturn(null); |
||
34 | $adminRouteHelper->method('isAdminRoute')->will($this->returnValueMap([['/en/admin/', true], ['/en/whatever/', false], ['/en/admin/preview/', false]])); |
||
35 | |||
36 | $listener = new AdminLocaleListener($storage, $trans, $adminRouteHelper, 'en'); |
||
0 ignored issues
–
show
$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...
|
|||
37 | |||
38 | $events = AdminLocaleListener::getSubscribedEvents(); |
||
39 | $this->assertArrayHasKey(KernelEvents::REQUEST, $events); |
||
40 | |||
41 | $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...
|
|||
42 | |||
43 | $request = $request->duplicate([], [], [], [], [], ['REQUEST_URI' => '/en/whatever/']); |
||
44 | $event = $this->createMock(GetResponseEvent::class); |
||
45 | $event->expects($this->any())->method('getRequest')->willReturn($request); |
||
46 | |||
47 | $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...
|
|||
48 | |||
49 | $request = $request->duplicate([], [], [], [], [], ['REQUEST_URI' => '/en/admin/preview/']); |
||
50 | $event = $this->createMock(GetResponseEvent::class); |
||
51 | $event->expects($this->any())->method('getRequest')->willReturn($request); |
||
52 | |||
53 | $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...
|
|||
54 | } |
||
55 | } |
||
56 |
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: