Skip to content

Commit 246e7ba

Browse files
authored
Merge pull request #3011 from stof/fix_event_migration
Fix remaining event dispatching missed in the migration
2 parents 4842949 + abd3534 commit 246e7ba

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

Tests/Util/UserManipulatorTest.php

+8-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
use FOS\UserBundle\FOSUserEvents;
1515
use FOS\UserBundle\Tests\TestUser;
1616
use FOS\UserBundle\Util\UserManipulator;
17+
use PHPUnit\Framework\MockObject\MockObject;
1718
use PHPUnit\Framework\TestCase;
19+
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
20+
use Symfony\Component\HttpFoundation\RequestStack;
1821

1922
class UserManipulatorTest extends TestCase
2023
{
@@ -371,27 +374,27 @@ public function testRemoveRole()
371374
* @param string $event
372375
* @param bool $once
373376
*
374-
* @return \PHPUnit_Framework_MockObject_MockObject
377+
* @return MockObject&EventDispatcherInterface
375378
*/
376379
protected function getEventDispatcherMock($event, $once = true)
377380
{
378-
$eventDispatcherMock = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock();
381+
$eventDispatcherMock = $this->getMockBuilder(EventDispatcherInterface::class)->getMock();
379382

380383
$eventDispatcherMock->expects($once ? $this->once() : $this->never())
381384
->method('dispatch')
382-
->with($event);
385+
->with($this->anything(), $event);
383386

384387
return $eventDispatcherMock;
385388
}
386389

387390
/**
388391
* @param bool $once
389392
*
390-
* @return \PHPUnit_Framework_MockObject_MockObject
393+
* @return MockObject&RequestStack
391394
*/
392395
protected function getRequestStackMock($once = true)
393396
{
394-
$requestStackMock = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->getMock();
397+
$requestStackMock = $this->getMockBuilder(RequestStack::class)->getMock();
395398

396399
$requestStackMock->expects($once ? $this->once() : $this->never())
397400
->method('getCurrentRequest')

Util/UserManipulator.php

+10-8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
use FOS\UserBundle\Model\UserInterface;
1717
use FOS\UserBundle\Model\UserManagerInterface;
1818
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
19+
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
20+
use Symfony\Component\HttpFoundation\Request;
1921
use Symfony\Component\HttpFoundation\RequestStack;
2022

2123
/**
@@ -52,7 +54,7 @@ class UserManipulator
5254
public function __construct(UserManagerInterface $userManager, EventDispatcherInterface $dispatcher, RequestStack $requestStack)
5355
{
5456
$this->userManager = $userManager;
55-
$this->dispatcher = $dispatcher;
57+
$this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher);
5658
$this->requestStack = $requestStack;
5759
}
5860

@@ -78,7 +80,7 @@ public function create($username, $password, $email, $active, $superadmin)
7880
$this->userManager->updateUser($user);
7981

8082
$event = new UserEvent($user, $this->getRequest());
81-
$this->dispatcher->dispatch(FOSUserEvents::USER_CREATED, $event);
83+
$this->dispatcher->dispatch($event, FOSUserEvents::USER_CREATED);
8284

8385
return $user;
8486
}
@@ -95,7 +97,7 @@ public function activate($username)
9597
$this->userManager->updateUser($user);
9698

9799
$event = new UserEvent($user, $this->getRequest());
98-
$this->dispatcher->dispatch(FOSUserEvents::USER_ACTIVATED, $event);
100+
$this->dispatcher->dispatch($event, FOSUserEvents::USER_ACTIVATED);
99101
}
100102

101103
/**
@@ -110,7 +112,7 @@ public function deactivate($username)
110112
$this->userManager->updateUser($user);
111113

112114
$event = new UserEvent($user, $this->getRequest());
113-
$this->dispatcher->dispatch(FOSUserEvents::USER_DEACTIVATED, $event);
115+
$this->dispatcher->dispatch($event, FOSUserEvents::USER_DEACTIVATED);
114116
}
115117

116118
/**
@@ -126,7 +128,7 @@ public function changePassword($username, $password)
126128
$this->userManager->updateUser($user);
127129

128130
$event = new UserEvent($user, $this->getRequest());
129-
$this->dispatcher->dispatch(FOSUserEvents::USER_PASSWORD_CHANGED, $event);
131+
$this->dispatcher->dispatch($event, FOSUserEvents::USER_PASSWORD_CHANGED);
130132
}
131133

132134
/**
@@ -141,7 +143,7 @@ public function promote($username)
141143
$this->userManager->updateUser($user);
142144

143145
$event = new UserEvent($user, $this->getRequest());
144-
$this->dispatcher->dispatch(FOSUserEvents::USER_PROMOTED, $event);
146+
$this->dispatcher->dispatch($event, FOSUserEvents::USER_PROMOTED);
145147
}
146148

147149
/**
@@ -156,7 +158,7 @@ public function demote($username)
156158
$this->userManager->updateUser($user);
157159

158160
$event = new UserEvent($user, $this->getRequest());
159-
$this->dispatcher->dispatch(FOSUserEvents::USER_DEMOTED, $event);
161+
$this->dispatcher->dispatch($event, FOSUserEvents::USER_DEMOTED);
160162
}
161163

162164
/**
@@ -220,7 +222,7 @@ private function findUserByUsernameOrThrowException($username)
220222
}
221223

222224
/**
223-
* @return Request
225+
* @return Request|null
224226
*/
225227
private function getRequest()
226228
{

0 commit comments

Comments
 (0)