-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
265 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace Zenstruck\ScheduleBundle\Schedule\Task; | ||
|
||
/** | ||
* @author Kevin Bond <[email protected]> | ||
*/ | ||
final class Config | ||
{ | ||
private $data = []; | ||
|
||
/** | ||
* @param mixed $value | ||
*/ | ||
public function set(string $name, $value): self | ||
{ | ||
$this->data[$name] = $value; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @param mixed $default | ||
* | ||
* @return mixed | ||
*/ | ||
public function get(string $name, $default = null) | ||
{ | ||
return $this->data[$name] ?? $default; | ||
} | ||
|
||
public function all(): array | ||
{ | ||
return $this->data; | ||
} | ||
|
||
public function humanized(): array | ||
{ | ||
$ret = []; | ||
|
||
foreach ($this->data as $key => $value) { | ||
switch (true) { | ||
case \is_bool($value): | ||
$value = $value ? 'yes' : 'no'; | ||
|
||
break; | ||
|
||
case \is_scalar($value): | ||
break; | ||
|
||
case \is_object($value): | ||
$value = \sprintf('(%s)', \get_class($value)); | ||
|
||
break; | ||
|
||
default: | ||
$value = \sprintf('(%s)', \gettype($value)); | ||
} | ||
|
||
$ret[$key] = $value; | ||
} | ||
|
||
return $ret; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -274,6 +274,31 @@ public function full_task_configuration() | |
$this->assertSame('On Task Failure, email output to "[email protected]"', (string) $extensions[8]); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function can_add_task_config(): void | ||
{ | ||
$schedule = $this->createSchedule([ | ||
[ | ||
'task' => 'my:command', | ||
'frequency' => '0 * * * *', | ||
'config' => [ | ||
'foo' => 'bar', | ||
'bar' => 'foo', | ||
], | ||
], | ||
]); | ||
|
||
$this->assertSame( | ||
[ | ||
'foo' => 'bar', | ||
'bar' => 'foo', | ||
], | ||
$schedule->all()[0]->config()->all() | ||
); | ||
} | ||
|
||
private function createSchedule(array $taskConfig): Schedule | ||
{ | ||
$processor = new Processor(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
use PHPUnit\Framework\TestCase; | ||
use Zenstruck\ScheduleBundle\Schedule\Task\CompoundTask; | ||
use Zenstruck\ScheduleBundle\Tests\Fixture\MockTask; | ||
|
||
/** | ||
* @author Kevin Bond <[email protected]> | ||
|
@@ -22,4 +23,41 @@ public function cannot_nest_compound_tasks() | |
|
||
$task->add(new CompoundTask()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function config_is_passed_to_sub_tasks(): void | ||
{ | ||
$task = new CompoundTask(); | ||
$task->add(new MockTask('subtask1')); | ||
$task->add(new MockTask('subtask2')); | ||
$task->config()->set('foo', 'bar'); | ||
$task->config()->set('bar', 'foo'); | ||
|
||
[$subtask1, $subtask2] = \iterator_to_array($task); | ||
|
||
$this->assertSame('bar', $subtask1->config()->get('foo')); | ||
$this->assertSame('foo', $subtask1->config()->get('bar')); | ||
$this->assertSame('bar', $subtask2->config()->get('foo')); | ||
$this->assertSame('foo', $subtask2->config()->get('bar')); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function config_on_sub_tasks_takes_precedence_over_compound_task(): void | ||
{ | ||
$subTask = new MockTask('subtask'); | ||
$subTask->config()->set('key2', 'subtask value2'); | ||
$task = new CompoundTask(); | ||
$task->config()->set('key1', 'compound value1'); | ||
$task->config()->set('key2', 'compound value2'); | ||
$task->add($subTask); | ||
|
||
[$subTask] = \iterator_to_array($task); | ||
|
||
$this->assertSame('compound value1', $subTask->config()->get('key1')); | ||
$this->assertSame('subtask value2', $subTask->config()->get('key2')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters