Created
January 18, 2012 16:44
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
parameters: | |
test.client.class: Your\MainBundle\ExceptionalClient |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 | |
); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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