4 * This file is part of the Behat Testwork.
5 * (c) Konstantin Kudryashov <ever.zet@gmail.com>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
11 namespace Behat\Testwork\Call\Handler\Exception;
13 use Behat\Testwork\Call\Handler\ExceptionHandler;
17 * Handles method not found exceptions.
19 * @see ExceptionHandler
21 * @author Konstantin Kudryashov <ever.zet@gmail.com>
23 abstract class MethodNotFoundHandler implements ExceptionHandler
25 const PATTERN = '/^Call to undefined method ([^:]+)::([^\)]+)\(\)$/';
30 final public function supportsException($exception)
32 if (!$exception instanceof Error) {
36 return null !== $this->extractNonExistentCallable($exception);
42 final public function handleException($exception)
44 $this->handleNonExistentMethod($this->extractNonExistentCallable($exception));
50 * Override to handle non-existent method.
52 * @param array $callable
54 abstract public function handleNonExistentMethod(array $callable);
57 * Extract callable from exception.
59 * @param Error $exception
63 private function extractNonExistentCallable(Error $exception)
65 if (1 === preg_match(self::PATTERN, $exception->getMessage(), $matches)) {
66 return array($matches[1], $matches[2]);