Skip to content

Commit

Permalink
III-2490 Add equal method on the IsInteger trait.
Browse files Browse the repository at this point in the history
  • Loading branch information
Luc Wollants committed Mar 6, 2018
1 parent db758ff commit d6a534b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/Integer/Behaviour/IsInteger.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ public function sameAs($other)
return get_class($this) === get_class($other) && $this->toInteger() === $other->toInteger();
}

/**
* @param IsInteger $other
* @return bool
*/
public function equals($other)
{
$this->guardSameType($other);
return $this->toInteger() === $other->toInteger();
}

/**
* @param IsInteger $other
* @return bool
Expand Down
6 changes: 4 additions & 2 deletions tests/Integer/Behaviour/IsIntegerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace TwoDotsTwice\ValueObject\Integer\Behaviour;

use TwoDotsTwice\ValueObject\String\Behaviour\MockString;

class IsIntegerTest extends \PHPUnit_Framework_TestCase
{
/**
Expand All @@ -29,6 +27,10 @@ public function it_should_be_comparable_to_other_objects_of_the_same_type()
$this->assertTrue($two->sameAs($two));
$this->assertFalse($one->sameAs($two));

$this->assertTrue($one->equals($one));
$this->assertFalse($one->equals($two));
$this->assertFalse($one->equals($three));

$this->assertFalse($one->lt($one));
$this->assertTrue($one->lt($two));
$this->assertTrue($one->lt($three));
Expand Down

0 comments on commit d6a534b

Please sign in to comment.