From 85a8ef95a89cdc94634d6a4b1f6ed0a9e6c79872 Mon Sep 17 00:00:00 2001 From: Kirk Mayo Date: Thu, 6 Oct 2022 11:40:01 +1300 Subject: [PATCH 1/2] FIX Handle URLsToProcess being null --- src/Job.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Job.php b/src/Job.php index f1e02b71..b815bb8b 100644 --- a/src/Job.php +++ b/src/Job.php @@ -104,6 +104,9 @@ public function setup(): void public function getSignature(): string { + if (!$this->URLsToProcess) { + return md5(static::class); + } return md5(implode('-', [static::class, implode('-', array_keys($this->URLsToProcess))])); } @@ -112,14 +115,16 @@ public function process(): void $chunkSize = $this->getChunkSize(); $count = 0; - foreach ($this->URLsToProcess as $url => $priority) { - $count += 1; + if ($this->URLsToProcess) { + foreach ($this->URLsToProcess as $url => $priority) { + $count += 1; - if ($chunkSize > 0 && $count > $chunkSize) { - return; - } + if ($chunkSize > 0 && $count > $chunkSize) { + return; + } - $this->processUrl($url, $priority); + $this->processUrl($url, $priority); + } } $this->updateCompletedState(); @@ -165,7 +170,7 @@ protected function markUrlAsProcessed(string $url): void */ protected function updateCompletedState(): void { - if (count($this->URLsToProcess) > 0) { + if ($this->URLsToProcess && count($this->URLsToProcess) > 0) { return; } From 3f93eb82aaee24ac9ab22c2397858289baf044a1 Mon Sep 17 00:00:00 2001 From: Kirk Mayo Date: Wed, 19 Oct 2022 14:04:32 +1300 Subject: [PATCH 2/2] MNT Unit test for Delete static cache job --- tests/php/RunDeleteCacheJobTest.php | 42 +++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tests/php/RunDeleteCacheJobTest.php diff --git a/tests/php/RunDeleteCacheJobTest.php b/tests/php/RunDeleteCacheJobTest.php new file mode 100644 index 00000000..bfa7519f --- /dev/null +++ b/tests/php/RunDeleteCacheJobTest.php @@ -0,0 +1,42 @@ +getJobData(); + $signature = $job->getSignature(); + $this->assertEmpty($data->jobData); + $this->assertFalse($data->isComplete); + + $job->hydrate(['/' => 1], null); + $data = $job->getJobData(); + $this->assertIsObject($data->jobData); + $this->assertFalse($data->isComplete); + $hydratedSignature = $job->getSignature(); + + // hydrating the job should affect the signature + $this->assertNotEquals($signature, $hydratedSignature); + } + + // test that the job can process regardless of URLsToProcess + public function testJobCanComplete() + { + $job = new DeleteStaticCacheJob(); + $job->process(); + $data = $job->getJobData(); + $this->assertTrue($data->isComplete); + + $job = new DeleteStaticCacheJob(); + $job->hydrate(['/' => 1], null); + $job->process(); + $data = $job->getJobData(); + $this->assertTrue($data->isComplete); + } +}