Skip to content

Instantly share code, notes, and snippets.

@everzet
Created January 18, 2012 16:44
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save everzet/1633955 to your computer and use it in GitHub Desktop.
Save everzet/1633955 to your computer and use it in GitHub Desktop.
View real exceptions in Behat output with Mink+SymfonyDriver in your Symfony2 feature suite
...
parameters:
test.client.class: Your\MainBundle\ExceptionalClient
<?php
namespace Your\MainBundle;
use Symfony\Bundle\FrameworkBundle\Client;
use Symfony\Component\HttpKernel\HttpKernelInterface;
class ExceptionalClient extends Client
{
static private $catchExceptions = true;
private $isRequestAlreadyPerformed = false;
static public function catchExceptions($catch = true)
{
self::$catchExceptions = (bool) $catch;
}
protected function doRequest($request)
{
if ($this->isRequestAlreadyPerformed) {
$this->kernel->shutdown();
} else {
$this->isRequestAlreadyPerformed = true;
}
return $this->kernel->handle(
$request, HttpKernelInterface::MASTER_REQUEST, self::$catchExceptions
);
}
}
<?php
...
/**
* @Given do not catch exceptions
*/
public function doNotCatchExceptions()
{
if (!$this->getSession()->getDriver() instanceof SymfonyDriver) {
throw new \RuntimeException('This step could be used only with SymfonyDriver');
}
$this->getSession()->getDriver()->getClient()->catchExceptions(false);
}
/**
* @BeforeScenario @exceptions
*/
public function dontCatchExceptions()
{
if (!$this->getSession()->getDriver() instanceof SymfonyDriver) {
throw new \RuntimeException('@exceptions tag could be used only with SymfonyDriver');
}
$this->getSession()->getDriver()->getClient()->catchExceptions(false);
}
/**
* @AfterScenario
*/
public function catchExceptions()
{
if ($this->getSession()->getDriver() instanceof SymfonyDriver) {
$this->getSession()->getDriver()->getClient()->catchExceptions(true);
}
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment