Skip to content

Commit

Permalink
Refactor UnitTestCase::mock()
Browse files Browse the repository at this point in the history
Makes it much simpler!
  • Loading branch information
bradfeehan committed May 9, 2014
1 parent 1a1c2d4 commit d72132a
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions tests/Desk/Test/Helper/UnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,12 @@ abstract protected function getMockedClass();
*/
protected function mock($methods = array(), array $constructorArgs = array())
{
$class = $this->getMockedClass();
$reflection = new ReflectionClass($class);
$mock = \Mockery::mock($this->getMockedClass(), $constructorArgs);

// Populate $mockedMethods with all methods defined on $class
// excluding any passed in to $methods
$mockedMethods = array();

$allMethods = $reflection->getMethods(ReflectionMethod::IS_PUBLIC);
foreach ($allMethods as $method) {
if (!in_array($method->getName(), (array) $methods)) {
$mockedMethods[] = $method->getName();
}
foreach ((array) $methods as $method) {
$mock->shouldReceive($method)->passthru();
}

$methods = implode(',', (array) $mockedMethods);
return \Mockery::mock("{$class}[{$methods}]", $constructorArgs);
return $mock;
}
}

0 comments on commit d72132a

Please sign in to comment.