-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OP-291: Add tests for the new command
- Loading branch information
Showing
6 changed files
with
152 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
@cli_wishlist | ||
Feature: Removing guest wishlists | ||
In order to clean guest wishlists | ||
As a developer | ||
I want to be able to delete wishlists created by anonymous customers by running a CLI command | ||
|
||
Background: | ||
Given the store operates on a single channel in "United States" | ||
And the store has a product "Jack Daniels Gentleman" priced at "$10.00" | ||
And all store products appear under a main taxonomy | ||
And I add this product to wishlist | ||
And there are 1 wishlists in the database | ||
|
||
@cli | ||
Scenario: Removing all guest wishlists | ||
Given there is a user "test@example.com" | ||
And user "test@example.com" "sylius" is authenticated | ||
And there are 2 wishlists in the database | ||
When I run delete guest wishlists command | ||
Then the command should succeed | ||
And there are 1 wishlists in the database | ||
|
||
# @cli | ||
# Scenario: Removing guest wishlists with date | ||
# When I run delete guests wishlists command with date "01-01-2024" | ||
# Then the command should succeed | ||
# | ||
# @cli | ||
# Scenario: Removing guest wishlists with invalid date | ||
# When I run delete guests wishlists command with date "invalid" | ||
# Then the command should fail | ||
# And there are 1 wishlists in the database |
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\BitBag\SyliusWishlistPlugin\Behat\Context\Cli; | ||
|
||
use Behat\Behat\Context\Context; | ||
use Symfony\Bundle\FrameworkBundle\Console\Application; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
use Symfony\Component\HttpKernel\KernelInterface; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class WishlistContext implements Context | ||
{ | ||
public const REMOVE_GUEST_WISHLISTS_COMMAND = 'bitbag:wishlist:remove-guest-wishlists'; | ||
|
||
private Application $application; | ||
|
||
private ?CommandTester $commandTester = null; | ||
|
||
public function __construct( | ||
KernelInterface $kernel, | ||
) { | ||
$this->application = new Application($kernel); | ||
} | ||
|
||
/** | ||
* @When I run delete guest wishlists command | ||
*/ | ||
public function runRemoveGuestWishlistsCommand(): void | ||
{ | ||
$command = $this->application->find(self::REMOVE_GUEST_WISHLISTS_COMMAND); | ||
|
||
$this->commandTester = new CommandTester($command); | ||
$this->commandTester->execute([]); | ||
} | ||
|
||
/** | ||
* @When I run delete guests wishlists command with date :date | ||
*/ | ||
public function runRemoveGuestWishlistsCommandWithInvalidDate(string $date): void | ||
{ | ||
$command = $this->application->find(self::REMOVE_GUEST_WISHLISTS_COMMAND); | ||
$this->commandTester = new CommandTester($command); | ||
$this->commandTester->execute(['--date' => $date]); | ||
} | ||
|
||
/** | ||
* @When the command should succeed | ||
*/ | ||
public function theCommandShouldSucceed(): void | ||
{ | ||
Assert::same($this->commandTester->getStatusCode(), 0); | ||
} | ||
|
||
/** | ||
* @When the command should fail | ||
*/ | ||
public function theCommandShouldFail(): void | ||
{ | ||
Assert::same($this->commandTester->getStatusCode(), 1); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\BitBag\SyliusWishlistPlugin\Behat\Context\Common; | ||
|
||
use Behat\Behat\Context\Context; | ||
use BitBag\SyliusWishlistPlugin\Repository\WishlistRepositoryInterface; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class WishlistContext implements Context | ||
{ | ||
public function __construct(private WishlistRepositoryInterface $wishlistRepository) | ||
{ | ||
} | ||
|
||
/** | ||
* @When there are :count wishlists in the database | ||
*/ | ||
public function thereAreWishlistsInTheDatabase(int $count): void | ||
{ | ||
Assert::same(count($this->wishlistRepository->findAll()), $count); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
imports: | ||
- suites/ui/ui_wishlist.yml | ||
- suites/api/api_wishlist.yml | ||
- suites/cli/cli_wishlist.yml |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
default: | ||
suites: | ||
cli_wishlist: | ||
contexts: | ||
- sylius.behat.context.hook.doctrine_orm | ||
- sylius.behat.context.setup.channel | ||
- sylius.behat.context.setup.product | ||
- sylius.behat.context.setup.user | ||
- sylius.behat.context.transform.lexical | ||
- sylius.behat.context.transform.product | ||
- sylius.behat.context.transform.product_variant | ||
- sylius.behat.context.transform.channel | ||
- sylius.behat.context.api.shop.channel | ||
|
||
- bitbag_wishlist_plugin.behat.context.api.wishlist | ||
- bitbag_wishlist_plugin.behat.context.cli.wishlist | ||
- bitbag_wishlist_plugin.behat.context.common.wishlist | ||
- bitbag_sylius_cms_plugin.behat.context.ui.wishlist | ||
- bitbag_sylius_cms_plugin.behat.context.setup.wishlist | ||
|
||
filters: | ||
tags: "@cli_wishlist&&@cli" |