Skip to content

Commit

Permalink
remove unnecessary setters and test cases of SlotRange
Browse files Browse the repository at this point in the history
  • Loading branch information
messikiller committed Nov 25, 2024
1 parent 561bd9d commit a6a0cb1
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 117 deletions.
58 changes: 0 additions & 58 deletions src/Cluster/SlotRange.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,54 +99,6 @@ public function getConnection()
return $this->connection;
}

/**
* Sets the start slot index of this range.
*
* @param int $start
*
* @return static
*/
public function setStart(int $start)
{
if (!static::isValidRange($start, $this->end)) {
throw new OutOfBoundsException("Invalid slot range start, range: {$start}-{$this->end}");
}
$this->start = $start;

return $this;
}

/**
* Sets the end slot index of this range.
*
* @param int $end
*
* @return static
*/
public function setEnd(int $end)
{
if (!static::isValidRange($this->start, $end)) {
throw new OutOfBoundsException("Invalid slot range end, range: {$this->start}-{$end}");
}
$this->end = $end;

return $this;
}

/**
* Sets the connection to the server hosting this slot range.
*
* @param string $connection
*
* @return static
*/
public function setConnection(string $connection)
{
$this->connection = $connection;

return $this;
}

/**
* Checks if the specific slot is contained in this range.
*
Expand All @@ -159,16 +111,6 @@ public function hasSlot(int $slot)
return $this->start <= $slot && $this->end >= $slot;
}

/**
* Returns a copy of this range.
*
* @return SlotRange
*/
public function copy(): SlotRange
{
return clone $this;
}

/**
* Returns an array of connection strings for each slot in this range.
*
Expand Down
60 changes: 1 addition & 59 deletions tests/Predis/Cluster/SlotRangeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,48 +59,13 @@ public function testIsValidRangeReturnsFalseOnInvalidSlotRange()
/**
* @group disconnected
*/
public function testPropertySettersAndGetters()
public function testPropertySetters()
{
$range = new SlotRange(2000, 5000, 'c1');

$this->assertEquals(2000, $range->getStart());
$this->assertEquals(5000, $range->getEnd());
$this->assertEquals('c1', $range->getConnection());

$range->setStart(3000);
$this->assertEquals(3000, $range->getStart());

$range->setEnd(8000);
$this->assertEquals(8000, $range->getEnd());

$range->setConnection('c2');
$this->assertEquals('c2', $range->getConnection());
}

/**
* @group disconnected
*/
public function testSetStartThrowExceptionOnInvalidSlotRange(): void
{
$this->expectException('OutOfBoundsException');
$this->expectExceptionMessage('Invalid slot range start, range: 5000-3000');

$range = new SlotRange(1000, 3000, 'c1');

$range->setStart(5000);
}

/**
* @group disconnected
*/
public function testSetEndThrowExceptionOnInvalidSlotRange(): void
{
$this->expectException('OutOfBoundsException');
$this->expectExceptionMessage('Invalid slot range end, range: 1000-100');

$range = new SlotRange(1000, 3000, 'c1');

$range->setEnd(100);
}

/**
Expand All @@ -118,29 +83,6 @@ public function testHasSlot()
$this->assertFalse($range->hasSlot(5000));
}

/**
* @group disconnected
*/
public function testCopy()
{
$range = new SlotRange(1000, 3000, 'c1');

$copy = $range->copy();

$this->assertInstanceOf(SlotRange::class, $copy);
$this->assertEquals(1000, $copy->getStart());
$this->assertEquals(3000, $copy->getEnd());
$this->assertEquals('c1', $copy->getConnection());

$this->assertEquals($range, $copy);
$this->assertNotSame($range, $copy);

$range->setStart(1500);
$this->assertNotEquals($range, $copy);
$this->assertEquals(1500, $range->getStart());
$this->assertEquals(1000, $copy->getStart());
}

/**
* @group disconnected
*/
Expand Down

0 comments on commit a6a0cb1

Please sign in to comment.