mr-sun / hamcrest

Hamcrest matchers for c++ (using with carnamock)
0 stars 0 forks source link

EqualTo matcher should check objects for equals() method #168

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Even though PHP doesn't have a natural equals() method concept, it makes more 
sense to compare two objects using one's equals() method rather than comparing 
that they have the same class.

    assertThat($foo, is($bar));

This should be equivalent to

    assertThat($foo->equals($bar), is(true));

because it's far more interesting than

    assertThat(get_class($foo), is(get_class($bar)));

A new sameClass() matcher or overriding anInstanceOf() to accept an object 
would make more sense for the last case.

Original issue reported on code.google.com by dharkn...@gmail.com on 16 Dec 2011 at 7:02

GoogleCodeExporter commented 8 years ago
So it turns out that == already compares object attributes in addition to their 
classes. There probably isn't much need to check for an equals() method that 
alters this behavior, and in those cases you can call it directly.

Original comment by dharkn...@gmail.com on 16 Dec 2011 at 7:15