Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .harness.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"observed": [
"Code style",
"Rector",
"Dependency analysis",
"Security patterns"
"Dependency analysis"
]
}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Registering a command outside WP-CLI throws the named `WpCliUnavailable` exception instead of a bare `\RuntimeException`. It extends `\RuntimeException`, and the message keeps its `WP-CLI is not available` prefix, followed by how to avoid it

## [0.1.1] - 2026-10-13

### Fixed
Expand Down
18 changes: 18 additions & 0 deletions src/Domain/Exceptions/WpCliUnavailable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Pollora\WpCli\Domain\Exceptions;

use RuntimeException;

/**
* Thrown when a command is registered outside a WP-CLI process.
*/
final class WpCliUnavailable extends RuntimeException
{
public static function whenRegisteringACommand(): self
{
return new self('WP-CLI is not available. Register commands from code that runs under `wp`, or check the adapter with isAvailable() first.');
}
}
3 changes: 2 additions & 1 deletion src/Infrastructure/Adapters/WpCliAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Pollora\WpCli\Infrastructure\Adapters;

use Pollora\WpCli\Domain\Exceptions\WpCliUnavailable;
use WP_CLI;

/**
Expand Down Expand Up @@ -36,7 +37,7 @@ public function isAvailable(): bool
public function addCommand(string $name, string|array|object $handler, array $args = []): void
{
if (! $this->isAvailable()) {
throw new \RuntimeException('WP-CLI is not available');
throw WpCliUnavailable::whenRegisteringACommand();
}

$this->validateHandler($handler);
Expand Down
13 changes: 13 additions & 0 deletions tests/Unit/Domain/Exceptions/WpCliUnavailableTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

use Pollora\WpCli\Domain\Exceptions\WpCliUnavailable;

it('says WP-CLI is missing and what to do about it', function (): void {
$exception = WpCliUnavailable::whenRegisteringACommand();

expect($exception)->toBeInstanceOf(RuntimeException::class)
->and($exception->getMessage())->toStartWith('WP-CLI is not available')
->and($exception->getMessage())->toContain('isAvailable()');
});
Loading