Improve cancel unpaid orders test

This commit is contained in:
Rafał Świerczek 2022-02-17 13:53:56 +01:00 committed by Grzegorz Sadowski
parent af52ac2bd6
commit a45a544bb1
No known key found for this signature in database
GPG key ID: EF87FF4E6E3BD364
2 changed files with 14 additions and 16 deletions

View file

@ -1,9 +1,9 @@
@cli
Feature: Cancel unpaid orders
In order to manually cancel only unpaid orders
As a developer
I need to use command in terminal
Feature: Canceling unpaid orders
In order to have my orders list free from completed but unpaid orders
As a Developer
I want to have unpaid orders cancelled
Scenario: Canceling unpaid orders from console
When I run command that cancels unpaid orders
Then I should see output "Unpaid orders has been canceled" message in terminal
Scenario: Canceling unpaid orders
When the unpaid orders has been cancelled
Then I should see be informed that unpaid orders have been cancelled

View file

@ -15,14 +15,13 @@ namespace Sylius\Behat\Context\Cli;
use Webmozart\Assert\Assert;
use Behat\Behat\Context\Context;
use Sylius\Bundle\CoreBundle\Command\SetupCommand;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Bundle\FrameworkBundle\Console\Application;
final class CancelUnpaidOrdersContext implements Context
{
private const COMMAND_CANCEL_UNPAID_ORDERS = 'sylius:cancel-unpaid-orders';
private const CANCEL_UNPAID_ORDERS_COMMAND = 'sylius:cancel-unpaid-orders';
private Application $application;
@ -31,25 +30,24 @@ final class CancelUnpaidOrdersContext implements Context
public function __construct(KernelInterface $kernel)
{
$this->application = new Application($kernel);
$this->application->add(new SetupCommand());
}
/**
* @When I run command that cancels unpaid orders
* @When the unpaid orders has been cancelled
*/
public function runCancelUnpaidOrdersCommand(): void
{
$command = $this->application->find(self::COMMAND_CANCEL_UNPAID_ORDERS);
$command = $this->application->find(self::CANCEL_UNPAID_ORDERS_COMMAND);
$this->commandTester = new CommandTester($command);
$this->commandTester->execute(['command' => self::COMMAND_CANCEL_UNPAID_ORDERS]);
$this->commandTester->execute(['command' => self::CANCEL_UNPAID_ORDERS_COMMAND]);
}
/**
* @Then I should see output :output message in terminal
* @Then I should see be informed that unpaid orders have been cancelled
*/
public function shouldSeeOutputMessage(string $output): void
public function shouldSeeOutputMessage(): void
{
Assert::contains($this->commandTester->getDisplay(), $output);
Assert::contains($this->commandTester->getDisplay(), "Unpaid orders has been canceled");
}
}