event-centric / EventCentric.Core

Event Sourcing and CQRS in PHP
MIT License
126 stars 9 forks source link

Compare two Identifier objects by value and type #11

Closed ianlet closed 10 years ago

ianlet commented 10 years ago

In EventCentric\Identifiers\Identifier.php, comment of method 'equals' says it should compare the value and the type of both Identifier object. But, the implementations (the fixtures) never do it. So for instance, using the equals method between an OrderId and a ProductId with same string value (I'm aware that it should not happen) will return true.

The following test is passing :

$orderId = OrderId::generate();
$productId = ProductId::fromString((string) $orderId);

$this->assertTrue($orderId->equals($productId));

Is it an issue that should be corrected?

revati commented 10 years ago

I think it should pass because you have created $orderId and $productId both with the same uuid string.

So when they are compared within equals method they both are casted to strings (and they are equal) and test passes (as it should).

ianlet commented 10 years ago

I'm pointing this out because of the description of the method. I agree with what you say but based on @mathiasverraes description it should compare the value and the type as well.

mathiasverraes commented 10 years ago

Thanks, my current thinking is that it's a bug indeed. If two objects of different types share the same value, it can be

proof and fix: https://github.com/event-centric/EventCentric.Core/pull/12