Skip to content
Open
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: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Latest
------

## Changes
* [#351](https://github.com/cleverage/process-bundle/issues/351) `ProcessManager` and `ProcessHelpCommand` are typed on `TaskRegistryInterface` instead of the final `TaskRegistry` class: the task registry can be decorated or replaced. Add tests.

v5.4.1
-----

Expand Down
5 changes: 3 additions & 2 deletions src/Command/ProcessHelpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use CleverAge\ProcessBundle\Model\TaskInterface;
use CleverAge\ProcessBundle\Registry\ProcessConfigurationRegistry;
use CleverAge\ProcessBundle\Registry\TaskRegistry;
use CleverAge\ProcessBundle\Registry\TaskRegistryInterface;
use CleverAge\ProcessBundle\Task\Process\ProcessExecutorTask;
use CleverAge\ProcessBundle\Task\Process\ProcessLauncherTask;
use Psr\Container\ContainerInterface;
Expand Down Expand Up @@ -64,7 +65,7 @@ class ProcessHelpCommand extends Command

protected const INDENT_SIZE = 4;

protected TaskRegistry $taskRegistry;
protected TaskRegistryInterface $taskRegistry;

/**
* @deprecated since 5.4, only set when a container is passed to the constructor, will be removed in v6.0
Expand All @@ -73,7 +74,7 @@ class ProcessHelpCommand extends Command

public function __construct(
protected ProcessConfigurationRegistry $processConfigRegistry,
TaskRegistry|ContainerInterface $taskRegistry,
TaskRegistryInterface|ContainerInterface $taskRegistry,
) {
parent::__construct();
if ($taskRegistry instanceof ContainerInterface) {
Expand Down
7 changes: 4 additions & 3 deletions src/Manager/ProcessManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use CleverAge\ProcessBundle\Model\TaskInterface;
use CleverAge\ProcessBundle\Registry\ProcessConfigurationRegistry;
use CleverAge\ProcessBundle\Registry\TaskRegistry;
use CleverAge\ProcessBundle\Registry\TaskRegistryInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\Service\ResetInterface;
Expand Down Expand Up @@ -66,7 +67,7 @@ class ProcessManager implements ProcessManagerInterface, ResetInterface

protected ?TaskConfiguration $taskConfiguration = null;

protected TaskRegistry $taskRegistry;
protected TaskRegistryInterface $taskRegistry;

/**
* @param iterable<ProcessStopCheckerInterface> $stopCheckers
Expand All @@ -79,9 +80,9 @@ public function __construct(
protected ContextualOptionResolver $contextualOptionResolver,
protected EventDispatcherInterface $eventDispatcher,
protected iterable $stopCheckers = [],
?TaskRegistry $taskRegistry = null,
?TaskRegistryInterface $taskRegistry = null,
) {
if (!$taskRegistry instanceof TaskRegistry) {
if (!$taskRegistry instanceof TaskRegistryInterface) {
trigger_deprecation(
'cleverage/process-bundle',
'5.4',
Expand Down
19 changes: 18 additions & 1 deletion tests/Manager/ProcessManagerTaskRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
use CleverAge\ProcessBundle\Model\AbstractConfigurableTask;
use CleverAge\ProcessBundle\Model\ProcessHistory;
use CleverAge\ProcessBundle\Model\ProcessState;
use CleverAge\ProcessBundle\Model\TaskInterface;
use CleverAge\ProcessBundle\Registry\ProcessConfigurationRegistry;
use CleverAge\ProcessBundle\Registry\TaskRegistry;
use CleverAge\ProcessBundle\Registry\TaskRegistryInterface;
use CleverAge\ProcessBundle\Task\ConstantOutputTask;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\UsesClass;
Expand Down Expand Up @@ -65,6 +67,21 @@ public function testTasksAreFetchedWithTheTaskRegistry(): void
self::assertSame([], $this->deprecations);
}

public function testAnyTaskRegistryCanBeUsed(): void
{
// E.g. a decorator of the task registry of the bundle
$taskRegistry = new class implements TaskRegistryInterface {
public function getTask(TaskConfiguration $taskConfiguration): TaskInterface
{
return new ConstantOutputTask();
}
};
$processManager = $this->collectDeprecations(fn (): ProcessManager => $this->createProcessManager($taskRegistry));

self::assertSame('ok', $this->collectDeprecations(static fn (): mixed => $processManager->execute('test.process')));
self::assertSame([], $this->deprecations);
}

public function testWithoutTaskRegistryTheTasksAreFetchedFromTheContainerWithADeprecation(): void
{
$processManager = $this->collectDeprecations(fn (): ProcessManager => $this->createProcessManager(null));
Expand All @@ -76,7 +93,7 @@ public function testWithoutTaskRegistryTheTasksAreFetchedFromTheContainerWithADe
);
}

private function createProcessManager(?TaskRegistry $taskRegistry): ProcessManager
private function createProcessManager(?TaskRegistryInterface $taskRegistry): ProcessManager
{
$container = new Container();
$container->set('app.constant', new ConstantOutputTask());
Expand Down
Loading