Skip to content

Commit

Permalink
Fix missing matcher passing silently bug
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelloDuarte committed Jan 22, 2012
1 parent 2256f84 commit fb21591
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
7 changes: 7 additions & 0 deletions spec/Loader/ClassLoaderSpec.php
Expand Up @@ -64,4 +64,11 @@ function itThrowsAnErrorIfItCannotFindTheConventionClassInIt()
})->should->throwException('\PHPSpec\Runner\Error', "Could not find class \"$class\" in file \"$file\"");
unlink($file);
}

function after()
{
if (file_exists(realpath(__DIR__ . '/_files') . '/NoFooSpec.php')) {
unlink(realpath(__DIR__ . '/_files') . '/NoFooSpec.php');
}
}
}
2 changes: 1 addition & 1 deletion spec/Matcher/PredicateSpec.php
@@ -1,6 +1,6 @@
<?php

namespace Spec\PHPspec\Matcher;
namespace Spec\PHPSpec\Matcher;

use \PHPSpec\Matcher\Predicate;

Expand Down
7 changes: 7 additions & 0 deletions src/PHPSpec/Specification/Interceptor.php
Expand Up @@ -152,6 +152,13 @@ public function __call($method, $args)
$this->_actualValue, $args
);
}

if (!$this instanceof Interceptor\Object &&
$this->_expectation !== null) {
throw new \BadMethodCallException(
"Call to undefined method $method"
);
}
}

/**
Expand Down
10 changes: 8 additions & 2 deletions src/PHPSpec/Specification/Interceptor/Object.php
Expand Up @@ -62,8 +62,14 @@ public function __call($method, $args)
}

$object = $this->getActualValue();
return InterceptorFactory::create(
call_user_func_array(array($object, $method), $args)
if (method_exists($object, $method)) {
return InterceptorFactory::create(
call_user_func_array(array($object, $method), $args)
);
}
$class = get_class($object);
throw new \BadMethodCallException(
"Call to undefined method {$class}::{$method}"
);
}

Expand Down

0 comments on commit fb21591

Please sign in to comment.