Skip to content

Commit

Permalink
Merge pull request #42 from lruozzi9/erase-all-queue-items
Browse files Browse the repository at this point in the history
Fix clean up command on specifying 0 as retention number of days
  • Loading branch information
mmenozzi authored Feb 8, 2021
2 parents ce62ae0 + 69d4a7d commit 0612c60
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
10 changes: 10 additions & 0 deletions features/cleaning_queue.feature
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,13 @@ Feature: cleaning queue
When I clean the queue specifying 16 days of retention
Then I should be notified that 1 item has been deleted
And there shouldn't be any more item to clean

@cli
Scenario: Cleaning the queue specifying zero as retention number of days
Given there is an already imported item with identifier "braided-hat-m" for the "Product" importer in the Akeneo queue
And this item has been imported now
And there is an already imported item with identifier "braided-hat-s" for the "Product" importer in the Akeneo queue
And this item has been imported 20 days ago
When I clean the queue specifying 0 days of retention
Then I should be notified that 2 items have been deleted
And there shouldn't be any more items to clean
2 changes: 1 addition & 1 deletion src/Command/QueueCleanupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$numberOfDays = self::DEFAULT_DAYS;
// get the number of days from user
$numberOfDaysEntered = $input->getArgument(self::DAYS_ARGUMENT_NAME);
if ($numberOfDaysEntered) {
if ($numberOfDaysEntered !== null) {
if (!is_string($numberOfDaysEntered) || (int) $numberOfDaysEntered < 0) {
$output->writeln('Sorry, the number of days entered is not valid!');

Expand Down
4 changes: 2 additions & 2 deletions tests/Behat/Context/Cli/QueueCleanupCommandContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function iShouldBeNotifiedThatThereAreNoItemsToClean()
}

/**
* @Then /^I should be notified that (\d+) item has been deleted$/
* @Then /^I should be notified that (\d+) item[s]? (has|have) been deleted$/
*/
public function iShouldBeNotifiedThatItemHasBeenDeleted(int $count)
{
Expand All @@ -66,7 +66,7 @@ public function iShouldBeNotifiedThatItemHasBeenDeleted(int $count)
}

/**
* @Then /^there shouldn\'t be any more item to clean$/
* @Then /^there shouldn\'t be any more item[s]? to clean$/
*/
public function thereShouldntBeAnyMoreItemToClean()
{
Expand Down
9 changes: 9 additions & 0 deletions tests/Behat/Context/Setup/QueueContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,13 @@ public function thisItemHasBeenImportedDaysAgo(QueueItemInterface $queueItem, in
$queueItem->setImportedAt(new \DateTime("$days days ago"));
$this->queueItemRepository->add($queueItem);
}

/**
* @Given /^(this item) has been imported now$/
*/
public function thisItemHasBeenImportedNow(QueueItemInterface $queueItem)
{
$queueItem->setImportedAt(new \DateTime());
$this->queueItemRepository->add($queueItem);
}
}

0 comments on commit 0612c60

Please sign in to comment.