Skip to content

Commit f06b7e1

Browse files
committed
refactor: improve UX on cache:clear, cache:info, and debugbar:clear commands
1 parent df9f137 commit f06b7e1

7 files changed

Lines changed: 19 additions & 10 deletions

File tree

system/Commands/Cache/ClearCache.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ protected function execute(array $arguments, array $options): int
4848
$config->handler = $driver;
4949

5050
if (! service('cache', $config)->clean()) {
51-
CLI::error('Error occurred while clearing the cache.');
51+
CLI::error(sprintf('Error occurred while clearing the cache using the "%s" driver.', $driver));
5252

5353
return EXIT_ERROR;
5454
}
5555

56-
CLI::write('Cache cleared.', 'green');
56+
CLI::write(sprintf('Cache cleared using the "%s" driver.', $driver), 'green');
5757

5858
return EXIT_SUCCESS;
5959
}

system/Commands/Cache/InfoCache.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ protected function execute(array $arguments, array $options): int
3030
$config = config(Cache::class);
3131

3232
if ($config->handler !== 'file') {
33-
CLI::error('This command only supports the file cache handler.');
33+
CLI::error(sprintf(
34+
'This command only supports the file cache handler. The configured handler is "%s".',
35+
$config->handler,
36+
));
3437

3538
return EXIT_ERROR;
3639
}

system/Commands/Housekeeping/ClearDebugbar.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ protected function execute(array $arguments, array $options): int
2727
{
2828
helper('filesystem');
2929

30+
$path = clean_path(WRITEPATH . 'debugbar');
31+
3032
if (! delete_files(WRITEPATH . 'debugbar', htdocs: true)) {
31-
CLI::error('Error deleting the debugbar JSON files.');
33+
CLI::error(sprintf('Error deleting the debugbar JSON files in "%s".', $path));
3234

3335
return EXIT_ERROR;
3436
}
3537

36-
CLI::write('Debugbar cleared.', 'green');
38+
CLI::write(sprintf('Cleared debugbar JSON files in "%s".', $path), 'green');
3739

3840
return EXIT_SUCCESS;
3941
}

tests/system/Commands/Cache/ClearCacheTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ public function testClearCacheWorks(): void
6666
command('cache:clear');
6767

6868
$this->assertNull(cache('foo'));
69-
$this->assertStringContainsString('Cache cleared.', $this->getStreamFilterBuffer());
69+
$this->assertStringContainsString(
70+
sprintf('Cache cleared using the "%s" driver.', config('Cache')->handler),
71+
$this->getStreamFilterBuffer(),
72+
);
7073
}
7174

7275
public function testClearCacheFails(): void
@@ -82,7 +85,7 @@ public function testClearCacheFails(): void
8285
command('cache:clear');
8386

8487
$this->assertSame(
85-
"\nError occurred while clearing the cache.\n",
88+
sprintf("\nError occurred while clearing the cache using the \"%s\" driver.\n", config('Cache')->handler),
8689
preg_replace('/\e\[[^m]+m/', '', $this->getStreamFilterBuffer()),
8790
);
8891
}

tests/system/Commands/Cache/InfoCacheTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function testInfoCacheErrorsOnInvalidHandler(): void
6060
$this->assertSame(
6161
<<<'EOT'
6262
63-
This command only supports the file cache handler.
63+
This command only supports the file cache handler. The configured handler is "redis".
6464

6565
EOT,
6666
$this->getUndecoratedBuffer(),

tests/system/Commands/Housekeeping/ClearDebugbarTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function testClearDebugbarWorks(): void
7575
$this->assertFileDoesNotExist(WRITEPATH . 'debugbar' . DIRECTORY_SEPARATOR . "debugbar_{$this->time}.json");
7676
$this->assertFileExists(WRITEPATH . 'debugbar' . DIRECTORY_SEPARATOR . 'index.html');
7777
$this->assertSame(
78-
"\nDebugbar cleared.\n",
78+
sprintf("\nCleared debugbar JSON files in \"%s\".\n", clean_path(WRITEPATH . 'debugbar')),
7979
preg_replace('/\e\[[^m]+m/', '', $this->getStreamFilterBuffer()),
8080
);
8181
}
@@ -95,7 +95,7 @@ public function testClearDebugbarWithError(): void
9595

9696
$this->assertFileExists($path);
9797
$this->assertSame(
98-
"\nError deleting the debugbar JSON files.\n",
98+
sprintf("\nError deleting the debugbar JSON files in \"%s\".\n", clean_path(WRITEPATH . 'debugbar')),
9999
preg_replace('/\e\[[^m]+m/', '', $this->getStreamFilterBuffer()),
100100
);
101101
}

user_guide_src/source/changelogs/v4.8.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Behavior Changes
3030
- **Commands:** The ``filter:check`` command now requires the HTTP method argument to be uppercase (e.g., ``spark filter:check GET /`` instead of ``spark filter:check get /``).
3131
- **Commands:** Several built-in commands have been migrated from ``BaseCommand`` to the modern ``AbstractCommand`` style. Applications that extend a built-in command to override
3232
behaviour may need to re-implement against the modern API (``configure()`` + ``execute()`` and the ``#[Command]`` attribute) once the class it extends is migrated, or, preferably, compose instead of extending. Invocations on the command line are unaffected.
33+
- **Commands:** The success and error messages from ``debugbar:clear``, ``cache:clear``, and ``cache:info`` now include the affected path or cache driver/handler so the user can see which resource was acted on (or rejected). Scripts asserting on the prior literal text will need to be updated.
3334
- **Database:** The Postgre driver's ``$db->error()['code']`` previously always returned ``''``. It now returns the 5-character SQLSTATE string for query and transaction failures (e.g., ``'42P01'``), or ``'08006'`` for connection-level failures. Code that relied on ``$db->error()['code'] === ''`` will need updating.
3435
- **Filters:** HTTP method matching for method-based filters is now case-sensitive. The keys in ``Config\Filters::$methods`` must exactly match the request method
3536
(e.g., ``GET``, ``POST``). Lowercase method names (e.g., ``post``) will no longer match.

0 commit comments

Comments
 (0)