Skip to content

Commit

Permalink
OP-291: Add tests for the new command
Browse files Browse the repository at this point in the history
  • Loading branch information
hmfilar committed Jul 26, 2024
1 parent 6a82668 commit 85b2b1a
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 0 deletions.
32 changes: 32 additions & 0 deletions features/removing_guest_wishlists.feature
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 "[email protected]"
And user "[email protected]" "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
70 changes: 70 additions & 0 deletions tests/Behat/Context/Cli/WishlistContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* You can find more information about us on https://bitbag.io and write us
* an email on [email protected].
*/

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);

Check failure on line 60 in tests/Behat/Context/Cli/WishlistContext.php

View workflow job for this annotation

GitHub Actions / Sylius ~1.12.13, PHP 8.1, Symfony ^5.4, MySQL 8.0, State Machine Adapter winzou_state_machine

Cannot call method getStatusCode() on Symfony\Component\Console\Tester\CommandTester|null.

Check failure on line 60 in tests/Behat/Context/Cli/WishlistContext.php

View workflow job for this annotation

GitHub Actions / Sylius ~1.13.0, PHP 8.1, Symfony ^5.4, MySQL 8.0, State Machine Adapter winzou_state_machine

Cannot call method getStatusCode() on Symfony\Component\Console\Tester\CommandTester|null.

Check failure on line 60 in tests/Behat/Context/Cli/WishlistContext.php

View workflow job for this annotation

GitHub Actions / Sylius ~1.13.0, PHP 8.1, Symfony ^5.4, MySQL 8.0, State Machine Adapter symfony_workflow

Cannot call method getStatusCode() on Symfony\Component\Console\Tester\CommandTester|null.

Check failure on line 60 in tests/Behat/Context/Cli/WishlistContext.php

View workflow job for this annotation

GitHub Actions / Sylius ~1.12.13, PHP 8.1, Symfony ^6.0, MySQL 8.0, State Machine Adapter winzou_state_machine

Cannot call method getStatusCode() on Symfony\Component\Console\Tester\CommandTester|null.

Check failure on line 60 in tests/Behat/Context/Cli/WishlistContext.php

View workflow job for this annotation

GitHub Actions / Sylius ~1.13.0, PHP 8.1, Symfony ^6.0, MySQL 8.0, State Machine Adapter winzou_state_machine

Cannot call method getStatusCode() on Symfony\Component\Console\Tester\CommandTester|null.

Check failure on line 60 in tests/Behat/Context/Cli/WishlistContext.php

View workflow job for this annotation

GitHub Actions / Sylius ~1.13.0, PHP 8.1, Symfony ^6.0, MySQL 8.0, State Machine Adapter symfony_workflow

Cannot call method getStatusCode() on Symfony\Component\Console\Tester\CommandTester|null.
}

/**
* @When the command should fail
*/
public function theCommandShouldFail(): void
{
Assert::same($this->commandTester->getStatusCode(), 1);

Check failure on line 68 in tests/Behat/Context/Cli/WishlistContext.php

View workflow job for this annotation

GitHub Actions / Sylius ~1.12.13, PHP 8.1, Symfony ^5.4, MySQL 8.0, State Machine Adapter winzou_state_machine

Cannot call method getStatusCode() on Symfony\Component\Console\Tester\CommandTester|null.

Check failure on line 68 in tests/Behat/Context/Cli/WishlistContext.php

View workflow job for this annotation

GitHub Actions / Sylius ~1.13.0, PHP 8.1, Symfony ^5.4, MySQL 8.0, State Machine Adapter winzou_state_machine

Cannot call method getStatusCode() on Symfony\Component\Console\Tester\CommandTester|null.

Check failure on line 68 in tests/Behat/Context/Cli/WishlistContext.php

View workflow job for this annotation

GitHub Actions / Sylius ~1.13.0, PHP 8.1, Symfony ^5.4, MySQL 8.0, State Machine Adapter symfony_workflow

Cannot call method getStatusCode() on Symfony\Component\Console\Tester\CommandTester|null.

Check failure on line 68 in tests/Behat/Context/Cli/WishlistContext.php

View workflow job for this annotation

GitHub Actions / Sylius ~1.12.13, PHP 8.1, Symfony ^6.0, MySQL 8.0, State Machine Adapter winzou_state_machine

Cannot call method getStatusCode() on Symfony\Component\Console\Tester\CommandTester|null.

Check failure on line 68 in tests/Behat/Context/Cli/WishlistContext.php

View workflow job for this annotation

GitHub Actions / Sylius ~1.13.0, PHP 8.1, Symfony ^6.0, MySQL 8.0, State Machine Adapter winzou_state_machine

Cannot call method getStatusCode() on Symfony\Component\Console\Tester\CommandTester|null.

Check failure on line 68 in tests/Behat/Context/Cli/WishlistContext.php

View workflow job for this annotation

GitHub Actions / Sylius ~1.13.0, PHP 8.1, Symfony ^6.0, MySQL 8.0, State Machine Adapter symfony_workflow

Cannot call method getStatusCode() on Symfony\Component\Console\Tester\CommandTester|null.
}
}
31 changes: 31 additions & 0 deletions tests/Behat/Context/Common/WishlistContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* You can find more information about us on https://bitbag.io and write us
* an email on [email protected].
*/

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);
}
}
10 changes: 10 additions & 0 deletions tests/Behat/Resources/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ services:
- "@bitbag_wishlist_plugin.behat.page.wishlist.index_page"
- "@bitbag_wishlist_plugin.behat.page.wishlist.chosen_show_page"

bitbag_wishlist_plugin.behat.context.cli.wishlist:
class: Tests\BitBag\SyliusWishlistPlugin\Behat\Context\Cli\WishlistContext
arguments:
- '@kernel'

bitbag_wishlist_plugin.behat.context.common.wishlist:
class: Tests\BitBag\SyliusWishlistPlugin\Behat\Context\Common\WishlistContext
arguments:
- '@bitbag_sylius_wishlist_plugin.repository.wishlist'

bitbag_sylius_cms_plugin.behat.page.shop.wishlist:
class: Tests\BitBag\SyliusWishlistPlugin\Behat\Page\Shop\WishlistPage
parent: sylius.behat.symfony_page
Expand Down
1 change: 1 addition & 0 deletions tests/Behat/Resources/suites.yml
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
22 changes: 22 additions & 0 deletions tests/Behat/Resources/suites/cli/cli_wishlist.yml
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"

0 comments on commit 85b2b1a

Please sign in to comment.