sebastianbergmann / phpunit

The PHP Unit Testing framework.
https://phpunit.de/
BSD 3-Clause "New" or "Revised" License
19.69k stars 2.2k forks source link

Second argument of assertInstanceOf does not check for object #3045

Closed carusogabriel closed 6 years ago

carusogabriel commented 6 years ago
Q A
PHPUnit version latest
PHP version latest
Installation Method Composer

Hi,

While refactoring some tests (https://github.com/zendframework/zend-expressive/pull/590), we've discovered that the second argument of assertInstanceOf does not check if the given value is actually an object. Should we check it, or maybe extend the assertInstanceOf functionality to also accept a string and instantiate it if is an object?

dnaber-de commented 6 years ago

For what I see, assertInstanceOf() fails if the actual argument is a string. From the name of the method I would exactly expect that as a string is not an instance. Changing the behavior to the one of is_a('stdClass', 'stdClass', true) would thus be not a good idea, in my opinion.

sebastianbergmann commented 6 years ago

The IsInstanceOf constraint is -- and is supposed to be -- "just" a wrapper for the instanceof operator.