Skip to content

Commit 7b9fb37

Browse files
committed
ref
1 parent bdda5b1 commit 7b9fb37

File tree

12 files changed

+68
-10
lines changed

12 files changed

+68
-10
lines changed

src/Task/HttpTask.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ public function setUrl(string $url): self
5656

5757
public function getMethod(): string
5858
{
59-
return $this->options['method'] ?? 'GET';
59+
return is_string(value: $this->options['method'])
60+
? $this->options['method']
61+
: 'GET'
62+
;
6063
}
6164

6265
public function setMethod(string $method): self
@@ -71,7 +74,10 @@ public function setMethod(string $method): self
7174
*/
7275
public function getClientOptions(): array
7376
{
74-
return is_array(value: $this->options['client_options']) ? $this->options['client_options'] : [];
77+
return is_array(value: $this->options['client_options'])
78+
? $this->options['client_options']
79+
: []
80+
;
7581
}
7682

7783
/**

src/Test/Constraint/Probe/ProbeExecutedTask.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ public function toString(): string
3131
*/
3232
protected function matches($other): bool
3333
{
34+
if (!$other instanceof ProbeInterface) {
35+
return false;
36+
}
37+
3438
return $this->expectedCount === $other->getExecutedTasks();
3539
}
3640
}

src/Test/Constraint/Probe/ProbeFailedTask.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ public function toString(): string
3131
*/
3232
protected function matches($other): bool
3333
{
34+
if (!$other instanceof ProbeInterface) {
35+
return false;
36+
}
37+
3438
return $this->expectedCount === $other->getFailedTasks();
3539
}
3640
}

src/Test/Constraint/Probe/ProbeScheduledTask.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ public function toString(): string
3131
*/
3232
protected function matches($other): bool
3333
{
34+
if (!$other instanceof ProbeInterface) {
35+
return false;
36+
}
37+
3438
return $this->expectedCount === $other->getScheduledTasks();
3539
}
3640
}

src/Test/Constraint/Probe/ProbeState.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PHPUnit\Framework\Constraint\Constraint;
88
use SchedulerBundle\Probe\ProbeInterface;
99

10+
use Throwable;
1011
use function json_encode;
1112
use function sprintf;
1213

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

3334
/**
3435
* @param mixed|ProbeInterface $other
36+
* @throws Throwable {@see ProbeInterface::getScheduledTasks()}
3537
*/
3638
protected function matches($other): bool
3739
{
40+
if (!$other instanceof ProbeInterface) {
41+
return false;
42+
}
43+
3844
return $this->expectedState === [
3945
'executedTasks' => $other->getExecutedTasks(),
4046
'failedTasks' => $other->getFailedTasks(),

src/Test/Constraint/Scheduler/SchedulerDueTask.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PHPUnit\Framework\Constraint\Constraint;
88
use SchedulerBundle\SchedulerInterface;
99

10+
use Throwable;
1011
use function sprintf;
1112

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

2930
/**
3031
* @param mixed|SchedulerInterface $other
32+
* @throws Throwable {@see SchedulerInterface::getDueTasks()}
3133
*/
3234
protected function matches($other): bool
3335
{
34-
return $this->expectedCount === $other->getDueTasks()->count();
36+
if (!$other instanceof SchedulerInterface) {
37+
return false;
38+
}
39+
40+
$dueTasks = $other->getDueTasks();
41+
42+
return $this->expectedCount === $dueTasks->count();
3543
}
3644
}

src/Test/Constraint/TaskExecuted.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ public function toString(): string
3333
*/
3434
protected function matches($other): bool
3535
{
36+
if (!$other instanceof TaskEventList) {
37+
return false;
38+
}
39+
3640
return $this->expectedCount === $this->countExecutedTasks($other);
3741
}
3842

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

47-
if (TaskInterface::SUCCEED !== $taskEvent->getTask()->getExecutionState()) {
51+
$task = $taskEvent->getTask();
52+
53+
if (TaskInterface::SUCCEED !== $task->getExecutionState()) {
4854
continue;
4955
}
5056

src/Test/Constraint/TaskFailed.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use SchedulerBundle\Event\TaskEventList;
99

1010
use function count;
11-
use function is_countable;
1211
use function sprintf;
1312

1413
/**
@@ -33,6 +32,10 @@ public function toString(): string
3332
*/
3433
protected function matches($other): bool
3534
{
36-
return $this->expectedCount === (is_countable($other->getFailedTaskEvents()) ? count($other->getFailedTaskEvents()) : 0);
35+
if (!$other instanceof TaskEventList) {
36+
return false;
37+
}
38+
39+
return $this->expectedCount === count($other->getFailedTaskEvents());
3740
}
3841
}

src/Test/Constraint/TaskQueued.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ public function toString(): string
3232
*/
3333
protected function matches($other): bool
3434
{
35+
if (!$other instanceof TaskEventList) {
36+
return false;
37+
}
38+
3539
return $this->expectedCount === $this->countQueuedTasks($other);
3640
}
3741

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

46-
if (!$taskEvent->getTask()->isQueued()) {
50+
$task = $taskEvent->getTask();
51+
52+
if (!$task->isQueued()) {
4753
continue;
4854
}
4955

src/Test/Constraint/TaskScheduled.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ public function toString(): string
3232
*/
3333
protected function matches($other): bool
3434
{
35-
return $this->expectedCount === (is_countable($other->getScheduledTaskEvents()) ? count($other->getScheduledTaskEvents()) : 0);
35+
if (!$other instanceof TaskEventList) {
36+
return false;
37+
}
38+
39+
return $this->expectedCount === count($other->getScheduledTaskEvents());
3640
}
3741
}

0 commit comments

Comments
 (0)