Skip to content

Commit

Permalink
Merge branch 'spatie:main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
kolaente authored Jul 15, 2024
2 parents d46bccf + 3d07098 commit e1dd279
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 11 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

All notable changes to `laravel-health` will be documented in this file.

## 1.29.2 - 2024-07-15

### What's Changed

* Fix serialization of non-closures by @Riley19280 in https://github.com/spatie/laravel-health/pull/233

**Full Changelog**: https://github.com/spatie/laravel-health/compare/1.29.1...1.29.2

## 1.29.1 - 2024-06-27

### What's Changed
Expand Down
20 changes: 14 additions & 6 deletions src/Checks/Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,16 @@ public function __serialize(): array
{
$vars = get_object_vars($this);

$serializableClosures = [];
$serializedShouldRun = [];
foreach ($vars['shouldRun'] as $shouldRun) {
$serializableClosures[] = new SerializableClosure($shouldRun);
if ($shouldRun instanceof \Closure) {
$serializedShouldRun[] = new SerializableClosure($shouldRun);
} else {
$serializedShouldRun[] = $shouldRun;
}
}

$vars['shouldRun'] = $serializableClosures;
$vars['shouldRun'] = $serializedShouldRun;

return $vars;
}
Expand All @@ -142,12 +146,16 @@ public function __unserialize(array $data): void
$this->$property = $value;
}

$unwrappedClosures = [];
$deserializedShouldRun = [];

foreach ($this->shouldRun as $shouldRun) {
$unwrappedClosures[] = $shouldRun->getClosure();
if ($shouldRun instanceof SerializableClosure) {
$deserializedShouldRun[] = $shouldRun->getClosure();
} else {
$deserializedShouldRun[] = $shouldRun;
}
}

$this->shouldRun = $unwrappedClosures;
$this->shouldRun = $deserializedShouldRun;
}
}
21 changes: 17 additions & 4 deletions tests/Checks/QueueCheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use function Pest\Laravel\artisan;
use function PHPUnit\Framework\assertCount;
use function PHPUnit\Framework\assertInstanceOf;
use function PHPUnit\Framework\assertIsBool;
use function Spatie\PestPluginTestTime\testTime;
use function Spatie\Snapshots\assertMatchesObjectSnapshot;
use function Spatie\Snapshots\assertMatchesSnapshot;
Expand Down Expand Up @@ -114,7 +115,7 @@
expect($this->queueCheck->getQueues())->toBe([$queueName]);
});

it('can be serialized', function () {
it('can serialize closures', function () {
$check = QueueCheck::new()
->onQueue('sync')
->if(fn () => false);
Expand All @@ -126,15 +127,27 @@
assertMatchesSnapshot($result);
});

it('can be unserialized', function () {
it('can serialize non closures', function () {
$check = QueueCheck::new()
->onQueue('sync')
->if(true);

$result = serialize($check);

assertMatchesSnapshot($result);
});

it('can unserialize', function () {
$check = QueueCheck::new()
->onQueue('sync')
->if(true)
->if(fn () => false);

$result = unserialize(serialize($check));

assertCount(1, $result->getRunConditions());
assertInstanceOf(Closure::class, $result->getRunConditions()[0]);
assertCount(2, $result->getRunConditions());
assertIsBool($result->getRunConditions()[0]);
assertInstanceOf(Closure::class, $result->getRunConditions()[1]);

assertMatchesObjectSnapshot($result);
});

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
O:38:"Spatie\Health\Checks\Checks\QueueCheck":8:{s:10:"expression";s:9:"* * * * *";s:4:"name";N;s:5:"label";N;s:9:"shouldRun";a:1:{i:0;O:47:"Laravel\SerializableClosure\SerializableClosure":1:{s:12:"serializable";O:46:"Laravel\SerializableClosure\Serializers\Native":5:{s:3:"use";a:0:{}s:8:"function";s:14:"fn () => false";s:5:"scope";s:29:"P\Tests\Checks\QueueCheckTest";s:4:"this";N;s:4:"self";s:32:"0000000000000000000000000000000000000000";}}}s:8:"cacheKey";s:37:"health:checks:queue:latestHeartbeatAt";s:14:"cacheStoreName";N;s:37:"failWhenTestJobTakesLongerThanMinutes";i:5;s:8:"onQueues";a:1:{i:0;s:4:"sync";}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
O:38:"Spatie\Health\Checks\Checks\QueueCheck":8:{s:10:"expression";s:9:"* * * * *";s:4:"name";N;s:5:"label";N;s:9:"shouldRun";a:1:{i:0;b:1;}s:8:"cacheKey";s:37:"health:checks:queue:latestHeartbeatAt";s:14:"cacheStoreName";N;s:37:"failWhenTestJobTakesLongerThanMinutes";i:5;s:8:"onQueues";a:1:{i:0;s:4:"sync";}}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ queues:
label: Queue
name: Queue
runConditions:
- true
- { }

0 comments on commit e1dd279

Please sign in to comment.