padraic/mockery — Issue #39: Proxying Objects -Another Gotcha
Author: royweston
Created: 2011-12-01 12:32:07+00:00
State: open

Came across this style of code. Proxying an object that is used in a 'method_exists' call breaks the code as the method is not defined on the proxy object. A simple but not so straight forward answer would be to change all the code to use type hinting.

```php
class AClass
{
public function aMethod()
{
return 3;
}
}

class BClass
{
public function __construct($aClass) {
if (!$aClass || !is_object($aClass) || !method_exists($aClass, "aMethod")) {
throw new Exception("Invalid AClass object passed to ".__METHOD__);
}
// ...
}
}

$stubAClass = \Mockery::mock('overload:AClass', array('aMethod' => null));
$bClass = new BClass($stubAClass);
```