-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: remove Symfony < 4.4.* BC code (#106)
- Loading branch information
1 parent
5d1119e
commit 56e9ea5
Showing
5 changed files
with
18 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,17 +14,15 @@ | |
namespace CoopTilleuls\ForgotPasswordBundle\Event; | ||
|
||
use CoopTilleuls\ForgotPasswordBundle\Entity\AbstractPasswordToken; | ||
use Symfony\Contracts\EventDispatcher\Event; | ||
|
||
/** | ||
* @author Vincent CHALAMON <[email protected]> | ||
* | ||
* @deprecated Use CreateTokenEvent and UpdatePasswordEvent instead | ||
*/ | ||
class ForgotPasswordEvent extends PolyfillEvent | ||
class ForgotPasswordEvent extends Event | ||
{ | ||
public const CREATE_TOKEN = 'coop_tilleuls_forgot_password.create_token'; | ||
public const UPDATE_PASSWORD = 'coop_tilleuls_forgot_password.update_password'; | ||
|
||
protected $passwordToken; | ||
protected $password; | ||
|
||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,11 +15,9 @@ | |
|
||
use CoopTilleuls\ForgotPasswordBundle\Entity\AbstractPasswordToken; | ||
use CoopTilleuls\ForgotPasswordBundle\Event\CreateTokenEvent; | ||
use CoopTilleuls\ForgotPasswordBundle\Event\ForgotPasswordEvent; | ||
use CoopTilleuls\ForgotPasswordBundle\Event\UpdatePasswordEvent; | ||
use CoopTilleuls\ForgotPasswordBundle\Manager\Bridge\ManagerInterface; | ||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface as ContractsEventDispatcherInterface; | ||
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; | ||
|
||
/** | ||
* @author Vincent CHALAMON <[email protected]> | ||
|
@@ -65,11 +63,7 @@ public function resetPassword($propertyName, $value): void | |
} | ||
|
||
// Generate password token | ||
if ($this->dispatcher instanceof ContractsEventDispatcherInterface) { | ||
$this->dispatcher->dispatch(new CreateTokenEvent($token)); | ||
} else { | ||
$this->dispatcher->dispatch(ForgotPasswordEvent::CREATE_TOKEN, new CreateTokenEvent($token)); | ||
} | ||
$this->dispatcher->dispatch(new CreateTokenEvent($token)); | ||
} | ||
|
||
/** | ||
|
@@ -80,11 +74,7 @@ public function resetPassword($propertyName, $value): void | |
public function updatePassword(AbstractPasswordToken $passwordToken, $password) | ||
{ | ||
// Update user password | ||
if ($this->dispatcher instanceof ContractsEventDispatcherInterface) { | ||
$this->dispatcher->dispatch(new UpdatePasswordEvent($passwordToken, $password)); | ||
} else { | ||
$this->dispatcher->dispatch(ForgotPasswordEvent::UPDATE_PASSWORD, new UpdatePasswordEvent($passwordToken, $password)); | ||
} | ||
$this->dispatcher->dispatch(new UpdatePasswordEvent($passwordToken, $password)); | ||
|
||
// Remove PasswordToken | ||
$this->manager->remove($passwordToken); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,17 +15,15 @@ | |
|
||
use CoopTilleuls\ForgotPasswordBundle\Entity\AbstractPasswordToken; | ||
use CoopTilleuls\ForgotPasswordBundle\Event\CreateTokenEvent; | ||
use CoopTilleuls\ForgotPasswordBundle\Event\ForgotPasswordEvent; | ||
use CoopTilleuls\ForgotPasswordBundle\Event\UpdatePasswordEvent; | ||
use CoopTilleuls\ForgotPasswordBundle\Manager\Bridge\ManagerInterface; | ||
use CoopTilleuls\ForgotPasswordBundle\Manager\ForgotPasswordManager; | ||
use CoopTilleuls\ForgotPasswordBundle\Manager\PasswordTokenManager; | ||
use CoopTilleuls\ForgotPasswordBundle\Tests\ProphecyTrait; | ||
use PHPUnit\Framework\TestCase; | ||
use Prophecy\Argument; | ||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
use Symfony\Component\Security\Core\User\UserInterface; | ||
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface as ContractsEventDispatcherInterface; | ||
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; | ||
|
||
/** | ||
* @author Vincent CHALAMON <[email protected]> | ||
|
@@ -77,15 +75,9 @@ public function testResetPasswordWithNoPreviousToken(): void | |
$this->managerMock->findOneBy('App\Entity\User', ['email' => '[email protected]'])->willReturn($this->userMock->reveal())->shouldBeCalledOnce(); | ||
$this->passwordManagerMock->findOneByUser($this->userMock->reveal())->willReturn(null)->shouldBeCalledOnce(); | ||
$this->passwordManagerMock->createPasswordToken($this->userMock->reveal())->willReturn($tokenMock->reveal())->shouldBeCalledOnce(); | ||
if ($this->eventDispatcherMock->reveal() instanceof ContractsEventDispatcherInterface) { | ||
$this->eventDispatcherMock->dispatch(Argument::that(function ($event) use ($tokenMock) { | ||
return $event instanceof CreateTokenEvent && null === $event->getPassword() && $tokenMock->reveal() === $event->getPasswordToken(); | ||
}))->shouldBeCalledOnce(); | ||
} else { | ||
$this->eventDispatcherMock->dispatch(ForgotPasswordEvent::CREATE_TOKEN, Argument::that(function ($event) use ($tokenMock) { | ||
return $event instanceof CreateTokenEvent && null === $event->getPassword() && $tokenMock->reveal() === $event->getPasswordToken(); | ||
}))->shouldBeCalledOnce(); | ||
} | ||
$this->eventDispatcherMock->dispatch(Argument::that(function ($event) use ($tokenMock) { | ||
return $event instanceof CreateTokenEvent && null === $event->getPassword() && $tokenMock->reveal() === $event->getPasswordToken(); | ||
}))->shouldBeCalledOnce(); | ||
|
||
$this->manager->resetPassword('email', '[email protected]'); | ||
} | ||
|
@@ -98,15 +90,9 @@ public function testResetPasswordWithExpiredPreviousToken(): void | |
$this->passwordManagerMock->findOneByUser($this->userMock->reveal())->willReturn($this->tokenMock->reveal())->shouldBeCalledOnce(); | ||
$this->tokenMock->isExpired()->willReturn(true)->shouldBeCalledOnce(); | ||
$this->passwordManagerMock->createPasswordToken($this->userMock->reveal())->willReturn($tokenMock->reveal())->shouldBeCalledOnce(); | ||
if ($this->eventDispatcherMock->reveal() instanceof ContractsEventDispatcherInterface) { | ||
$this->eventDispatcherMock->dispatch(Argument::that(function ($event) use ($tokenMock) { | ||
return $event instanceof CreateTokenEvent && null === $event->getPassword() && $tokenMock->reveal() === $event->getPasswordToken(); | ||
}))->shouldBeCalledOnce(); | ||
} else { | ||
$this->eventDispatcherMock->dispatch(ForgotPasswordEvent::CREATE_TOKEN, Argument::that(function ($event) use ($tokenMock) { | ||
return $event instanceof CreateTokenEvent && null === $event->getPassword() && $tokenMock->reveal() === $event->getPasswordToken(); | ||
}))->shouldBeCalledOnce(); | ||
} | ||
$this->eventDispatcherMock->dispatch(Argument::that(function ($event) use ($tokenMock) { | ||
return $event instanceof CreateTokenEvent && null === $event->getPassword() && $tokenMock->reveal() === $event->getPasswordToken(); | ||
}))->shouldBeCalledOnce(); | ||
|
||
$this->manager->resetPassword('email', '[email protected]'); | ||
} | ||
|
@@ -128,15 +114,9 @@ public function testResetPasswordWithUnexpiredTokenHttp(): void | |
$this->managerMock->findOneBy('App\Entity\User', ['email' => '[email protected]'])->willReturn($this->userMock->reveal())->shouldBeCalledOnce(); | ||
$this->passwordManagerMock->findOneByUser($this->userMock->reveal())->willReturn($token)->shouldBeCalledOnce(); | ||
|
||
if ($this->eventDispatcherMock->reveal() instanceof ContractsEventDispatcherInterface) { | ||
$this->eventDispatcherMock->dispatch(Argument::that(function ($event) use ($token) { | ||
return $event instanceof CreateTokenEvent && null === $event->getPassword() && $token === $event->getPasswordToken(); | ||
}))->shouldBeCalledOnce(); | ||
} else { | ||
$this->eventDispatcherMock->dispatch(ForgotPasswordEvent::CREATE_TOKEN, Argument::that(function ($event) use ($token) { | ||
return $event instanceof CreateTokenEvent && null === $event->getPassword() && $token === $event->getPasswordToken(); | ||
}))->shouldBeCalledOnce(); | ||
} | ||
$this->eventDispatcherMock->dispatch(Argument::that(function ($event) use ($token) { | ||
return $event instanceof CreateTokenEvent && null === $event->getPassword() && $token === $event->getPasswordToken(); | ||
}))->shouldBeCalledOnce(); | ||
|
||
$this->manager->resetPassword('email', '[email protected]'); | ||
} | ||
|
@@ -145,15 +125,9 @@ public function testUpdatePassword(): void | |
{ | ||
$token = $this->tokenMock->reveal(); | ||
|
||
if ($this->eventDispatcherMock->reveal() instanceof ContractsEventDispatcherInterface) { | ||
$this->eventDispatcherMock->dispatch(Argument::that(function ($event) use ($token) { | ||
return $event instanceof UpdatePasswordEvent && 'bar' === $event->getPassword() && $token === $event->getPasswordToken(); | ||
}))->shouldBeCalledOnce(); | ||
} else { | ||
$this->eventDispatcherMock->dispatch(ForgotPasswordEvent::UPDATE_PASSWORD, Argument::that(function ($event) use ($token) { | ||
return $event instanceof UpdatePasswordEvent && 'bar' === $event->getPassword() && $token === $event->getPasswordToken(); | ||
}))->shouldBeCalledOnce(); | ||
} | ||
$this->eventDispatcherMock->dispatch(Argument::that(function ($event) use ($token) { | ||
return $event instanceof UpdatePasswordEvent && 'bar' === $event->getPassword() && $token === $event->getPasswordToken(); | ||
}))->shouldBeCalledOnce(); | ||
$this->managerMock->remove($token)->shouldBeCalledOnce(); | ||
|
||
$this->manager->updatePassword($token, 'bar'); | ||
|