Skip to content

Commit

Permalink
Merge pull request #989 from veewee/task-enabled
Browse files Browse the repository at this point in the history
Task enabled
  • Loading branch information
veewee authored Mar 10, 2022
2 parents f89da5d + a523839 commit 64450ed
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
9 changes: 9 additions & 0 deletions doc/tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ grumphp:
anytask:
metadata:
blocking: true
enabled: true
label: null
priority: 0
task: null
Expand All @@ -152,6 +153,14 @@ This option can be used to make a failing task non-blocking.
By default all tasks will be marked as blocking.
When a task is non-blocking, the errors will be displayed but the tests will pass.

**enabled**

*Default: true*

This option can be used to disable task execution.
By default all tasks will be enabled.
This makes it possible to conditionally run a task by setting parameters or changing the value through an extension.

**label**

*Default: null*
Expand Down
8 changes: 8 additions & 0 deletions spec/Task/Config/MetadataSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function it_contains_an_options_resolver_with_default(): void
$result->shouldBe([
'priority' => 0,
'blocking' => true,
'enabled' => true,
'task' => '',
'label' => '',
]);
Expand All @@ -34,6 +35,7 @@ public function it_contains_default_options(): void
{
$this->beConstructedWith([]);
$this->priority()->shouldBe(0);
$this->isEnabled()->shouldBe(true);
$this->isBlocking()->shouldBe(true);
$this->task()->shouldBe('');
$this->label()->shouldBe('');
Expand All @@ -51,6 +53,12 @@ public function it_knows_if_blocking(): void
$this->isBlocking()->shouldBe(true);
}

public function it_knows_if_enabled(): void
{
$this->beConstructedWith(['enabled' => true]);
$this->isEnabled()->shouldBe(true);
}

public function it_knows_if_not_blocking(): void
{
$this->beConstructedWith(['blocking' => false]);
Expand Down
6 changes: 6 additions & 0 deletions src/Configuration/Compiler/TaskCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ public function process(ContainerBuilder $container): void
$metadataConfig
));

// Disabled tasks can be skipped
// This allows to conditionally disable tasks through parameters or by an extension.
if (!$metadata->isEnabled()) {
continue;
}

// Configure task:
$taskBuilder = new Definition($taskClass, [
new Reference($taskId),
Expand Down
2 changes: 1 addition & 1 deletion src/Console/ApplicationConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class ApplicationConfigurator
{
const APP_NAME = 'GrumPHP';
const APP_VERSION = '1.8.0';
const APP_VERSION = '1.8.1';

public function configure(Application $application): void
{
Expand Down
6 changes: 6 additions & 0 deletions src/Task/Config/Metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public static function getConfigurableOptions(): OptionsResolver
$resolver->setDefaults([
'priority' => 0,
'blocking' => true,
'enabled' => true,
'task' => '',
'label' => '',
]);
Expand All @@ -44,6 +45,11 @@ public function isBlocking(): bool
return (bool) $this->metadata['blocking'];
}

public function isEnabled(): bool
{
return (bool) $this->metadata['enabled'];
}

public function task(): string
{
return (string) $this->metadata['task'];
Expand Down

0 comments on commit 64450ed

Please sign in to comment.