X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fbehat%2Fbehat%2Fsrc%2FBehat%2FTestwork%2FCall%2FHandler%2FException%2FClassNotFoundHandler.php;fp=vendor%2Fbehat%2Fbehat%2Fsrc%2FBehat%2FTestwork%2FCall%2FHandler%2FException%2FClassNotFoundHandler.php;h=8d0f488fd3a6a220fdd1907bfc3cef7c101f0bd8;hp=0000000000000000000000000000000000000000;hb=1270d9129ce8f27c9b28b10518e32132c58e0aca;hpb=c27c0f0cdaa3f354b1fe54a56ae7e854be6e3f68 diff --git a/vendor/behat/behat/src/Behat/Testwork/Call/Handler/Exception/ClassNotFoundHandler.php b/vendor/behat/behat/src/Behat/Testwork/Call/Handler/Exception/ClassNotFoundHandler.php new file mode 100644 index 000000000..8d0f488fd --- /dev/null +++ b/vendor/behat/behat/src/Behat/Testwork/Call/Handler/Exception/ClassNotFoundHandler.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 class not found exceptions. + * + * @see ExceptionHandler + * + * @author Konstantin Kudryashov + */ +abstract class ClassNotFoundHandler implements ExceptionHandler +{ + const PATTERN = "/^Class '([^']+)' not found$/"; + + /** + * {@inheritdoc} + */ + final public function supportsException($exception) + { + if (!$exception instanceof Error) { + return false; + } + + return null !== $this->extractNonExistentClass($exception); + } + + /** + * {@inheritdoc} + */ + final public function handleException($exception) + { + $this->handleNonExistentClass($this->extractNonExistentClass($exception)); + + return $exception; + } + + /** + * Override to handle non-existent class name. + * + * @param string $class + */ + abstract public function handleNonExistentClass($class); + + /** + * Extracts missing class name from the exception. + * + * @param Error $exception + * + * @return null|string + */ + private function extractNonExistentClass(Error $exception) + { + if (1 === preg_match(self::PATTERN, $exception->getMessage(), $matches)) { + return $matches[1]; + } + + return null; + } +}