Skip to content

Commit

Permalink
Merge pull request #9428 from pamil/sf4-moar
Browse files Browse the repository at this point in the history
Symfony 4: Behat scenarios isolation + random fixes
  • Loading branch information
pamil committed May 26, 2018
2 parents 18522aa + 100d6e7 commit d74f626
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 46 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -80,7 +80,7 @@
"friends-of-behat/context-service-extension": "^1.2",
"friends-of-behat/cross-container-extension": "^1.1",
"friends-of-behat/service-container-extension": "^1.0",
"friends-of-behat/symfony-extension": "^1.1",
"friends-of-behat/symfony-extension": "^1.2.1",
"friends-of-behat/variadic-extension": "^1.1",
"hwi/oauth-bundle": "^0.6",
"lakion/api-test-case": "^3.0",
Expand Down
Expand Up @@ -28,7 +28,7 @@ prepare_for_behat_with_js() {
run_command "java -Dwebdriver.chrome.driver=$SYLIUS_CACHE_DIR/chromedriver -jar $SYLIUS_CACHE_DIR/selenium.jar > /dev/null 2>&1 &"

# Run webserver
run_command "bin/console server:run 127.0.0.1:8080 --env=test_cached --router=app/config/router_test_cached.php --no-debug --quiet > /dev/null 2>&1 &"
run_command "bin/console server:run 127.0.0.1:8080 --env=test_cached --docroot=web --router=app/config/router_test_cached.php --no-debug --quiet > /dev/null 2>&1 &"
}

