From 2f7abffc357154e369c0c35ea54346d2d21a65c8 Mon Sep 17 00:00:00 2001 From: Mojmir Fendek Date: Wed, 10 Mar 2021 09:45:55 +1300 Subject: [PATCH] BUG: Allow zero values for integers and floats within queued job rule. (#337) --- src/DataObjects/QueuedJobRule.php | 18 +++++----- tests/QueuedJobRuleTest.php | 60 +++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 9 deletions(-) create mode 100644 tests/QueuedJobRuleTest.php diff --git a/src/DataObjects/QueuedJobRule.php b/src/DataObjects/QueuedJobRule.php index b86ad6e8..bac8b104 100644 --- a/src/DataObjects/QueuedJobRule.php +++ b/src/DataObjects/QueuedJobRule.php @@ -48,7 +48,7 @@ class QueuedJobRule extends DataObject implements Rule */ public function getProcesses() { - if ($this->getField('Processes')) { + if ($this->getField('Processes') !== null) { return $this->getField('Processes'); } @@ -74,7 +74,7 @@ public function getHandler() */ public function getMinimumProcessorUsage() { - if ($this->getField('MinimumProcessorUsage')) { + if ($this->getField('MinimumProcessorUsage') !== null) { return $this->getField('MinimumProcessorUsage'); } @@ -88,7 +88,7 @@ public function getMinimumProcessorUsage() */ public function getMaximumProcessorUsage() { - if ($this->getField('MaximumProcessorUsage')) { + if ($this->getField('MaximumProcessorUsage') !== null) { return $this->getField('MaximumProcessorUsage'); } @@ -102,7 +102,7 @@ public function getMaximumProcessorUsage() */ public function getMinimumMemoryUsage() { - if ($this->getField('MinimumMemoryUsage')) { + if ($this->getField('MinimumMemoryUsage') !== null) { return $this->getField('MinimumMemoryUsage'); } @@ -114,7 +114,7 @@ public function getMinimumMemoryUsage() */ public function getMaximumMemoryUsage() { - if ($this->getField('MaximumMemoryUsage')) { + if ($this->getField('MaximumMemoryUsage') !== null) { return $this->getField('MaximumMemoryUsage'); } @@ -128,7 +128,7 @@ public function getMaximumMemoryUsage() */ public function getMinimumSiblingProcessorUsage() { - if ($this->getField('MinimumSiblingProcessorUsage')) { + if ($this->getField('MinimumSiblingProcessorUsage') !== null) { return $this->getField('MinimumSiblingProcessorUsage'); } @@ -142,7 +142,7 @@ public function getMinimumSiblingProcessorUsage() */ public function getMaximumSiblingProcessorUsage() { - if ($this->getField('MaximumSiblingProcessorUsage')) { + if ($this->getField('MaximumSiblingProcessorUsage') !== null) { return $this->getField('MaximumSiblingProcessorUsage'); } @@ -156,7 +156,7 @@ public function getMaximumSiblingProcessorUsage() */ public function getMinimumSiblingMemoryUsage() { - if ($this->getField('MinimumSiblingMemoryUsage')) { + if ($this->getField('MinimumSiblingMemoryUsage') !== null) { return $this->getField('MinimumSiblingMemoryUsage'); } @@ -170,7 +170,7 @@ public function getMinimumSiblingMemoryUsage() */ public function getMaximumSiblingMemoryUsage() { - if ($this->getField('MaximumSiblingMemoryUsage')) { + if ($this->getField('MaximumSiblingMemoryUsage') !== null) { return $this->getField('MaximumSiblingMemoryUsage'); } diff --git a/tests/QueuedJobRuleTest.php b/tests/QueuedJobRuleTest.php new file mode 100644 index 00000000..e1ed7574 --- /dev/null +++ b/tests/QueuedJobRuleTest.php @@ -0,0 +1,60 @@ +{$property} = $value; + + $this->assertSame($expected, $rule->{$property}); + } + + public function ruleGetterProvider(): array + { + return [ + ['Processes', null, 1], + ['Processes', 0, 0], + ['Processes', 1, 1], + ['Processes', 2, 2], + ['Handler', null, null], + ['Handler', '', null], + ['Handler', 'Test', 'Test'], + ['MinimumProcessorUsage', null, null], + ['MinimumProcessorUsage', 0, 0], + ['MinimumProcessorUsage', 1, 1], + ['MaximumProcessorUsage', null, null], + ['MaximumProcessorUsage', 0, 0], + ['MaximumProcessorUsage', 1, 1], + ['MinimumMemoryUsage', null, null], + ['MinimumMemoryUsage', 0, 0], + ['MinimumMemoryUsage', 1, 1], + ['MaximumMemoryUsage', null, null], + ['MaximumMemoryUsage', 0, 0], + ['MaximumMemoryUsage', 1, 1], + ['MinimumSiblingProcessorUsage', null, null], + ['MinimumSiblingProcessorUsage', 0, 0], + ['MinimumSiblingProcessorUsage', 1, 1], + ['MaximumSiblingProcessorUsage', null, null], + ['MaximumSiblingProcessorUsage', 0, 0], + ['MaximumSiblingProcessorUsage', 1, 1], + ['MinimumSiblingMemoryUsage', null, null], + ['MinimumSiblingMemoryUsage', 0, 0], + ['MinimumSiblingMemoryUsage', 1, 1], + ['MaximumSiblingMemoryUsage', null, null], + ['MaximumSiblingMemoryUsage', 0, 0], + ['MaximumSiblingMemoryUsage', 1, 1], + ]; + } +}