liangzai-cool / hamcrest

Automatically exported from code.google.com/p/hamcrest
0 stars 0 forks source link

PHP: Hamcrest_MatcherAssert::doAssert() has no return value, but assertThat() returns it #114

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The global function assertThat() returns the result of 
Hamcrest_MatcherAssert::assertThat(), which in turn returns the result of 
Hamcrest_MatcherAssert::doAssert(), but doAssert() does not return any value. 
Instead, doAssert() either returns normally or throws an exception.

Is this intentional? Should doAssert() return true if the assertion passes? If 
not, should the other functions be changed not to have return values since they 
will always be null?

Original issue reported on code.google.com by emperorf...@gmail.com on 2 Jul 2010 at 6:24

GoogleCodeExporter commented 9 years ago
The two assertThat() functions no longer return a value, but this doesn't 
really affect anything since that results in them returning NULL.

I also changed assertThat() so that it accepts a single boolean argument for 
generic assertions without a message (not recommended), or if the third 
parameter is not a Matcher it is wrapped with equalTo().

    assertThat('name', $user->getName(), 'bob');

I might be able to do the same thing with the two-argument case. If you pass a 
string and boolean, I would assume you wanted the generic non-Matcher test:

    assertThat('apples are tasty', $apple->isTasty());

Otherwise the second argument would be wrapped with equalTo() and the first 
argument assumed to be the value to assert--not a message.

    assertThat($apple->isTasty(), true);

The problem with that is if isTasty() is broken to return a string the 
assertion would be interpreted as a generic boolean test and PASS.

Original comment by dharkn...@gmail.com on 12 Jul 2010 at 6:33