ExpectationException.php in Zircon Profile 8.0
File
vendor/behat/mink/src/Exception/ExpectationException.php
View source
<?php
namespace Behat\Mink\Exception;
use Behat\Mink\Driver\DriverInterface;
use Behat\Mink\Session;
class ExpectationException extends Exception {
private $session;
private $driver;
public function __construct($message, $driver, \Exception $exception = null) {
if ($driver instanceof Session) {
@trigger_error('Passing a Session object to the ExpectationException constructor is deprecated as of Mink 1.7. Pass the driver instead.', E_USER_DEPRECATED);
$this->session = $driver;
$this->driver = $driver
->getDriver();
}
elseif (!$driver instanceof DriverInterface) {
throw new \InvalidArgumentException('The ExpectationException constructor expects a DriverInterface or a Session.');
}
else {
$this->driver = $driver;
}
if (!$message && null !== $exception) {
$message = $exception
->getMessage();
}
parent::__construct($message, 0, $exception);
}
public function __toString() {
try {
$pageText = $this
->pipeString($this
->trimString($this
->getContext()) . "\n");
$string = sprintf("%s\n\n%s%s", $this
->getMessage(), $this
->getResponseInfo(), $pageText);
} catch (\Exception $e) {
return $this
->getMessage();
}
return $string;
}
protected function getContext() {
return $this
->trimBody($this->driver
->getContent());
}
protected function getDriver() {
return $this->driver;
}
protected function getSession() {
if (null === $this->session) {
throw new \LogicException(sprintf('The deprecated method %s cannot be used when passing a driver in the constructor', __METHOD__));
}
@trigger_error(sprintf('The method %s is deprecated as of Mink 1.7 and will be removed in 2.0. Use getDriver and the driver API instead.'));
return $this->session;
}
protected function pipeString($string) {
return '| ' . strtr($string, array(
"\n" => "\n| ",
));
}
protected function trimBody($string) {
$string = preg_replace(array(
'/^.*<body>/s',
'/<\\/body>.*$/s',
), array(
'<body>',
'</body>',
), $string);
return $string;
}
protected function trimString($string, $count = 1000) {
$string = trim($string);
if ($count < mb_strlen($string)) {
return mb_substr($string, 0, $count - 3) . '...';
}
return $string;
}
protected function getResponseInfo() {
$driver = basename(str_replace('\\', '/', get_class($this->driver)));
$info = '+--[ ';
try {
$info .= 'HTTP/1.1 ' . $this->driver
->getStatusCode() . ' | ';
} catch (UnsupportedDriverActionException $e) {
}
$info .= $this->driver
->getCurrentUrl() . ' | ' . $driver . " ]\n|\n";
return $info;
}
}