X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=vendor%2Fbehat%2Fbehat%2Fsrc%2FBehat%2FTestwork%2FCall%2FHandler%2FException%2FMethodNotFoundHandler.php;fp=vendor%2Fbehat%2Fbehat%2Fsrc%2FBehat%2FTestwork%2FCall%2FHandler%2FException%2FMethodNotFoundHandler.php;h=3ca680dae9d1dca78892df9e13820eb98a01a7d9;hb=1270d9129ce8f27c9b28b10518e32132c58e0aca;hp=0000000000000000000000000000000000000000;hpb=c27c0f0cdaa3f354b1fe54a56ae7e854be6e3f68;p=yaffs-website diff --git a/vendor/behat/behat/src/Behat/Testwork/Call/Handler/Exception/MethodNotFoundHandler.php b/vendor/behat/behat/src/Behat/Testwork/Call/Handler/Exception/MethodNotFoundHandler.php new file mode 100644 index 000000000..3ca680dae --- /dev/null +++ b/vendor/behat/behat/src/Behat/Testwork/Call/Handler/Exception/MethodNotFoundHandler.php @@ -0,0 +1,71 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Behat\Testwork\Call\Handler\Exception; + +use Behat\Testwork\Call\Handler\ExceptionHandler; +use Error; + +/** + * Handles method not found exceptions. + * + * @see ExceptionHandler + * + * @author Konstantin Kudryashov + */ +abstract class MethodNotFoundHandler implements ExceptionHandler +{ + const PATTERN = '/^Call to undefined method ([^:]+)::([^\)]+)\(\)$/'; + + /** + * {@inheritdoc} + */ + final public function supportsException($exception) + { + if (!$exception instanceof Error) { + return false; + } + + return null !== $this->extractNonExistentCallable($exception); + } + + /** + * {@inheritdoc} + */ + final public function handleException($exception) + { + $this->handleNonExistentMethod($this->extractNonExistentCallable($exception)); + + return $exception; + } + + /** + * Override to handle non-existent method. + * + * @param array $callable + */ + abstract public function handleNonExistentMethod(array $callable); + + /** + * Extract callable from exception. + * + * @param Error $exception + * + * @return null|array + */ + private function extractNonExistentCallable(Error $exception) + { + if (1 === preg_match(self::PATTERN, $exception->getMessage(), $matches)) { + return array($matches[1], $matches[2]); + } + + return null; + } +}