Skip to content

Commit

Permalink
BUG: Allow zero values for integers and floats within queued job rule. (
Browse files Browse the repository at this point in the history
  • Loading branch information
mfendeksilverstripe authored Mar 9, 2021
1 parent 00938b3 commit 2f7abff
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/DataObjects/QueuedJobRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand All @@ -74,7 +74,7 @@ public function getHandler()
*/
public function getMinimumProcessorUsage()
{
if ($this->getField('MinimumProcessorUsage')) {
if ($this->getField('MinimumProcessorUsage') !== null) {
return $this->getField('MinimumProcessorUsage');
}

Expand All @@ -88,7 +88,7 @@ public function getMinimumProcessorUsage()
*/
public function getMaximumProcessorUsage()
{
if ($this->getField('MaximumProcessorUsage')) {
if ($this->getField('MaximumProcessorUsage') !== null) {
return $this->getField('MaximumProcessorUsage');
}

Expand All @@ -102,7 +102,7 @@ public function getMaximumProcessorUsage()
*/
public function getMinimumMemoryUsage()
{
if ($this->getField('MinimumMemoryUsage')) {
if ($this->getField('MinimumMemoryUsage') !== null) {
return $this->getField('MinimumMemoryUsage');
}

Expand All @@ -114,7 +114,7 @@ public function getMinimumMemoryUsage()
*/
public function getMaximumMemoryUsage()
{
if ($this->getField('MaximumMemoryUsage')) {
if ($this->getField('MaximumMemoryUsage') !== null) {
return $this->getField('MaximumMemoryUsage');
}

Expand All @@ -128,7 +128,7 @@ public function getMaximumMemoryUsage()
*/
public function getMinimumSiblingProcessorUsage()
{
if ($this->getField('MinimumSiblingProcessorUsage')) {
if ($this->getField('MinimumSiblingProcessorUsage') !== null) {
return $this->getField('MinimumSiblingProcessorUsage');
}

Expand All @@ -142,7 +142,7 @@ public function getMinimumSiblingProcessorUsage()
*/
public function getMaximumSiblingProcessorUsage()
{
if ($this->getField('MaximumSiblingProcessorUsage')) {
if ($this->getField('MaximumSiblingProcessorUsage') !== null) {
return $this->getField('MaximumSiblingProcessorUsage');
}

Expand All @@ -156,7 +156,7 @@ public function getMaximumSiblingProcessorUsage()
*/
public function getMinimumSiblingMemoryUsage()
{
if ($this->getField('MinimumSiblingMemoryUsage')) {
if ($this->getField('MinimumSiblingMemoryUsage') !== null) {
return $this->getField('MinimumSiblingMemoryUsage');
}

Expand All @@ -170,7 +170,7 @@ public function getMinimumSiblingMemoryUsage()
*/
public function getMaximumSiblingMemoryUsage()
{
if ($this->getField('MaximumSiblingMemoryUsage')) {
if ($this->getField('MaximumSiblingMemoryUsage') !== null) {
return $this->getField('MaximumSiblingMemoryUsage');
}

Expand Down
60 changes: 60 additions & 0 deletions tests/QueuedJobRuleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace Symbiote\QueuedJobs\Tests;

use SilverStripe\Dev\SapphireTest;
use Symbiote\QueuedJobs\DataObjects\QueuedJobRule;

class QueuedJobRuleTest extends SapphireTest
{
/**
* @param string $property
* @param mixed $value
* @param mixed $expected
* @dataProvider ruleGetterProvider
*/
public function testQueueRuleGetters($property, $value, $expected)
{
$rule = QueuedJobRule::create();
$rule->{$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],
];
}
}

0 comments on commit 2f7abff

Please sign in to comment.