Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Updated contexts for Behat 2.4 #26

Merged
merged 7 commits into from

3 participants

@jakzal

Following contexts were updated and tested with Behat 2.4:

  • SymfonyDoctrineContext
  • SymfonyMailerContext
  • MinkRedirectContext
  • MinkExtraContext

I didn't test neither WebApiContext nor Behat1BCContext but it looks like these two are not affected by recent Behat changes.

Behat/CommonContexts/SymfonyMailerContext.php
((5 lines not shown))
use Behat\Behat\Context\BehatContext;
+use Behat\MinkExtension\Context\RawMinkContext;
+use Symfony\Component\HttpKernel\KernelInterface;
@Inoryy
Inoryy added a note

Missed use Behat\Symfony2Extension\Context\KernelAwareInterface here

@jakzal
jakzal added a note

Added, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@jakzal

If there's no more suggestions this PR is ready to be merged.

@everzet everzet merged commit fdd3472 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
8 Behat/CommonContexts/MinkExtraContext.php
@@ -26,7 +26,7 @@ public function pageShouldExist($page)
{
return array(
new Step\When('I go to "'.$page.'"'),
- new Step\Then('The response status code should not be 404'),
+ new Step\Then('the response status code should not be 404'),
);
}
@@ -41,7 +41,7 @@ public function pageShouldNotExist($page)
{
return array(
new Step\When('I go to "'.$page.'"'),
- new Step\Then('The response status code should be 404'),
+ new Step\Then('the response status code should be 404'),
);
}
@@ -56,7 +56,7 @@ public function iShouldNotBeAllowedToGoTo($page)
{
return array(
new Step\When('I go to "'.$page.'"'),
- new Step\Then('The response status code should be 403'),
+ new Step\Then('the response status code should be 403'),
);
}
@@ -71,7 +71,7 @@ public function iShouldBeAllowedToGoTo($page)
{
return array(
new Step\When('I go to "'.$page.'"'),
- new Step\Then('The response status code should be 200'),
+ new Step\Then('the response status code should be 200'),
);
}
}
View
28 Behat/CommonContexts/MinkRedirectContext.php
@@ -5,10 +5,10 @@
require_once 'PHPUnit/Autoload.php';
require_once 'PHPUnit/Framework/Assert/Functions.php';
-use Behat\Behat\Context\BehatContext;
+use Behat\MinkExtension\Context\RawMinkContext;
use Behat\Mink\Exception\UnsupportedDriverActionException,
- Behat\Mink\Driver\GoutteDriver;
+ Behat\Mink\Driver\BrowserKitDriver;
/**
* Context class for managing redirects within an application.
@@ -16,7 +16,7 @@
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
* @author Marijn Huizendveld <marijn.huizendveld@gmail.com>
*/
-class MinkRedirectContext extends BehatContext
+class MinkRedirectContext extends RawMinkContext
{
/**
* Prevent following redirects.
@@ -39,7 +39,7 @@ public function iDoNotFollowRedirects()
*/
public function afterScenario($event)
{
- if ($this->getSession()->getDriver() instanceof GoutteDriver) {
+ if ($this->getSession()->getDriver() instanceof BrowserKitDriver) {
$this->getClient()->followRedirects(true);
}
}
@@ -55,8 +55,7 @@ public function afterScenario($event)
*/
public function iAmRedirected($location = null)
{
- $session = $this->getSession();
- $headers = $session->getResponseHeaders();
+ $headers = $this->getSession()->getResponseHeaders();
assertArrayHasKey('Location', $headers, 'The response contains a "Location" header');
@@ -84,25 +83,12 @@ protected function getClient()
{
$driver = $this->getSession()->getDriver();
- if (!$driver instanceof GoutteDriver) {
- $message = "This step is only supported by the @mink:symfony and @mink:goutte drivers";
+ if (!$driver instanceof BrowserKitDriver) {
+ $message = 'This step is only supported by the browserkit drivers';
throw new UnsupportedDriverActionException($message, $driver);
}
return $driver->getClient();
}
-
- /**
- * Returns current active mink session.
- *
- * If you are using MinkContext as a subcontext instead of using it as
- * the main one, overwrite this method
- *
- * @return Behat\Mink\Session
- */
- protected function getSession()
- {
- return $this->getMainContext()->getSession();
- }
}
View
46 Behat/CommonContexts/SymfonyDoctrineContext.php
@@ -2,9 +2,11 @@
namespace Behat\CommonContexts;
-use Behat\BehatBundle\Context\BehatContext;
+use Behat\Behat\Context\BehatContext;
use Behat\Behat\Event\ScenarioEvent;
+use Behat\Symfony2Extension\Context\KernelAwareInterface;
use Doctrine\ORM\Tools\SchemaTool;
+use Symfony\Component\HttpKernel\KernelInterface;
/**
* Provides hooks for building and cleaning up a database schema with Doctrine.
@@ -13,9 +15,14 @@
*
* @author Jakub Zalas <jakub@zalas.pl>
*/
-class SymfonyDoctrineContext extends BehatContext
+class SymfonyDoctrineContext extends BehatContext implements KernelAwareInterface
{
/**
+ * @var \Symfony\Component\HttpKernel\KernelInterface $kernel
+ */
+ private $kernel = null;
+
+ /**
* @param \Behat\Behat\Event\ScenarioEvent|\Behat\Behat\Event\OutlineExampleEvent $event
*
* @BeforeScenario
@@ -50,6 +57,16 @@ public function closeDBALConnections($event)
}
/**
+ * @param \Symfony\Component\HttpKernel\KernelInterface $kernel
+ *
+ * @return null
+ */
+ public function setKernel(KernelInterface $kernel)
+ {
+ $this->kernel = $kernel;
+ }
+
+ /**
* @return array
*/
protected function getMetadata()
@@ -62,7 +79,7 @@ protected function getMetadata()
*/
protected function getEntityManager()
{
- return $this->getContainer()->get('doctrine.orm.entity_manager');
+ return $this->kernel->getContainer()->get('doctrine.orm.entity_manager');
}
/**
@@ -70,27 +87,6 @@ protected function getEntityManager()
*/
protected function getConnections()
{
- if ($this->getContainer()->has('behat.mink')) {
- $driver = $this->getMinkContext()->getSession()->getDriver();
-
- if ($driver instanceof \Behat\MinkBundle\Driver\SymfonyDriver) {
- return $driver->getClient()->getContainer()->get('doctrine')->getConnections();
- }
- }
-
- return $this->getContainer()->get('doctrine')->getConnections();
- }
-
- /**
- * Gets the Mink context.
- *
- * If you are using MinkContext as a subcontext instead of using it as
- * the main one, overwrite this method
- *
- * @return \Behat\Mink\Behat\Context\BaseMinkContext
- */
- protected function getMinkContext()
- {
- return $this->getMainContext();
+ return $this->kernel->getContainer()->get('doctrine')->getConnections();
}
}
View
33 Behat/CommonContexts/SymfonyMailerContext.php
@@ -2,19 +2,29 @@
namespace Behat\CommonContexts;
-use Symfony\Component\HttpKernel\KernelInterface;
use Behat\Behat\Context\BehatContext;
+use Behat\Symfony2Extension\Context\KernelAwareInterface;
+use Behat\MinkExtension\Context\RawMinkContext;
+use Symfony\Component\HttpKernel\KernelInterface;
/**
* Provides some steps/methods which are useful for testing a Symfony2 application.
*
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/
-class SymfonyMailerContext extends BehatContext
+class SymfonyMailerContext extends RawMinkContext implements KernelAwareInterface
{
- private $kernel;
+ /**
+ * @var \Symfony\Component\HttpKernel\KernelInterface $kernel
+ */
+ private $kernel = null;
- public function __construct(KernelInterface $kernel)
+ /**
+ * @param \Symfony\Component\HttpKernel\KernelInterface $kernel
+ *
+ * @return null
+ */
+ public function setKernel(KernelInterface $kernel)
{
$this->kernel = $kernel;
}
@@ -91,7 +101,7 @@ public function emailWithSubjectShouldHaveBeenSent($subject, $to = null)
public function loadProfile($token = null)
{
if (null === $token) {
- $headers = $this->getMinkContext()->getSession()->getResponseHeaders();
+ $headers = $this->getSession()->getResponseHeaders();
if (!isset($headers['X-Debug-Token']) && !isset($headers['x-debug-token'])) {
throw new \RuntimeException('Debug-Token not found in response headers. Have you turned on the debug flag?');
@@ -101,17 +111,4 @@ public function loadProfile($token = null)
return $this->kernel->getContainer()->get('profiler')->loadProfile($token);
}
-
- /**
- * Gets the Mink context.
- *
- * If you are using MinkContext as a subcontext instead of using it as
- * the main one, overwrite this method
- *
- * @return \Behat\Mink\Behat\Context\BaseMinkContext
- */
- protected function getMinkContext()
- {
- return $this->getMainContext();
- }
}
View
19 README.md
@@ -16,26 +16,17 @@ that:
namespace Acme\DemoBundle\Features\Context;
-use Behat\BehatBundle\Context\BehatContext,
- Behat\BehatBundle\Context\MinkContext;
-use Behat\Behat\Context\ClosuredContextInterface,
- Behat\Behat\Context\TranslatedContextInterface,
- Behat\Behat\Exception\PendingException;
-use Behat\Gherkin\Node\PyStringNode,
- Behat\Gherkin\Node\TableNode;
+use Behat\Behat\Context\BehatContext;
+use Behat\CommonContexts\SymfonyMailerContext;
/**
* Feature context.
*/
-class FeatureContext extends MinkContext
+class FeatureContext extends BehatContext
{
- public function __construct($kernel)
+ public function __construct()
{
- $this->useContext('symfony_extra',
- new \Behat\CommonContexts\SymfonyMailerContext($kernel)
- );
-
- parent::__construct($kernel);
+ $this->useContext('symfony_extra', new SymfonyMailerContext());
}
}
View
8 composer.json
@@ -34,10 +34,10 @@
},
"suggest": {
- "behat/behat-bundle": "*",
- "behat/mink-bundle": "*",
- "doctrine/doctrine-bundle": "*",
- "kriswallsmith/buzz": ">=0.5.0"
+ "behat/symfony2-extension": "*",
+ "behat/mink-extension": "*",
+ "doctrine/doctrine-bundle": "*",
+ "kriswallsmith/buzz": ">=0.5.0"
},
"autoload": {
Something went wrong with that request. Please try again.