Skip to content

Loading…

[RFC] Feature/behat24 #194

Merged
merged 1 commit into from

4 participants

@cordoval

Build Status

This upgrades knpbundles.com to use behat 2.4

Tests: passed on local + travis

updated according to this guide

@cordoval cordoval was assigned
@everzet everzet commented on an outdated diff
composer.json
@@ -14,10 +14,13 @@
"sensio/distribution-bundle": "*",
"jms/i18n-routing-bundle": "*",
- "behat/behat": "2.3.*",
- "behat/behat-bundle": "*",
- "behat/mink-bundle": "*",
- "behat/common-contexts": "1.1.*",
+ "behat/behat": "*",
@everzet
everzet added a note

This should be dev requirements.

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@everzet everzet commented on an outdated diff
behat.yml
@@ -0,0 +1,14 @@
+default:
+ formatter:
+ name: progress
+ extensions:
+ Behat\Symfony2Extension\Extension:
+ mink_driver: true
+ kernel:
+ env: test
+ debug: true
+ Behat\MinkExtension\Extension:
+ base_url: 'http://knpbundles.local/app_test.php/'
@everzet
everzet added a note

This is environment-sensitive information. You should give developers ability to redefine it. Rename behat.yml to behat.yml.dist

done, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@everzet everzet commented on an outdated diff
.../KnpBundlesBundle/Features/Context/FeatureContext.php
((16 lines not shown))
public function __construct($kernel)
{
- $this->useContext('symfony_doctrine', new \Behat\CommonContexts\SymfonyDoctrineContext($kernel));
- $this->useContext('solr', new \Knp\Bundle\KnpBundlesBundle\Features\Context\SolrContext($kernel));
-
- parent::__construct($kernel);
+ $this->useContext('symfony_doctrine', new \Behat\CommonContexts\SymfonyDoctrineContext());
+ $this->useContext('solr', new \Knp\Bundle\KnpBundlesBundle\Features\Context\SolrContext());
@everzet
everzet added a note

Why not using namespace aliases (use ...;) as you already started anyway?

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@everzet everzet commented on an outdated diff
...dle/KnpBundlesBundle/Features/Context/SolrContext.php
((6 lines not shown))
{
/**
+ * @var \Symfony\Component\HttpKernel\KernelInterface $kernel
+ */
+ private $kernel = null;
@everzet
everzet added a note

null is the default value anyway. In PHP there's no uninitialized variables.

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@stof stof commented on an outdated diff
app/AppKernel.php
@@ -39,8 +39,7 @@ public function registerBundles()
);
if ('test' === $this->getEnvironment()) {
- $bundles[] = new Behat\BehatBundle\BehatBundle();
- $bundles[] = new Behat\MinkBundle\MinkBundle();
+ // initialization of tester bundles
}
@stof KNP Labs member
stof added a note

you should remove this useless if entirely

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@stof stof commented on an outdated diff
composer.json
@@ -14,10 +14,13 @@
"sensio/distribution-bundle": "*",
"jms/i18n-routing-bundle": "*",
- "behat/behat": "2.3.*",
- "behat/behat-bundle": "*",
- "behat/mink-bundle": "*",
- "behat/common-contexts": "1.1.*",
+ "behat/behat": "*",
+ "behat/symfony2-extension": "*",
+ "behat/mink-extension": "*",
+ "behat/mink-browserkit-driver": "*",
+ "behat/mink-selenium2-driver": "*",
@stof KNP Labs member
stof added a note

you don't need this one as you don't even enable it

@everzet
everzet added a note

+1

upper sensei forced my hand here

@everzet
everzet added a note

upper sensei told you to use selenium2 instead of sahi, not just adding this dependency ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@cordoval cordoval Upgrading behat to 2.4 and additional required changes
remove initialization of mink and behat bundles
add project directory level behat.yml initial spec
remove behat mink configuration from symfony config files
remove old composer.lock and update vendors
add composer lock file for upgrade
fix travis call for behat script and make behat-ci script executable
move behat-ci.sh inside bin directory
fix behat-ci script
adapt Behat Contexts to running state
add mink selenium driver
enable minkcontext steps
ignore behat.yml and make dist version of configuration
embed behat deps on require-dev
shorten namespaces
remove nulls from declaration of kernel vars
remove useless if
remove sellenium, sahi
76b083c
@stloyd stloyd merged commit 647349b into KnpLabs:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 27, 2012
  1. @cordoval

    Upgrading behat to 2.4 and additional required changes

    cordoval committed
    remove initialization of mink and behat bundles
    add project directory level behat.yml initial spec
    remove behat mink configuration from symfony config files
    remove old composer.lock and update vendors
    add composer lock file for upgrade
    fix travis call for behat script and make behat-ci script executable
    move behat-ci.sh inside bin directory
    fix behat-ci script
    adapt Behat Contexts to running state
    add mink selenium driver
    enable minkcontext steps
    ignore behat.yml and make dist version of configuration
    embed behat deps on require-dev
    shorten namespaces
    remove nulls from declaration of kernel vars
    remove useless if
    remove sellenium, sahi
View
4 .gitignore
@@ -20,4 +20,6 @@ composer.phar
bin/*
!bin/launch-rabit-consumers.sh
!bin/prepare-*.sh
-
+!bin/behat-*.sh
+build
+behat.yml
View
4 .travis.yml
@@ -12,7 +12,9 @@ before_script:
- ./bin/prepare-test-solr.sh
- ./bin/prepare-test-gd.sh
-script: phpunit -c app/ && php app/console --env=test behat --format progress
+script:
+ - phpunit -c app/
+ - ./bin/behat-ci.sh
branches:
except:
View
5 app/AppKernel.php
@@ -38,11 +38,6 @@ public function registerBundles()
new Knp\Bundle\SitemapBundle\KnpSitemapBundle(),
);
- if ('test' === $this->getEnvironment()) {
- $bundles[] = new Behat\BehatBundle\BehatBundle();
- $bundles[] = new Behat\MinkBundle\MinkBundle();
- }
-
if ($this->isDebug()) {
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
}
View
0 app/config/config_behat.yml
No changes.
View
3 app/config/config_test.yml
@@ -9,6 +9,3 @@ framework:
web_profiler:
toolbar: false
intercept_redirects: false
-
-mink:
- show_cmd: firefox %s
View
12 behat.yml.dist
@@ -0,0 +1,12 @@
+default:
+ formatter:
+ name: progress
+ extensions:
+ Behat\Symfony2Extension\Extension:
+ mink_driver: true
+ kernel:
+ env: test
+ debug: true
+ Behat\MinkExtension\Extension:
+ base_url: 'http://knpbundles.local/app_test.php/'
+ default_session: symfony2
View
42 bin/behat-ci.sh
@@ -0,0 +1,42 @@
+#!/bin/bash
+
+# ./bin/behat-ci.sh
+
+project_dir=$(dirname $(readlink -f $0))"/.."
+logs_path=${1:-"./build/logs/behat"}
+reports_path=${2:-"./build/behat"}
+
+check_and_create_dir() {
+ path=$1
+ echo $path
+ if [[ -d "$path" ]]; then
+ # Directory already exists, do nothing
+ : echo "Directory already exists"
+ elif [[ -e "$path" ]]; then
+ echo "$path exists and is not a directory";
+ else
+ mkdir -p $path
+ fi
+}
+
+check_and_create_dir $reports_path
+check_and_create_dir $logs_path
+
+cd $project_dir
+
+logs_path=${logs_path##$(pwd)/}
+reports_path=${reports_path##$(pwd)/}
+
+for feature_path in `find src/ -path '*/Features'`; do
+ var=`echo $feature_path`;
+ var2=${var%Bundle*};
+ bundle=`echo "${var2##*/}Bundle"`
+ reports_dir=$reports_path"/$bundle.html"
+
+ echo "Running suite for $bundle";
+
+ ./bin/behat --format=progress,junit,html --out=,$logs_path,$reports_dir "@$bundle";
+ echo "<a href=\"$bundle.html\">$bundle</a><br />" >> $reports_path"/index.html"
+done
+
+cd -
View
18 composer.json
@@ -13,12 +13,6 @@
"symfony/monolog-bundle": "*",
"sensio/distribution-bundle": "*",
"jms/i18n-routing-bundle": "*",
-
- "behat/behat": "2.3.*",
- "behat/behat-bundle": "*",
- "behat/mink-bundle": "*",
- "behat/common-contexts": "1.1.*",
-
"doctrine/doctrine-fixtures-bundle": "*",
"doctrine/doctrine-migrations-bundle": "*",
"stof/doctrine-extensions-bundle": "*",
@@ -47,13 +41,15 @@
"mbontemps/oauth-bundle": "*"
},
-
+ "require-dev": {
+ "behat/behat": "*",
+ "behat/symfony2-extension": "*",
+ "behat/mink-extension": "*",
+ "behat/mink-browserkit-driver": "*",
+ "behat/common-contexts": "*"
+ },
"repositories": [
{
- "type": "composer",
- "url": "behat.org"
- },
- {
"type": "package",
"package": {
"name": "mbontemps/oauth-bundle",
View
108 composer.lock
@@ -1,5 +1,5 @@
{
- "hash": "6436ead2fe90a0f48e8a14dc18bafda9",
+ "hash": "f8afd49fea4210b279e876b675093de4",
"packages": [
{
"package": "avalanche123/imagine-bundle",
@@ -9,31 +9,49 @@
},
{
"package": "behat/behat",
- "version": "v2.3.5"
- },
- {
- "package": "behat/behat-bundle",
- "version": "dev-master",
- "source-reference": "12e75b35f44e4ba911abb34db3d2b3c585d41123",
- "commit-date": "1336682785"
+ "version": "v2.4.2"
},
{
"package": "behat/common-contexts",
- "version": "v1.1.1"
+ "version": "dev-master",
+ "source-reference": "fdd34724890828bd8442a443fd59f8af81daed17",
+ "commit-date": "1339965382"
},
{
"package": "behat/gherkin",
- "version": "v2.1.1"
+ "version": "v2.2.1"
},
{
"package": "behat/mink",
- "version": "v1.3.4"
+ "version": "v1.4.0"
+ },
+ {
+ "package": "behat/mink-browserkit-driver",
+ "version": "dev-master",
+ "source-reference": "b07a3908fed61cd31953ddaa6faeb66767cf9d6e",
+ "commit-date": "1339680228"
+ },
+ {
+ "package": "behat/mink-extension",
+ "version": "dev-master",
+ "source-reference": "f77bd494338c4765e56d5448750985f0bb7ffe97",
+ "commit-date": "1340368028"
},
{
- "package": "behat/mink-bundle",
+ "package": "behat/mink-sahi-driver",
"version": "dev-master",
- "source-reference": "144c8cbc08e386e70029edae7a73611079e2dca1",
- "commit-date": "1337850147"
+ "source-reference": "79ecebabcd031c0c9ae78335cda9a893fe40ff38",
+ "commit-date": "1338334143"
+ },
+ {
+ "package": "behat/sahi-client",
+ "version": "v1.0.1"
+ },
+ {
+ "package": "behat/symfony2-extension",
+ "version": "dev-master",
+ "source-reference": "1ae47b8839e9e9501c715ad516f97412ee98a042",
+ "commit-date": "1340373540"
},
{
"package": "doctrine/common",
@@ -42,8 +60,8 @@
{
"package": "doctrine/data-fixtures",
"version": "dev-master",
- "source-reference": "d233d05437c1a10034867f22069b4bb0f7dc96b6",
- "commit-date": "1338071483"
+ "source-reference": "1f0b8be5db0b53681f80c99324c94e21e1efe39a",
+ "commit-date": "1340392920"
},
{
"package": "doctrine/dbal",
@@ -89,8 +107,14 @@
},
{
"package": "fabpot/goutte",
- "version": "master-dev",
- "source-reference": "master",
+ "version": "dev-master",
+ "alias-pretty-version": "1.0.x-dev",
+ "alias-version": "1.0.9999999.9999999-dev"
+ },
+ {
+ "package": "fabpot/goutte",
+ "version": "dev-master",
+ "source-reference": "c2ea8d9a6682d14482e57ede2371001b8a5238d2",
"commit-date": "1340264258"
},
{
@@ -102,8 +126,12 @@
{
"package": "gedmo/doctrine-extensions",
"version": "dev-master",
- "source-reference": "f14d807797b2d6feb8e9a02e61ca03d125e9349b",
- "commit-date": "1340355081"
+ "source-reference": "9ed48efd2868652f9020c681519d176688a0e87f",
+ "commit-date": "1340362268"
+ },
+ {
+ "package": "guzzle/guzzle",
+ "version": "v2.6.6"
},
{
"package": "igorw/file-serve-bundle",
@@ -126,8 +154,8 @@
{
"package": "jms/translation-bundle",
"version": "dev-master",
- "source-reference": "3b96a2560ab26ba30c7ffcc88342c4ef20a597b6",
- "commit-date": "1339728208"
+ "source-reference": "cbe95c467ed5e5c26944a4eb23d7fcc90e799b35",
+ "commit-date": "1340675531"
},
{
"package": "knplabs/github-api",
@@ -270,8 +298,8 @@
{
"package": "symfony/monolog-bundle",
"version": "dev-master",
- "source-reference": "0b5046d3d1ef93cd59ceabfa37de2665f5118c7f",
- "commit-date": "1339708477"
+ "source-reference": "660a1aeaf93e8ffdc34c27b3a82dc47195ad1d8d",
+ "commit-date": "1340609637"
},
{
"package": "symfony/symfony",
@@ -282,8 +310,8 @@
{
"package": "symfony/symfony",
"version": "dev-master",
- "source-reference": "v2.1.0-BETA1",
- "commit-date": "1340300540"
+ "source-reference": "d0e154725c85a3ec5bc6760a59cc2769b8a17ae5",
+ "commit-date": "1340724924"
},
{
"package": "twig/extensions",
@@ -300,8 +328,8 @@
{
"package": "twig/twig",
"version": "dev-master",
- "source-reference": "4679ad51c5390648b7ea4c8f0ecd2c0c344145ba",
- "commit-date": "1339959143"
+ "source-reference": "cd049dac38dda63bd0fb264bbd939a547c7c4b1a",
+ "commit-date": "1340727866"
},
{
"package": "twitter/app-bundle",
@@ -328,30 +356,6 @@
{
"package": "zendframework/zend-filter",
"version": "2.0.0-beta1"
- },
- {
- "package": "zendframework/zend-http",
- "version": "2.0.0beta3"
- },
- {
- "package": "zendframework/zend-loader",
- "version": "2.0.0beta3"
- },
- {
- "package": "zendframework/zend-registry",
- "version": "2.0.0beta3"
- },
- {
- "package": "zendframework/zend-stdlib",
- "version": "2.0.0beta3"
- },
- {
- "package": "zendframework/zend-uri",
- "version": "2.0.0beta3"
- },
- {
- "package": "zendframework/zend-validator",
- "version": "2.0.0beta3"
}
],
"packages-dev": null,
View
45 src/Knp/Bundle/KnpBundlesBundle/Features/Context/FeatureContext.php
@@ -2,15 +2,14 @@
namespace Knp\Bundle\KnpBundlesBundle\Features\Context;
-use Behat\BehatBundle\Context\BehatContext,
- Behat\BehatBundle\Context\MinkContext;
-
-use Behat\MinkBundle\Driver\SymfonyDriver;
-
use Behat\Behat\Context\ClosuredContextInterface,
Behat\Behat\Context\Step,
Behat\Behat\Context\TranslatedContextInterface,
Behat\Behat\Exception\PendingException;
+use Behat\CommonContexts\SymfonyDoctrineContext;
+use Behat\MinkExtension\Context\MinkContext;
+use Behat\Symfony2Extension\Context\KernelAwareInterface;
+use Behat\MinkExtension\Context\RawMinkContext;
use Behat\Gherkin\Node\PyStringNode,
Behat\Gherkin\Node\TableNode;
@@ -21,6 +20,8 @@
Behat\Mink\Exception\ElementTextException,
Behat\Mink\Exception\UnsupportedDriverActionException;
+use Symfony\Component\HttpKernel\KernelInterface;
+
use Etcpasswd\OAuthBundle\Security\Core\Authentication\Token\OAuthToken,
Etcpasswd\OAuthBundle\Provider\Token\GithubToken;
@@ -33,18 +34,22 @@
/**
* Feature context.
*/
-class FeatureContext extends MinkContext
+class FeatureContext extends RawMinkContext implements KernelAwareInterface
{
private $users;
private $bundles;
private $keywords;
+ /**
+ * @var \Symfony\Component\HttpKernel\KernelInterface $kernel
+ */
+ private $kernel;
+
public function __construct($kernel)
{
- $this->useContext('symfony_doctrine', new \Behat\CommonContexts\SymfonyDoctrineContext($kernel));
- $this->useContext('solr', new \Knp\Bundle\KnpBundlesBundle\Features\Context\SolrContext($kernel));
-
- parent::__construct($kernel);
+ $this->useContext('symfony_doctrine', new SymfonyDoctrineContext());
+ $this->useContext('solr', new SolrContext());
+ $this->useContext('mink', new MinkContext());
}
/**
@@ -353,4 +358,24 @@ protected function getRouter()
{
return $this->getContainer()->get('router');
}
+
+ /**
+ * gets container from kernel
+ *
+ * @return \Symfony\Component\DependencyInjection\ContainerInterface
+ */
+ protected function getContainer()
+ {
+ return $this->kernel->getContainer();
+ }
+
+ /**
+ * Sets Kernel instance.
+ *
+ * @param KernelInterface $kernel HttpKernel instance
+ */
+ public function setKernel(KernelInterface $kernel)
+ {
+ $this->kernel = $kernel;
+ }
}
View
31 src/Knp/Bundle/KnpBundlesBundle/Features/Context/SolrContext.php
@@ -2,7 +2,9 @@
namespace Knp\Bundle\KnpBundlesBundle\Features\Context;
-use Behat\BehatBundle\Context\BehatContext;
+use Behat\Behat\Context\BehatContext;
+use Symfony\Component\HttpKernel\KernelInterface;
+use Behat\Symfony2Extension\Context\KernelAwareInterface;
require_once 'PHPUnit/Autoload.php';
require_once 'PHPUnit/Framework/Assert/Functions.php';
@@ -10,9 +12,14 @@
/**
* Solr context.
*/
-class SolrContext extends BehatContext
+class SolrContext extends BehatContext implements KernelAwareInterface
{
/**
+ * @var \Symfony\Component\HttpKernel\KernelInterface $kernel
+ */
+ private $kernel;
+
+ /**
* @Given /^bundles are indexed$/
*/
public function bundlesAreIndexed()
@@ -42,4 +49,24 @@ protected function getSolariumClient()
{
return $this->getContainer()->get('solarium.client');
}
+
+ /**
+ * gets container from kernel
+ *
+ * @return \Symfony\Component\DependencyInjection\ContainerInterface
+ */
+ protected function getContainer()
+ {
+ return $this->kernel->getContainer();
+ }
+
+ /**
+ * Sets Kernel instance.
+ *
+ * @param KernelInterface $kernel HttpKernel instance
+ */
+ public function setKernel(KernelInterface $kernel)
+ {
+ $this->kernel = $kernel;
+ }
}
Something went wrong with that request. Please try again.