Skip to content

Commit 09fb76a

Browse files
committed
refactor(core): improvements on constraints & tests
1 parent 80a751d commit 09fb76a

File tree

11 files changed

+53
-5
lines changed

11 files changed

+53
-5
lines changed

src/Test/Constraint/Probe/ProbeExecutedTask.php

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

src/Test/Constraint/Probe/ProbeFailedTask.php

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

src/Test/Constraint/Probe/ProbeScheduledTask.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
use PHPUnit\Framework\Constraint\Constraint;
88
use SchedulerBundle\Probe\ProbeInterface;
9+
use SchedulerBundle\SchedulerInterface;
10+
use Throwable;
911
use function sprintf;
1012

1113
/**
@@ -27,9 +29,15 @@ public function toString(): string
2729

2830
/**
2931
* @param mixed|ProbeInterface $other
32+
*
33+
* @throws Throwable {@see SchedulerInterface::getTasks()}
3034
*/
3135
protected function matches($other): bool
3236
{
37+
if (!$other instanceof ProbeInterface) {
38+
return false;
39+
}
40+
3341
return $this->expectedCount === $other->getScheduledTasks();
3442
}
3543
}

src/Test/Constraint/Probe/ProbeState.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ public function toString(): string
3434
*/
3535
protected function matches($other): bool
3636
{
37+
if (!$other instanceof ProbeInterface) {
38+
return false;
39+
}
40+
3741
return $this->expectedState === [
3842
'executedTasks' => $other->getExecutedTasks(),
3943
'failedTasks' => $other->getFailedTasks(),

src/Test/Constraint/Scheduler/SchedulerDueTask.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use PHPUnit\Framework\Constraint\Constraint;
88
use SchedulerBundle\SchedulerInterface;
9+
use Throwable;
910
use function sprintf;
1011

1112
/**
@@ -27,9 +28,15 @@ public function toString(): string
2728

2829
/**
2930
* @param mixed|SchedulerInterface $other
31+
*
32+
* @throws Throwable {@see SchedulerInterface::getDueTasks()}
3033
*/
3134
protected function matches($other): bool
3235
{
36+
if (!$other instanceof SchedulerInterface) {
37+
return false;
38+
}
39+
3340
return $this->expectedCount === $other->getDueTasks()->count();
3441
}
3542
}

src/Test/Constraint/TaskExecuted.php

Lines changed: 4 additions & 0 deletions
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->countExecutedTasks($other);
3640
}
3741

src/Test/Constraint/TaskFailed.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use PHPUnit\Framework\Constraint\Constraint;
88
use SchedulerBundle\Event\TaskEventList;
99
use function count;
10-
use function is_countable;
1110
use function sprintf;
1211

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

src/Test/Constraint/TaskQueued.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 TaskEventList) {
35+
return false;
36+
}
37+
3438
return $this->expectedCount === $this->countQueuedTasks($other);
3539
}
3640

src/Test/Constraint/TaskScheduled.php

Lines changed: 5 additions & 1 deletion
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-
return $this->expectedCount === (is_countable($other->getScheduledTaskEvents()) ? count($other->getScheduledTaskEvents()) : 0);
34+
if (!$other instanceof TaskEventList) {
35+
return false;
36+
}
37+
38+
return $this->expectedCount === count($other->getScheduledTaskEvents());
3539
}
3640
}

src/Test/Constraint/TaskUnscheduled.php

Lines changed: 5 additions & 1 deletion
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-
return $this->expectedCount === (is_countable($other->getUnscheduledTaskEvents()) ? count($other->getUnscheduledTaskEvents()) : 0);
34+
if (!$other instanceof TaskEventList) {
35+
return false;
36+
}
37+
38+
return $this->expectedCount === count($other->getUnscheduledTaskEvents());
3539
}
3640
}

0 commit comments

Comments
 (0)