Skip to content

Commit

Permalink
Fix Range\Single::containsRange() method (#76)
Browse files Browse the repository at this point in the history
* Add a test that detect the bug

* Remove wrong Range\Single::containsRange() method

It really doesn't work when checking a non-Single range
  • Loading branch information
mlocati authored Nov 10, 2021
1 parent 0a474d3 commit 28763c8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
17 changes: 0 additions & 17 deletions src/Range/Single.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,23 +143,6 @@ public function contains(AddressInterface $address)
return $result;
}

/**
* {@inheritdoc}
*
* @see \IPLib\Range\RangeInterface::containsRange()
*/
public function containsRange(RangeInterface $range)
{
$result = false;
if ($range->getAddressType() === $this->getAddressType()) {
if ($range->toString(false) === $this->toString(false)) {
$result = true;
}
}

return $result;
}

/**
* {@inheritdoc}
*
Expand Down
23 changes: 23 additions & 0 deletions test/tests/Membership/MembershipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,27 @@ public function testRangeMembership($rangeString, $otherRangeString, $contained)
)
);
}

public function sameRangeProvider()
{
return array(
array('1.2.3.4', '1.2.3.4/32'),
);
}

/**
* @dataProvider sameRangeProvider
*
* @param string $range1
* @param string $range2
*/
public function testSameRange($range1, $range2)
{
$rangeObject1 = Factory::rangeFromString($range1);
$rangeObject2 = Factory::rangeFromString($range2);
$this->assertTrue($rangeObject1->containsRange($rangeObject1), "{$range1} should contain {$range1}");
$this->assertTrue($rangeObject2->containsRange($rangeObject2), "{$range2} should contain {$range2}");
$this->assertTrue($rangeObject1->containsRange($rangeObject2), "{$range1} should contain {$range2}");
$this->assertTrue($rangeObject2->containsRange($rangeObject1), "{$range2} should contain {$range1}");
}
}

0 comments on commit 28763c8

Please sign in to comment.