Skip to content

Commit

Permalink
ref
Browse files Browse the repository at this point in the history
  • Loading branch information
Guikingone committed Jun 20, 2023
1 parent bdda5b1 commit 7b9fb37
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 10 deletions.
10 changes: 8 additions & 2 deletions src/Task/HttpTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ public function setUrl(string $url): self

public function getMethod(): string
{
return $this->options['method'] ?? 'GET';
return is_string(value: $this->options['method'])
? $this->options['method']
: 'GET'
;
}

public function setMethod(string $method): self
Expand All @@ -71,7 +74,10 @@ public function setMethod(string $method): self
*/
public function getClientOptions(): array
{
return is_array(value: $this->options['client_options']) ? $this->options['client_options'] : [];
return is_array(value: $this->options['client_options'])
? $this->options['client_options']
: []
;
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/Test/Constraint/Probe/ProbeExecutedTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public function toString(): string
*/
protected function matches($other): bool
{
if (!$other instanceof ProbeInterface) {
return false;
}

return $this->expectedCount === $other->getExecutedTasks();
}
}
4 changes: 4 additions & 0 deletions src/Test/Constraint/Probe/ProbeFailedTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public function toString(): string
*/
protected function matches($other): bool
{
if (!$other instanceof ProbeInterface) {
return false;
}

return $this->expectedCount === $other->getFailedTasks();
}
}
4 changes: 4 additions & 0 deletions src/Test/Constraint/Probe/ProbeScheduledTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public function toString(): string
*/
protected function matches($other): bool
{
if (!$other instanceof ProbeInterface) {
return false;
}

return $this->expectedCount === $other->getScheduledTasks();
}
}
6 changes: 6 additions & 0 deletions src/Test/Constraint/Probe/ProbeState.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PHPUnit\Framework\Constraint\Constraint;
use SchedulerBundle\Probe\ProbeInterface;

use Throwable;
use function json_encode;
use function sprintf;

Expand All @@ -32,9 +33,14 @@ public function toString(): string

/**
* @param mixed|ProbeInterface $other
* @throws Throwable {@see ProbeInterface::getScheduledTasks()}
*/
protected function matches($other): bool
{
if (!$other instanceof ProbeInterface) {
return false;
}

return $this->expectedState === [
'executedTasks' => $other->getExecutedTasks(),
'failedTasks' => $other->getFailedTasks(),
Expand Down
10 changes: 9 additions & 1 deletion src/Test/Constraint/Scheduler/SchedulerDueTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PHPUnit\Framework\Constraint\Constraint;
use SchedulerBundle\SchedulerInterface;

use Throwable;
use function sprintf;

/**
Expand All @@ -28,9 +29,16 @@ public function toString(): string

/**
* @param mixed|SchedulerInterface $other
* @throws Throwable {@see SchedulerInterface::getDueTasks()}
*/
protected function matches($other): bool
{
return $this->expectedCount === $other->getDueTasks()->count();
if (!$other instanceof SchedulerInterface) {
return false;
}

$dueTasks = $other->getDueTasks();

return $this->expectedCount === $dueTasks->count();
}
}
8 changes: 7 additions & 1 deletion src/Test/Constraint/TaskExecuted.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public function toString(): string
*/
protected function matches($other): bool
{
if (!$other instanceof TaskEventList) {
return false;
}

return $this->expectedCount === $this->countExecutedTasks($other);
}

Expand All @@ -44,7 +48,9 @@ private function countExecutedTasks(TaskEventList $taskEventList): int
continue;
}

if (TaskInterface::SUCCEED !== $taskEvent->getTask()->getExecutionState()) {
$task = $taskEvent->getTask();

if (TaskInterface::SUCCEED !== $task->getExecutionState()) {
continue;
}

Expand Down
7 changes: 5 additions & 2 deletions src/Test/Constraint/TaskFailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use SchedulerBundle\Event\TaskEventList;

use function count;
use function is_countable;
use function sprintf;

/**
Expand All @@ -33,6 +32,10 @@ public function toString(): string
*/
protected function matches($other): bool
{
return $this->expectedCount === (is_countable($other->getFailedTaskEvents()) ? count($other->getFailedTaskEvents()) : 0);
if (!$other instanceof TaskEventList) {
return false;
}

return $this->expectedCount === count($other->getFailedTaskEvents());
}
}
8 changes: 7 additions & 1 deletion src/Test/Constraint/TaskQueued.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public function toString(): string
*/
protected function matches($other): bool
{
if (!$other instanceof TaskEventList) {
return false;
}

return $this->expectedCount === $this->countQueuedTasks($other);
}

Expand All @@ -43,7 +47,9 @@ private function countQueuedTasks(TaskEventList $taskEventList): int
continue;
}

if (!$taskEvent->getTask()->isQueued()) {
$task = $taskEvent->getTask();

if (!$task->isQueued()) {
continue;
}

Expand Down
6 changes: 5 additions & 1 deletion src/Test/Constraint/TaskScheduled.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public function toString(): string
*/
protected function matches($other): bool
{
return $this->expectedCount === (is_countable($other->getScheduledTaskEvents()) ? count($other->getScheduledTaskEvents()) : 0);
if (!$other instanceof TaskEventList) {
return false;
}

return $this->expectedCount === count($other->getScheduledTaskEvents());
}
}
6 changes: 5 additions & 1 deletion src/Test/Constraint/TaskUnscheduled.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public function toString(): string
*/
protected function matches($other): bool
{
return $this->expectedCount === (is_countable($other->getUnscheduledTaskEvents()) ? count($other->getUnscheduledTaskEvents()) : 0);
if (!$other instanceof TaskEventList) {
return false;
}

return $this->expectedCount === count($other->getUnscheduledTaskEvents());
}
}
5 changes: 4 additions & 1 deletion src/Worker/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ public function execute(WorkerConfiguration $configuration, TaskInterface ...$ta
*/
public function preempt(TaskListInterface $preemptTaskList, TaskListInterface $toPreemptTasksList): void
{
$nonExecutedTasks = $toPreemptTasksList->slice(...$preemptTaskList->map(func: static fn (TaskInterface $task): string => $task->getName(), keepKeys: false));
/** @var string[] $taskNameList */
$taskNameList = $preemptTaskList->map(func: static fn (TaskInterface $task): string => $task->getName(), keepKeys: false);

$nonExecutedTasks = $toPreemptTasksList->slice(...$taskNameList);
$nonExecutedTasks->walk(func: function (TaskInterface $task): void {
$accessLockBag = $task->getAccessLockBag();

Expand Down

0 comments on commit 7b9fb37

Please sign in to comment.