Skip to content

Commit

Permalink
Fix RemoveCacheCommand with empty path
Browse files Browse the repository at this point in the history
  • Loading branch information
franmomu committed Oct 26, 2019
1 parent 074da1a commit 664dcce
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Command/CacheCommandTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private function setupOutputStyle(InputInterface $input, OutputInterface $output
private function resolveInputFiltersAndPaths(InputInterface $input): array
{
return [
$input->getArgument('path'),
$input->getArgument('paths'),
$this->normalizeFilterList($input->getOption('filter')),
];
}
Expand Down
12 changes: 8 additions & 4 deletions Command/RemoveCacheCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected function configure(): void
{
$this
->setDescription('Remove cache entries for given paths and filters.')
->addArgument('path', InputArgument::REQUIRED | InputArgument::IS_ARRAY,
->addArgument('paths', InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
'Image file path(s) to run resolution on.')
->addOption('filter', 'f', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
'Filter(s) to use for image remove; if none explicitly passed, use all filters.')
Expand Down Expand Up @@ -77,9 +77,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int

[$images, $filters] = $this->resolveInputFiltersAndPaths($input);

foreach ($images as $i) {
foreach ($filters as $f) {
$this->runCacheImageRemove($i, $f);
if (empty($images)) {
$this->cacheManager->remove(null, $filters);
} else {
foreach ($images as $i) {
foreach ($filters as $f) {
$this->runCacheImageRemove($i, $f);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion Command/ResolveCacheCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected function configure(): void
{
$this
->setDescription('Warms up the cache for the specified image sources with all or specified filters applied, and prints the list of cache files.')
->addArgument('path', InputArgument::REQUIRED | InputArgument::IS_ARRAY,
->addArgument('paths', InputArgument::REQUIRED | InputArgument::IS_ARRAY,
'Image file path(s) for which to generate the cached images.')
->addOption('filter', 'f', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
'Filter(s) to use for image resolution; if none explicitly passed, use all filters.')
Expand Down
20 changes: 18 additions & 2 deletions Tests/Functional/Command/RemoveCacheCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,20 @@ public function testSkippedRemove(): void
$this->delResolvedImages($images, $filters);
}

public function testShouldRemoveAllImagesAndFilters(): void
{
$images = [];
$filters = [];

$output = $this->executeRemoveCacheCommand($images, $filters);

$filtersDefined = ['thumbnail_web_path', 'thumbnail_default'];

$this->assertOutputContainsSummary($output, $images, $filtersDefined);

$this->delResolvedImages($images, $filters);
}

protected function assertOutputContainsSkippedImages($output, array $images, array $filters): void
{
foreach ($images as $i) {
Expand All @@ -167,7 +181,9 @@ protected function assertOutputContainsRemovedImages($output, array $images, arr
protected function assertOutputContainsSummary(string $output, array $images, array $filters, int $failures = 0): void
{
$this->assertContains(sprintf('Completed %d removal', (count($images) * count($filters)) - $failures), $output);
$this->assertContains(sprintf('%d image', count($images)), $output);
if (0 !== count($images)) {
$this->assertContains(sprintf('%d image', count($images)), $output);
}
$this->assertContains(sprintf('%d filter', count($filters)), $output);
if (0 !== $failures) {
$this->assertContains(sprintf('%d failure', $failures), $output);
Expand Down Expand Up @@ -195,7 +211,7 @@ protected function assertOutputNotContainsSummary(string $output, array $images,
*/
private function executeRemoveCacheCommand(array $paths, array $filters = [], array $additionalOptions = [], int &$return = null): string
{
$options = array_merge(['path' => $paths], $additionalOptions);
$options = array_merge(['paths' => $paths], $additionalOptions);

if (0 < count($filters)) {
$options['--filter'] = $filters;
Expand Down
2 changes: 1 addition & 1 deletion Tests/Functional/Command/ResolveCacheCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ protected function assertOutputNotContainsSummary(string $output, array $images,
*/
private function executeResolveCacheCommand(array $paths, array $filters = [], array $additionalOptions = [], &$return = null): string
{
$options = array_merge(['path' => $paths], $additionalOptions);
$options = array_merge(['paths' => $paths], $additionalOptions);

if (0 < count($filters)) {
$options['--filter'] = $filters;
Expand Down

0 comments on commit 664dcce

Please sign in to comment.