Skip to content

Commit

Permalink
Allow whenHappen for added filters - See #3
Browse files Browse the repository at this point in the history
  • Loading branch information
gmazzap committed Jul 12, 2015
1 parent 20e14ae commit 3419d3c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Monkey/MockeryBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,15 @@ class MockeryBridge
public function __construct(ExpectationInterface $expectation, $parent = null)
{
$this->expectation = $expectation;
$name = $this->expectation->__toString();
if (is_string($parent) && class_exists($parent)) {
$reflection = new \ReflectionClass($parent);
$this->isHook = $reflection->isSubclassOf('Brain\Monkey\WP\Hooks');
$this->isAction =
$parent === 'Brain\Monkey\WP\Actions'
|| is_subclass_of($parent, 'Brain\Monkey\WP\Actions');
}
$this->isAddedHook = $this->isHook && strpos($name, '[add_') === 0;
}

/**
Expand Down Expand Up @@ -104,9 +106,9 @@ public function __call($name, array $arguments = [])
*/
public function whenHappen(callable $callback)
{
if (! $this->isAction) {
if (! $this->isAddedHook && ! $this->isAction) {
throw new RuntimeException(
'whenHappen() can only be used for WordPress action hook expectations.'
'whenHappen() can only be used for WordPress actions or added filters expectations.'
);
}

Expand Down

0 comments on commit 3419d3c

Please sign in to comment.