run_behat() {
Expand Down
51 changes: 13 additions & 38 deletions src/Sylius/Behat/Context/Cli/InstallerContext.php
Expand Up @@ -38,12 +38,7 @@ final class InstallerContext implements Context
* @var CommandTester
*/
private $tester;

/**
* @var QuestionHelper
*/
private $questionHelper;


/**
* @var SetupCommand
*/
Expand Down Expand Up @@ -71,7 +66,7 @@ public function __construct(KernelInterface $kernel)
/**
* @When I run Sylius CLI installer
*/
public function iRunSyliusCommandLineInstaller()
public function iRunSyliusCommandLineInstaller(): void
{
$this->application = new Application($this->kernel);
$this->application->add(new SetupCommand());
Expand All @@ -85,7 +80,7 @@ public function iRunSyliusCommandLineInstaller()
/**
* @Given I run Sylius Install Load Sample Data command
*/
public function iRunSyliusInstallSampleDataCommand()
public function iRunSyliusInstallSampleDataCommand(): void
{
$this->application = new Application($this->kernel);
$this->application->add(new InstallSampleDataCommand());
Expand All @@ -96,78 +91,61 @@ public function iRunSyliusInstallSampleDataCommand()
/**
* @Given I confirm loading sample data
*/
public function iConfirmLoadingData()
public function iConfirmLoadingData(): void
{
$this->iExecuteCommandAndConfirm('sylius:install:sample-data');
}

/**
* @Then the command should finish successfully
*/
public function commandSuccess()
public function commandSuccess(): void
{
Assert::same($this->tester->getStatusCode(), 0);
}

/**
* @Then I should see output :text
*/
public function iShouldSeeOutput($text)
public function iShouldSeeOutput(string $text): void
{
Assert::contains($this->tester->getDisplay(), $text);
}

/**
* @Given I do not provide an email
*/
public function iDoNotProvideEmail()
public function iDoNotProvideEmail(): void
{
$this->inputChoices['e-mail'] = '';
}

/**
* @Given I do not provide a correct email
*/
public function iDoNotProvideCorrectEmail()
public function iDoNotProvideCorrectEmail(): void
{
$this->inputChoices['e-mail'] = 'janusz';
}

/**
* @Given I provide full administrator data
*/
public function iProvideFullAdministratorData()
public function iProvideFullAdministratorData(): void
{
$this->inputChoices['e-mail'] = 'test@admin.com';
$this->inputChoices['username'] = 'test';
$this->inputChoices['password'] = 'pswd1$';
$this->inputChoices['confirmation'] = $this->inputChoices['password'];
}

/**
* @param string $input
*
* @return resource
*/
private function getInputStream($input)
{
$stream = fopen('php://memory', 'rb+', false);
fwrite($stream, $input);
rewind($stream);

return $stream;
}

/**
* @param string $name
*/
private function iExecuteCommandWithInputChoices($name)
private function iExecuteCommandWithInputChoices(string $name): void
{
$this->questionHelper = $this->command->getHelper('question');
$inputString = implode(PHP_EOL, $this->inputChoices);
$this->questionHelper->setInputStream($this->getInputStream($inputString . PHP_EOL));

try {
$this->tester->setInputs($this->inputChoices);
$this->tester->execute(['command' => $name]);
} catch (\Exception $e) {
}
Expand All @@ -176,13 +154,10 @@ private function iExecuteCommandWithInputChoices($name)
/**
* @param string $name
*/
private function iExecuteCommandAndConfirm($name)
private function iExecuteCommandAndConfirm(string $name): void
{
$this->questionHelper = $this->command->getHelper('question');
$inputString = 'y' . PHP_EOL;
$this->questionHelper->setInputStream($this->getInputStream($inputString));

try {
$this->tester->setInputs(['y']);
$this->tester->execute(['command' => $name]);
} catch (\Exception $e) {
}
Expand Down
Expand Up @@ -158,7 +158,7 @@ public function clearAction(Request $request): Response
$this->isGrantedOr403($configuration, ResourceActions::DELETE);
$resource = $this->getCurrentCart();

if ($configuration->isCsrfProtectionEnabled() && !$this->isCsrfTokenValid($resource->getId(), $request->get('_csrf_token'))) {
if ($configuration->isCsrfProtectionEnabled() && !$this->isCsrfTokenValid((string) $resource->getId(), $request->get('_csrf_token'))) {
throw new HttpException(Response::HTTP_FORBIDDEN, 'Invalid csrf token.');
}

Expand Down
Expand Up @@ -129,7 +129,7 @@ public function removeAction(Request $request): Response

$event = $this->eventDispatcher->dispatchPreEvent(CartActions::REMOVE, $configuration, $orderItem);

if ($configuration->isCsrfProtectionEnabled() && !$this->isCsrfTokenValid($orderItem->getId(), $request->request->get('_csrf_token'))) {
if ($configuration->isCsrfProtectionEnabled() && !$this->isCsrfTokenValid((string) $orderItem->getId(), $request->request->get('_csrf_token'))) {
throw new HttpException(Response::HTTP_FORBIDDEN, 'Invalid csrf token.');
}

Expand Down
Expand Up @@ -43,8 +43,9 @@ public function generateAction(Request $request): Response
}

$form = $this->container->get('form.factory')->create(PromotionCouponGeneratorInstructionType::class);
$form->handleRequest($request);

if ($form->handleRequest($request)->isValid()) {
if ($form->isSubmitted() && $form->isValid()) {
$this->getGenerator()->generate($promotion, $form->getData());
$this->flashHelper->addSuccessFlash($configuration, 'generate');

Expand Down
Expand Up @@ -109,7 +109,7 @@ private function createTokenGenerators(string $userType, array $config, Containe
$config['resetting']['token']['length'],
]
)
);
)->setPublic(true);

$container->setDefinition(
sprintf('sylius.%s_user.pin_generator.password_reset', $userType),
Expand All @@ -121,7 +121,7 @@ private function createTokenGenerators(string $userType, array $config, Containe
$config['resetting']['pin']['length'],
]
)
);
)->setPublic(true);

$container->setDefinition(
sprintf('sylius.%s_user.token_generator.email_verification', $userType),
Expand All @@ -133,7 +133,7 @@ private function createTokenGenerators(string $userType, array $config, Containe
$config['verification']['token']['length'],
]
)
);
)->setPublic(true);
}

/**
Expand Down

0 comments on commit d74f626

Please sign in to comment.