Skip to content

Commit abd3534

Browse files
committed
Fix remaining event dispatching missed in the migration
1 parent 3c0d934 commit abd3534

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
/**
@@ -49,7 +51,7 @@ class UserManipulator
4951
public function __construct(UserManagerInterface $userManager, EventDispatcherInterface $dispatcher, RequestStack $requestStack)
5052
{
5153
$this->userManager = $userManager;
52-
$this->dispatcher = $dispatcher;
54+
$this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher);
5355
$this->requestStack = $requestStack;
5456
}
5557

@@ -75,7 +77,7 @@ public function create($username, $password, $email, $active, $superadmin)
7577
$this->userManager->updateUser($user);
7678

7779
$event = new UserEvent($user, $this->getRequest());
78-
$this->dispatcher->dispatch(FOSUserEvents::USER_CREATED, $event);
80+
$this->dispatcher->dispatch($event, FOSUserEvents::USER_CREATED);
7981

8082
return $user;
8183
}
@@ -92,7 +94,7 @@ public function activate($username)
9294
$this->userManager->updateUser($user);
9395

9496
$event = new UserEvent($user, $this->getRequest());
95-
$this->dispatcher->dispatch(FOSUserEvents::USER_ACTIVATED, $event);
97+
$this->dispatcher->dispatch($event, FOSUserEvents::USER_ACTIVATED);
9698
}
9799

98100
/**
@@ -107,7 +109,7 @@ public function deactivate($username)
107109
$this->userManager->updateUser($user);
108110

109111
$event = new UserEvent($user, $this->getRequest());
110-
$this->dispatcher->dispatch(FOSUserEvents::USER_DEACTIVATED, $event);
112+
$this->dispatcher->dispatch($event, FOSUserEvents::USER_DEACTIVATED);
111113
}
112114

113115
/**
@@ -123,7 +125,7 @@ public function changePassword($username, $password)
123125
$this->userManager->updateUser($user);
124126

125127
$event = new UserEvent($user, $this->getRequest());
126-
$this->dispatcher->dispatch(FOSUserEvents::USER_PASSWORD_CHANGED, $event);
128+
$this->dispatcher->dispatch($event, FOSUserEvents::USER_PASSWORD_CHANGED);
127129
}
128130

129131
/**
@@ -138,7 +140,7 @@ public function promote($username)
138140
$this->userManager->updateUser($user);
139141

140142
$event = new UserEvent($user, $this->getRequest());
141-
$this->dispatcher->dispatch(FOSUserEvents::USER_PROMOTED, $event);
143+
$this->dispatcher->dispatch($event, FOSUserEvents::USER_PROMOTED);
142144
}
143145

144146
/**
@@ -153,7 +155,7 @@ public function demote($username)
153155
$this->userManager->updateUser($user);
154156

155157
$event = new UserEvent($user, $this->getRequest());
156-
$this->dispatcher->dispatch(FOSUserEvents::USER_DEMOTED, $event);
158+
$this->dispatcher->dispatch($event, FOSUserEvents::USER_DEMOTED);
157159
}
158160

159161
/**
@@ -217,7 +219,7 @@ private function findUserByUsernameOrThrowException($username)
217219
}
218220

219221
/**
220-
* @return Request
222+
* @return Request|null
221223
*/
222224
private function getRequest()
223225
{

0 commit comments

Comments
 (0)