Commit d1ebe163 authored by Dominique Merle's avatar Dominique Merle 💬
Browse files

Implement a step allowing to create moderators.

Showing how we can also use `Application` to expose non-public services
to the feature suite, allowing us to do pretty much anything.
parent 0d88341a
......@@ -9,6 +9,7 @@
use App\Entity\LimajuPoll;
use App\Entity\LimajuPollOption;
use App\Entity\User;
use MsgPhp\User\Command\AddUserRole;
/**
......@@ -60,6 +61,25 @@ class MainFeatureContext extends BaseFeatureContext
}
/**
* @Given /^a moderator named (?P<name>.+)$/ui
* @Given /^un(?:⋅?e)? modérat(?:eur[⋅.]?e?|rice)(?: .*?)? (?:sur)?nommé(?:⋅?e)? (?P<name>.+)$/ui
*/
public function givenModeratorNamed($name)
{
$userAndToken = $this->createUser($name);
$actor = $this->actor($name, true);
$actor->setUser($userAndToken['user']);
$actor->setPassword($userAndToken['token']);
$userId = $actor->getUser()->getId();
$roleName = 'ROLE_ADMIN';
$context = [];
$this->app()->getMessageBus()->dispatch(new AddUserRole($userId, $roleName, $context));
}
/**
* @Given /^un scrutin au jugement majoritaire comme suit:$/u
* @Given /^a majority judgment poll like so:$/u
......@@ -111,7 +131,7 @@ class MainFeatureContext extends BaseFeatureContext
/**
* @Then /^there should(?: now)?(?: still)?(?: only)? be (?P<thatMuch>.+) majority judgment polls? in the database$/ui
* @Then /^(?:qu')?il(?: ne)? d(?:oi|evrai)t(?: maintenant)?(?: encore)? y avoir (?P<thatMuch>.+) scrutins? au jugement majoritaire dans la base de données$/ui
* @Then /^(?:qu')?il(?: ne)? d(?:oi|evrai)t(?: maintenant)?(?: encore)? y avoir (?P<thatMuch>.+) scrutins?(?: au jugement majoritaire)? dans la base de données$/ui
*/
public function thereShouldBeSomeLimajuPollsInTheDatabase($thatMuch)
{
......
......@@ -9,6 +9,7 @@ use App\Entity\User;
use Doctrine\ORM\EntityManagerInterface;
use MsgPhp\User\Infrastructure\Security\UserIdentity;
use MsgPhp\User\Repository\UserRepository;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Security\Core\Security;
......@@ -48,6 +49,11 @@ class Application
*/
protected $iriConverter;
/**
* @var MessageBusInterface
*/
private $messageBus;
/**
* Application constructor.
* This is going to get almost ALL services. Smelly smelly!
......@@ -61,13 +67,15 @@ class Application
Security $security,
EntityManagerInterface $entityManager,
UserRepository $userRepository,
IriConverterInterface $iriConverter
IriConverterInterface $iriConverter,
MessageBusInterface $messageBus
)
{
$this->security = $security;
$this->entityManager = $entityManager;
$this->iriConverter = $iriConverter;
$this->userRepository = $userRepository;
$this->messageBus = $messageBus;
}
......@@ -108,4 +116,13 @@ class Application
return $this->getIriConverter()->getIriFromItem($item);
}
/**
* @return MessageBusInterface
*/
public function getMessageBus(): MessageBusInterface
{
return $this->messageBus;
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment