Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ default:
- 'Test\Specification\Authentication\AuthenticationContext'
paths:
- 'feature/authentication.feature'
authentication-ui:
contexts:
- 'Test\E2E\Authentication\AuthenticationContext'
paths:
- 'feature/authentication.feature'
blog-post:
contexts:
- 'Test\Specification\Blog\BlogPostContext'
Expand Down
79 changes: 79 additions & 0 deletions test/Specification/Authentication/AuthenticationContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,87 @@

namespace Test\Specification\Authentication;

use Authentication\Aggregate\User;
use Authentication\ReadModel\EmailIsRegistered;
use Authentication\ReadModel\IsUserBlocked;
use Authentication\Service\NotifyOfIntrusionDetection;
use Authentication\Value\ClearTextPassword;
use Authentication\Value\EmailAddress;
use Behat\Behat\Context\Context;
use Behat\Behat\Tester\Exception\PendingException;

final class AuthenticationContext implements Context
{
/** @var EmailIsRegistered|null */
private $emailIsRegistered;

/** @var User|null */
private $user;

/**
* @Given /^there are no registered users$/
*/
public function thereAreNoRegisteredUsers() : void
{
$this->emailIsRegistered = new class implements EmailIsRegistered
{
public function __invoke(EmailAddress $emailAddress) : bool
{
return false;
}
};
}

/**
* @When /^a user registers with the website$/
*/
public function aUserRegistersWithTheWebsite() : void
{
\assert(null !== $this->emailIsRegistered);

$this->user = User::register(
EmailAddress::fromEmailAddress('[email protected]'),
ClearTextPassword::fromInputPassword('potato'),
$this->emailIsRegistered
);
}

/**
* @Then /^the user can log into the website$/
*/
public function theUserCanLogIntoTheWebsite() : void
{
\assert(null !== $this->user);

$this->user->authenticate(
ClearTextPassword::fromInputPassword('potato'),
new class implements IsUserBlocked {
public function __invoke(EmailAddress $emailAddress) : bool
{
return false;
}
},
new class implements NotifyOfIntrusionDetection {
public function __invoke(EmailAddress $emailAddress) : void
{
}
}
);
}

/**
* @Given /^there is a registered user$/
*/
public function thereIsARegisteredUser() : void
{
throw new PendingException();
}

/**
* @Then /^the user cannot log into the website with a non\-matching password$/
*/
public function theUserCannotLogIntoTheWebsiteWithANonMatchingPassword() : void
{
throw new PendingException();
}
}