Giter Site home page Giter Site logo

symfony2extension's Introduction

Behat

Behat is a BDD framework for PHP to help you test business expectations.

Gitter chat License Build Status

Installing Behat

The easiest way to install Behat is by using Composer:

$> composer require --dev behat/behat

After that you'll be able to run Behat via:

$> vendor/bin/behat

Installing Development Version

Clone the repository and install dependencies via Composer:

$> composer install

After that you will be able to run development version of Behat via:

$> bin/behat

Contributing

Before contributing to Behat, please take a look at the CONTRIBUTING.md document.

Versioning

Starting from v3.0.0, Behat is following Semantic Versioning v2.0.0. This basically means that if all you do is implement interfaces (like this one) and use service constants (like this one), you would not have any backwards compatibility issues with Behat up until v4.0.0 (or later major) is released. Exception could be an extremely rare case where BC break is introduced as a measure to fix a serious issue.

You can read detailed guidance on what BC means in Symfony BC guide.

Useful Links

Contributors

symfony2extension's People

Contributors

bamarni avatar benji07 avatar bocharsky-bw avatar ciaranmcnulty avatar cordoval avatar cryptiklemur avatar daum avatar doncallisto avatar drschimke avatar elnur avatar everzet avatar fonsecas72 avatar glennmcewan avatar greg0ire avatar headrevision avatar jakzal avatar kingcrunch avatar l3l0 avatar ludofleury avatar pamil avatar pborreli avatar pschultz avatar robocoder avatar sroze avatar stof avatar thewilkybarkid avatar wouterj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

symfony2extension's Issues

Html tags in textarea field

When Behat trying to init form ( $this->forms[$formId] = new Form($buttonNode, $this->client->getRequest()->getUri()) ) object from BrowserKitDriver.php in method addField(\DOMElement $node) {
...........
elseif ('textarea' == $nodeName) {
$this->set(new Field\TextareaFormField($node));
}
...........
}
he trying to create "TextareaFormField" object and parse their content -
foreach ($this->node->childNodes as $node) {
$this->value .= $node->wholeText;
}
normally in $this->node->childNodes is a DOMText object. BUT if the textarea contents contains somes html tags such as "< br >", "< hr >", "< html >", etc property $this->node->childNodes contained DOMElement's and this object doesn't have property $wholeText. So I have error like this - Notice: Undefined property: DOMElement::$wholeText in Tools/Behat/vendor/symfony/dom-crawler/Symfony/Component/DomCrawler/Field/TextareaFormField.php line 39

So Behat can't parse field with wysiwyg editors. Thx

Allow more than one (frequently used) bundles to be added to a profile

As part of my continuous integration, I have to test behat features in each of my symfony bundle.

It would be a nice feature to specify these bundles in a profile, so that I can just execute

php behat.phar -p=profile_name

and get behat to run feature tests in each bundle within the profile.

symfony 3 support

could you please release in the next time a major release supporting sf3?

Load multiple .feature files Edit

It would be nice to allow to import multiple .feature files, for instance

default:
  paths:
    features:
      - '@testbundle/Features/'
      - '@testbundle2/Features/'

allowing to run all the scenarios described on those files.

Cannot switch kernel's environment

Hi,
I have the following config in my behat.yml :

default:
  context:
    class : 'features\bootstrap\Context\FeatureContext'
    parameters:
      reset_database  : false
      environment      : prod
      debug               : false
  formatter:
    name: progress
  extensions:
    Behat\Symfony2Extension\Extension:
      mink_driver: true

      kernel:
        env: prod

    Behat\Symfony2Extension\Extension:
      mink_driver: true
    Behat\MinkExtension\Extension:
      base_url : 'http://localhost/'
      goutte   :
        guzzle_parameters :
          curl.options     :
            CURLOPT_CONNECTTIMEOUT : 0
            CURLOPT_TIMEOUT        : 900

      default_session: goutte

And, in my context, using the Symfony2Extension, I have the following :

<?php
// with proper uses...

class ConsoleContext extends BehatContext
{
    use KernelDictionary;

    /** @var Application */
    private $application = null;

    /** CommandTester */
    private $tester = null;

    /** @When /^(?:I )?run the command "(?P<name>(?:[^"]|\\")+)"$/ */
    public function iRunCommand($name)
    {
        if (null === $this->application) {
            $this->application = new Application($this->getKernel());

            // register bundles commands... I guess.
            foreach ($this->getKernel()->getBundles() as $bundle) {
                if ($bundle instanceof Bundle) {
                    $bundle->registerCommands($this->application);
                }
            }
        }

        var_dump($this->getKernel()->getEnvironment());

        $command = $this->application->find($name);

        $this->tester = new CommandTester($command);
        $this->tester->execute(['command' => $command->getName()]);
    }

    /** @Then /^the console should have displayed "(?P<output>(?:[^"]|\\")+)"$/ */
    public function consoleShouldHaveDisplayed($output)
    {
        if (null === $this->tester) {
            throw new Exception('No command were run');
        }

        echo $this->tester->getDisplay();
    }
}

With the var_dump, I always have the result string(4) "test". So I don't know if I'm doing something wrong, but it seems I can't change the kernel environment from my config file... ?

By the way, would there be a cleaner way to initialize the console, as I need to run some behaviour tests on it ?

Thanks !

Kernel not booted properly

When my context is initialized by KernelAwareInitializer it does not always have kernel booted properly, but when I manually call KernelAwareInitializer->bootKernel in KernelAwareInitializer->initializeContext it works well. There is problem with container being null so probably it's just shut down kernel. I'm not sure where is the problem, but since there is almost no documentation for behat3 it might be just configuration issue.

Drop Behat 2.5 support

It looks like most of the issues are related to the version using Behat 2.5. The version 3 is old enough to be the only supported version IMO.

Referencing container parameters in behat.yml

Hi,
Since the last release, it seems that container parameters con be referenced in behat.yml file. Could you explain how that should be done? I tried to do it with no success.

Thanks

Symfony3 Directory Structure

When using Symfony's new directory structure, the extension creates new cache/logs directories in app and ignores the ones in var.

Container services are re-instantiated several times in a single scenario

Hi,

I've ran into a huge problem this morning. I am using external API which provides limitations for it's usage. So I decided to create stubbed connection with response mechanism working as a stack of responses. Everything works in PHPUnit, but when I run behat tests and expect to be able to prepare response stack in @BeforeScenario event, it does not work at all. I was surpised to see that response stack is emptied before each step.

I added simple echo in service's constructor and found out that the service's constructor is called multiple times in a single scenario. That's interesting, because setKernel on the context is called only once.

Can anyone explain to me what's going on and how to prevent services from being re-instantiated between steps and why it is exactly three times for 2-step scenario?

symfony2 as default session

I'm having problems setting symfony2 on default session. When I configure it, I'm having 404 on all my urls. It seems that is prepending "app_test.php/" on all routes.

If I change it to goutte, then it works ok!

I'm missing something?

Symfony 2.3

behat.yml

default:
    extensions:
        Behat\Symfony2Extension\Extension:
            mink_driver: true
            kernel:
                env: test
                debug: true

        Behat\MinkExtension\Extension:
            base_url: http://mercadotes.local:8888/app_test.php/
            default_session: symfony2
            javascript_session: sahi
            browser_name: phantomjs
            sahi: ~

composer.json

        "behat/behat": "2.4.*@stable",
        "behat/mink": "1.4.*@stable",
        "behat/symfony2-extension": "*",
        "behat/mink-browserkit-driver": "*",
        "behat/mink-extension": "*",
        "behat/mink-sahi-driver": "*",
        "behat/common-contexts": "*",
        "sanpi/behatch-contexts": "dev-master",

Set path parameters correctly when running bundle test suites

Hello!

Currently, when running a test suite for a bundle, the path parameters (%behat.paths.features% and %behat.paths.bootstrap%) are set relative to the project root dir, not the bundle dir (i.e. /var/www/features instead of /var/www/src/Acme/DemoBundle/Features). IMO they should be set relative to the bundle dir. If anybody agrees I could look into it that's possible.

Testing Pages requiring Authentication.

I have looked around, and i have not been able to find a way to do this.

Is there a method in Symfony2Extension to test authenticated pages with the test database?

i.e;

# app/config/config_test.yml
doctrine:
    dbal:
        dbname:   %database_name%_test

and do something like what is shown here? Of course this does not work, but how else can we test authenticated pages without traversing to the login page, logging in for every test case scenario? Is it possible and how?

Thanks in advance.

Running behat with symfony2 extension from another directory

Hi,

I have an question about running behat with symfony2 extension from another directory. Assuning this is my dir tree:

/root/main
/root/main/app
/root/main/bin
/root/main/config
/root/main/src
/root/main/vendor

The following works fine:

cd root/main
bin/behat --config app/config/behat.yml -dl

But this gives me an 'Class AppKernel does not exist' Exception:

cd root
main/bin/behat --config main/app/config/behat.yml -dl

Could you please give me a hint how to make this working?

TIA

Wrong feature path generation

Apparently there is an error in the generation of the features path in src/Behat/Symfony2Extension/Console/Processor/LocatorProcessor.php:99 that prevents behat working properly in some cases, for example through PhpStorm.
Please have a look at this threat for more details
https://youtrack.jetbrains.com/issue/WI-24974

Used version: v1.1.2

Behat 3 complains if an array is passed as a parameter to a context when Symfony2Extension is enabled

In behat.yml

- FeatureContext:
    queuesToPurge: ['param1', 'param2']

Triggers the following warning:
PHP Warning: preg_match() expects parameter 2 to be string, array given in /myprojectdir/vendor/behat/symfony2-extension/src/Behat/Symfony2Extension/Context/Argument/ServiceArgumentResolver.php on line 95
If I disable the Symfony2 extension, this problem goes away.

Is there a way to pass arrays as parameters without triggering this warning? I tried wrapping the array inside a string but then the context generates a fatal error because the parameter is type hinted as an array.

Extension file or class could not be located

I am using Behat 3 on dev-master and Symfony2Extension on dev-master. I keep getting this error:

[Behat\Testwork\ServiceContainer\Exception\ExtensionInitializationException]  
`Behat\Symfony2Extension\Extension` extension file or class could not be located. 

I see that Behat\Symfony2Extension\Extension doesn't exist anymore in this version. But what would be the correct extension location to look for?

Don't see steps defined in FeatureContext of some bundles

I have a project on Symfony 2 and use Behat for BDD.

I have a couple of bundles inside my Application directory:

  • ApplicationFirstBundle
  • ApplicationSecondBundle
  • etc.

In each bundle there is a Feature directory where placed all features for this bundle. FeatureContext class is also there. I have declared my own steps in some FeatureContext classes where it needs.

So, when I run ./bin/behat @ApplicationFirstBundle or some other bundle separately - Behat runs features, my custom steps enabled, everything is OK...
But, when I run ./bin/behat src/ - Behat stops on the first feature where used my custom steps. Behat doesn't see my steps in this situation.

Have you any solution how to run all application features with some custom steps inside them?

The KernelDictionnary trait is not detected if used embedded in another trait

Consider the following code :

A trait embedding KernelDictionnary trait

trait PersonTrait
{
    use \Behat\Symfony2Extension\Context\KernelDictionary;

    public function doSomethingInPersonTrait() 
    {
        $this->getContainer()->get('service')->doSomething();

    }
}

And the context class :


class FeatureContext extends MinkContext
{
   use PersonTrait;

   public function doSomethingElse() 
   {
       $this->doSomethingInPersonTrait();
   }
}

Will throw this error : PHP Fatal error: Call to a member function getContainer() on a non-object

The Kernel is not set to the Context. The problem reside in class KernelAwareInitializer : the function usesKernelDictionary does not detects traits recursively.

I am preparing a PR to solve this.

Autoloading issue

Hey!

I'm using Symfony 2.1 & Behat 2.4 through composer.

I'm facing an issue about autoloading since this commit 3d4528.

After reading the code, I understand bin/behat executable requires the composer autoload file whereas the Symfony2Extension requires the Symfony autoload file.

Since this commit 938fd6, the swiftmailer autoloading has been removed from symfony autoload & has been moved to composer autoload.

The issue is composer requires the swift_required.php script & the Symfony autoload will require the composer autoloader. So, the swift_required.php is loaded twice, since composer uses require and not require_once with projects not implementing PSR-0, with this config :

# from SwiftMailer composer.json

# ...
    "autoload": {
        "files": ["lib/swift_required.php"]
    },

This causes bin/behat to crash without any output, due to the @include from app/autoload.php.

We fixed temporarily the issue by using Symfony's autoload in the behat executable, just to be able to run the tests.

Let me know if you need more information. :)

Q: ParameterBag not shared between Extension and FeatureContext?

Snippet:

class FeatureContext extends MinkContext implements KernelAwareInterface
{
...
    public function setKernel(KernelInterface $kernel)
    {
        \Doctrine\Common\Util\Debug::dump($kernel->getContainer()->getParameterBag());
    }
}

The parameter bag doesn't include any of the parameters set by Behat/Symfony2Extension/Extension.php. Is this intentional?

(BTW using Symfony2 master + MinkExtension + Symfony2Extension)

path problem?

Hi, I've symfony 2.0.15, and it install behat and symfony2extension through phar, in te root directory of my symfony standard project, when y use command php behat.phar, it gives a error, this is the exit

**
php behat.phar
PHP Fatal error: Class 'Symfony\Component\HttpKernel\Kernel' not found in /proyectos/candgo/app/AppKernel.php on line 7
PHP Stack trace:
PHP 1. {main}() /proyectos/candgo/behat.phar:0
PHP 2. Symfony\Component\Console\Application->run() /proyectos/candgo/behat.phar:25
PHP 3. Behat\Behat\Console\BehatApplication->doRun() phar:///proyectos/candgo/behat.phar/vendor/symfony/console/Symfony/Component/Console/Application.php:118
PHP 4. Behat\Behat\Console\BehatApplication->createCommand() phar:///proyectos/candgo/behat.phar/src/Behat/Behat/Console/BehatApplication.php:66
PHP 5. Behat\Behat\Console\BehatApplication->createContainer() phar:///proyectos/candgo/behat.phar/src/Behat/Behat/Console/BehatApplication.php:80
PHP 6. Symfony\Component\DependencyInjection\ContainerBuilder->compile() phar:///proyectos/candgo/behat.phar/src/Behat/Behat/Console/BehatApplication.php:94
PHP 7. Symfony\Component\DependencyInjection\Compiler\Compiler->compile() phar:///proyectos/candgo/behat.phar/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/ContainerBuilder.php:437
PHP 8. Behat\Symfony2Extension\Compiler\KernelInitializationPass->process() phar:///proyectos/candgo/behat.phar/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/Compiler/Compiler.php:119
PHP 9. require() phar:///proyectos/candgo/symfony2_extension.phar/src/Behat/Symfony2Extension/Compiler/KernelInitializationPass.php:40
**

thank's a lot

--append-snippets not working

Hello,

I added new steps on one of my features and I use this command
bin/behat --dry-run --append-snippets --suite=api_suite
to add news steps, but noone has been added.

The curious thing is that, if I try to run my tests, Behat shows me this message "Snippets for the following steps in the api_suite suite were not generated (check your configuration): And each element must be active".

Where is my mistake?

Thank you!

"path_suffix" and "class_suffix" options are ignored when doing --init

When i specify custom "context.path_suffix" and "context.class_suffix" options and try to initialize the default features skeleton with

behat --init "@mybundle"

my custom paths are ignored, because "Features" and "Features\Context" paths are hardcoded in Console/Processor/InitProcessor.php:

94:   $featuresPath = $bundle->getPath().DIRECTORY_SEPARATOR.'Features';
96:   $contextPath  = $featuresPath.DIRECTORY_SEPARATOR.'Context';

Can't install using composer

I've created a composer.json file:

{
    "name": "root/1",
    "require": {
        "behat/symfony2-extension": "dev-master"
    }
}

But composer update fails with the following errors:

wicked@w:~/Programming/1$ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for behat/symfony2-extension dev-master -> satisfiable by behat/symfony2-extension[dev-master].
    - behat/symfony2-extension dev-master requires behat/behat ~3.0.0-RC2@dev -> no matching package found.

Potential causes:
 - A typo in the package name
 - The package is not available in a stable-enough version according to your minimum-stability setting
   see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.

Any idea on what's going on?

Symfony 2.1.x support

hi guys, thanks for your work.

If I understand correctly, there is no support for Symfony 2.1.x, is it?

Problems:
    - Problem caused by:
        - Package "behat/symfony2-extension-9999999-dev" contains the rule behat/symfony2-extension requires symfony/http-kernel ([>= 2.0.0.0, < 2.1.9999999.9999999-dev]). Any of these packages satisfy the dependency: symfony/symfony-2.0.9999999.9999999-dev, symfony/http-kernel-2.0.13.0, symfony/symfony-2.0.13.0, symfony/http-kernel-2.0.12.0, symfony/symfony-2.0.12.0, symfony/http-kernel-2.0.10.0, symfony/symfony-2.0.10.0, symfony/symfony-2.0.11.0, symfony/http-kernel-2.0.9.0, symfony/symfony-2.0.9.0, symfony/http-kernel-2.0.4.0, symfony/http-kernel-2.0.5.0, symfony/http-kernel-2.0.6.0, symfony/http-kernel-2.0.7.0, symfony/symfony-2.0.7.0, symfony/http-kernel-2.0.9999999.9999999-dev.

and I can't get symfony2_extension.phar file, the link from README is broken. can you provide correct link?

Too many connections - Doctrine connections are not closed

When running tests, it seems the extension "start" a new Symfony env for each feature (which is great), however the Doctrine connections of older env are not closed and it causes 'Too many connections' after a while

I had to add this to get past it:

    /**
     * @AfterScenario
     */
    public function closeConnections($event)
    {
        $doctrine = $this->getDoctrine();
        foreach ($doctrine->getManagers() as $name => $entityManager) {
            $entityManager->close();
            $connection->close();
        }
    }

@BundleName does not work with Symfony 2.1.1

I installed a clean installation of Symfony 2.1.1 via composer:

php composer.phar create-project symfony-framework-standard-edition Symfony-2.1 2.1.1

After that I added Behat and the Symfony2-extension of Behat to the project:

"require": {
        "behat/behat": "2.4.*@stable",
        "behat/mink-extension": "*",
        "behat/mink-browserkit-driver": "*",
        "behat/symfony2-extension": "*"
}

After running composer update, you can run behat via bin/behat, but it does not work correctly.
The default Symfony 2 installation contains the AcmeDemoBundle, so I tried to initialize behat for the AcmeDemoBundle using the following command:

bin/behat --init @AcmeDemoBundle

But when running this command I get the following error from Behat:

[InvalidArgumentException]
Provide features argument in order to init suite.

And when I add the features argument I get the following error:

[InvalidArgumentException]
Can not find bundle to initialize suite.

I put the following behat.yml in the root directory of the Symfony installation:

default:
    extensions:
        Behat\MinkExtension\Extension:
            base_url: http://localhost/app_dev.php/Symfony-2.1/web/app_dev.php
            default_session: 'symfony2'
        Behat\Symfony2Extension\Extension:
            mink_driver: true

behat --init fails if application level feature suite is used

If application level feature suite is used behat --init fails returning the following error

[InvalidArgumentException]
  Provide features argument in order to init suite.

The configuration in behat.yml is the following

default:
    paths:
        features: features
        bootstrap: %behat.paths.features%/bootstrap
    context:
        class: Infinity\Bundle\TestBundle\Test\Context\FeatureContext
    formatter:
        name: pretty
    extensions:
        Behat\MinkExtension\Extension:
            base_url: 'http://localhost'
            goutte:    ~
            selenium2: ~
            default_session: goutte
            javascript_session: selenium2
            browser_name: firefox
        Behat\Symfony2Extension\Extension: ~

The error suggests that behat --init expect a bundle or suite name as argument to be initialised even if such feature is not used.

The only way to run behat --init correctly is to comment out Behat\Symfony2Extension\Extension: ~ temporarily.

Symfony2Extension should be able to understand how is used based on the configuration and do not intercede with behat --init in case application level feature suite is used.

Cannot pass boolean arguments via environment variable

Setting BEHAT_PARAMS kernel debug value to true, false, 0 or 1 is always interpreted as a string, raising an exception:

BEHAT_PARAMS="extensions[Behat\Symfony2Extension\Extension][kernel][debug]=false"

This raises the following exception:

Invalid type for path "behat.extensions.behat_symfony2extension_extension.kernel.debug". Expected boolean, but got string. 

A fix may be to pre-parse the configuration option and convert the string to a boolean:

->booleanNode('debug')
    ->beforeNormalization()
        ->ifString()
            ->then(function($v) { return in_array($v, array('1', 'true', 'on')); })
    ->end()
    ->defaultFalse()
->end()

Incompatibility with "var/" kernel root dir

Hello,

I've activated the new directory structure using var/ as root dir for the cache, logs, etc.
The Symfony2Extension keeps creating app/cache and app/logs directories.

I'm finding a solution to enhance the extension, but haven't found yet how Symfony2 manage to override the kernel root directory (I thought it would have been done in app/AppKernel.php)

Commands bin/behat --init and bin/behat --init "@CompanyDemoBundle" don't create the same folder structure

When initializing behat,

  • the command
    $ bin/behat --init
    creates a directory 'features' in the current directory.
    Inside, there is the folder 'bootstrap', and inside bootstrap, 'FeatureContext.php'
  • the command
    $ bin/behat --init "@CompanyDemoBundle"
    creates a directory 'Features' in src/Company/DemoBundle/
    Inside, there is the folder 'Context', and inside bootstrap, 'FeatureContext.php'

The directory structure should be the same in both cases, but differs
...feature/bootstrap/FeatureContext.php
...Feature/Context/FeatureContext.php
(features has a capital letter. The directory bootstrap and Context have different names)

Steps to reproduce

  • Install behat via composer. Add the following in composer.json
    "require-dev": {
    "behat/behat": "@stable",
    "behat/symfony2-extension": "
    @stable",
    "behat/mink": "@stable",
    "behat/mink-extension": "
    @stable",
    "behat/mink-browserkit-driver": "*@stable",
    }
  • Type command
    $ bin/behat --init
    ---> directory 'features' is created in the current directory.
    Inside is the folder 'bootstrap', and inside, 'FeatureContext.php'
  • Activate the Symfony2Extension extension in behat.yml:
    default:
    # ...
    extensions:
    Behat\Symfony2Extension\Extension: ~
  • Type command
    $ bin/behat --init "@CompanyDemoBundle"
    ---> directory 'Features' is created in src/Company/DemoBundle/
    Inside, there is the folder 'Context', and inside bootstrap, 'FeatureContext.php'

AnnotateLoader - All annotations aren't loaded

Hello,

this is not a problem, I rather think I'm missing something.

When Behat runs, the AnnotatedLoader loads all found contexts, and add their definitions into the definitionDispatcher

But when I try to use the Symfony2Extension, with MinkExtension, Symfony is now used (instead of Behat) to load my contexts. The method AnnotatedLoader::load() is never called.

So, when I use my own sub contexts, my own definitions aren't found.

MyApp\MainContext

public function __construct(array $parameters)
{

    $this->useContext('mink', new MinkContext($parameters));
    $this->useContext('example', new MyApp\MySubContext($parameters));
}

the class MyApp\MySubContext is loaded

/**
 * @Given /^I do anything$/
 */
public function iDoAnything()
{

}

Output :

Vous pouvez implémenter les définitions d'étapes pour les étapes non définies avec ces modèles :
/**
 * @Given /^I do anything$/
 */
public function iDoAnything()
{
    throw new PendingException();
}

With the following config :

paths:
  features: Features
  bootstrap: %behat.paths.features%/Context
context:
  class: \(...)\MyApp\MainContext

of course, my main context is registered by the system : in Behat\Behat\Context\ContextDispatcher, the $classname $classname equals to MyApp\MainContext

Is that a bug? What I do not understand? When does the Loader Symfony will call it AnnotatedLoader ?

Thank's !

kernel booted twice

Hi,

I'm working with behat 2.5 and extension 1.x and I noticed that the kernel is booted twice, not sure if this is somehow needed or if is a issue.

At https://github.com/Behat/Symfony2Extension/blob/1.1.x/src/Behat/Symfony2Extension/Compiler/KernelInitializationPass.php#L58 the kernel is booted first time and then in https://github.com/Behat/Symfony2Extension/blob/1.1.x/src/Behat/Symfony2Extension/Context/Initializer/KernelAwareInitializer.php#L114 it is booted again.

KernelAwareInitializer is listening for beforeScenario. This is resulting in the kernel booting at behat startup and then before each scenario.

In my case this is an issue because I'm trying to test a bundle and I need to manipulate my kernel (i have a fixtures app) before it's booted.

As far as I know this could be solved by behat 3.0 and the new version of the extension (not sure, didn't checked yet) but I'm not sure if I want to switch to 3.0 before it is stable though.

PHP Warning in Symfony2 NativeFileSessionHandler

I get the following error when running behat tests

Warning: ini_set(): A session is active. You cannot change the session module's ini settings at this time in vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/NativeFileSessionHandler.php line 56

The line that throws the error is

ini_set('session.save_handler', 'files');

I have

session.auto_start = 0

In both of my php.ini files for MAMP

My Behat config is

default:
    # ...
    extensions:
        Behat\Symfony2Extension:
            kernel:
                env: test
                debug: true
        Behat\MinkExtension:
            base_url: 'http://helios.local.co.uk/app_test.php/'
            sessions:
                default_session:
                    symfony2: ~
            selenium2: ~
            show_cmd: 'open %s'
            files_path: '/tmp/'
            browser_name: 'firefox'
    suites:
        test_suite:
            type: symfony_bundle
            bundle: 'HeliosWebBundle'
            contexts:
                - FeatureContext

My composer config is

{
    "name": "symfony/framework-standard-edition",
    "license": "MIT",
    "type": "project",
    "description": "The \"Symfony Standard Edition\" distribution",
    "autoload": {
        "psr-0": { "": "src/", "SymfonyStandard": "app/" }
    },
    "repositories": [
        {
            "type": "package",
            "package": {
                "name": "jquery/jquery",
                "version": "2.0.3",
                "dist": {
                    "url": "http://code.jquery.com/jquery-2.0.3.js",
                    "type": "file"
                }
            }
        }
    ],
    "require": {
        "php": ">=5.3.3",
        "symfony/symfony": "2.5.*",
        "doctrine/orm": "~2.2,>=2.2.3",
        "doctrine/doctrine-bundle": "~1.2",
        "twig/extensions": "~1.0",
        "symfony/assetic-bundle": "~2.3",
        "symfony/swiftmailer-bundle": "~2.3",
        "symfony/monolog-bundle": "~2.4",
        "sensio/distribution-bundle": "~3.0",
        "sensio/framework-extra-bundle": "~3.0",
        "incenteev/composer-parameter-handler": "~2.0",

        "doctrine/doctrine-fixtures-bundle": "2.1.*@dev",
        "doctrine/data-fixtures": "1.0.*@dev",
        "doctrine/doctrine-migrations-bundle": "dev-master",
        "doctrine/migrations": "dev-master",
        "jms/security-extra-bundle": "*",
        "jms/di-extra-bundle": "*",

        "friendsofsymfony/user-bundle": "~2.0@dev",
        "friendsofsymfony/elastica-bundle": "3.0.*@alpha",
        "friendsofsymfony/jsrouting-bundle": "~1.1",
        "twbs/bootstrap": "3.0.0-rc.2",
        "jquery/jquery": "2.0.3",
        "knplabs/knp-menu": "2.0.*@dev",
        "knplabs/knp-menu-bundle": "2.0.*@dev",
        "knplabs/knp-paginator-bundle": "dev-master",
        "knplabs/knp-components": "dev-master",
        "knplabs/gaufrette": "0.2.*@dev",
        "knplabs/knp-gaufrette-bundle": "dev-master",
        "stof/doctrine-extensions-bundle": "~1.1@dev",
        "leafo/lessphp": "dev-master",
        "liip/imagine-bundle": "dev-master",
        "liip/url-auto-converter-bundle": "dev-master",
        "jms/serializer-bundle": "*",
        "jms/translation-bundle": "dev-master",
        "geoip2/geoip2": "0.5.*",
        "asm89/twig-cache-extension": "~0.1",
        "ornicar/apc-bundle": "1.0.*",
        "aws/aws-sdk-php": "2.*",
        "google/apiclient": "dev-master",
        "winzou/cache-bundle": "dev-master",
        "ddeboer/vatin-bundle": "@stable"
    },
    "require-dev": {
        "phpunit/phpunit": "4.1.*",
        "sensio/generator-bundle": "~2.3",
        "behat/behat": "~3.0.6",
        "behat/symfony2-extension": "~2.0@dev",
        "behat/mink-extension":          "~2.0@dev",
        "behat/mink-browserkit-driver":  "~1.1@dev",
        "behat/mink-selenium2-driver":   "*"
    },
    "scripts": {
        "post-root-package-install": [
            "SymfonyStandard\\Composer::hookRootPackageInstall"
        ],
        "post-install-cmd": [
            "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::removeSymfonyStandardFiles"
        ],
        "post-update-cmd": [
            "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::removeSymfonyStandardFiles"
        ]
    },
    "config": {
        "bin-dir": "bin"
    },
    "minimum-stability": "stable",
    "extra": {
        "symfony-app-dir": "app",
        "symfony-web-dir": "web",
        "incenteev-parameters": {
            "file": "app/config/parameters.yml"
        },
        "branch-alias": {
            "dev-master": "2.5-dev"
        }
    }
}

[ReflectionException] Class AdminKernel.php does not exist

Might be related to #41 .

When using the dev-master of Symfony2Extension with Behat 3.0, it gives:
[ReflectionException] Class AdminKernel.php does not exist

My directory structure looks like this :

    ├── apps
    |   ├── admin
    |   |   ├── AdminKernel.php
    |   └── site
    |   └── features
    |   └── behat.yml

With the following configuraiton :

        Behat\Symfony2Extension:
            kernel:
                env:   test
                debug: true
                path: admin/AdminKernel.php

does not find the kernel class.

Tried:

        Behat\Symfony2Extension:
            kernel:
                env:   test
                debug: true
                path: admin
                class: AdminKernel.php

results in:
Failed opening required '.../workspace/project/apps/admin' althgouh this is the correct path.

Error sharing objects between symfony container and behat context

I want to use behat to assert that an added entity(highlight) is shown in my homepage.

There is a highlight repository(in memory) service declared in symfony container:

highlight_repository:
    class: CustomIntranet\Infraestructure\InMemory\InMemoryHighlightRepository

Its simple implementation:

class InMemoryHighlightRepository implements HighlightRepository
{
    private $items = array();

    public function save(Highlight $highlight)
    {
        $this->items[$highlight->id()] = $highlight;
    }

    public function getAll()
    {
        return $this->items;
    }
}

And I use it in a controller

    /**
     * @Route("/", name="homepage")
     */
    public function indexAction()
    {
        $highlights = $this->get('highlight_repository')->getAll();
    }

Then I inject it into behat context:

default:
    suites:
        web:
            contexts:
                - WebContext:
                    highlightRepository: "@highlight_repository"
class WebContext extends RawMinkContext implements Context, SnippetAcceptingContext
{
    private $highlightRepository;

    public function __construct(HighlightRepository $highlightRepository)
    {
        $this->highlightRepository = $highlightRepository;
    }

    /**
     * @Given there is a highlight with title :title and a description :description
     */
    public function thereIsAHighlightWithTitleAndADescription($title, $description)
    {
        $this->highlightRepository->save(
            new Highlight($title, $description)
        );
    }

    /**
     * @When I open the homepage
     */
    public function iOpenTheHomepage()
    {
        $this->visitPath('/');
    }

    /**
     * @Then I should see the highlight title :title
     */
    public function iShouldSeeTheHighlightTitle($title)
    {
        $this->assertSession()->pageTextContains($title);
    }
}

The problem is that last assertion throws an exception because the highlight was not really added to the repository because it seems the injected object to Behat context is different from the used in controller.

Any way to have the same object? Any workaround?

Symfony2.2 and Behat dependency

Composer fails to resolve Symfony2Extension "dev-master" in combination with Symfony2.2. Composer says Symfony2Extension requires "behat/behat >=2.4.0,<2.5.0-dev". Although behat/behat is only in dev-master compatible with Symfony2.2 [https://github.com/Behat/Behat/commit/3de7f3c7cd5411a403a2099257c42b6900145cc6].

Cannot run features in another directory

I'm probably doing something wrong, but i cant seem to get behat to find and run my features when they arent in the bundle.

my dir structure:

app
src
    AcmeBundle
tests
    AcmeBundle
        Features
           Context
               FeatureContext.php
           demo.feature
behat.yml

_behat.yml_

default:
    suites:
        analytics:
            type: symfony_bundle
            bundle: AcmeDemoBundle
            paths: [ %paths.base%/./tests/DemoBundle/Features ]
            contexts: [ Acme\DemoBundle\Features\Context\FeatureContext ]
    formatters:
        pretty: true
    extensions:
        Behat\Symfony2Extension\Extension: ~

When i move them into the bundle, without paths, they work

It is apparently impossible to use multiple contexts in a suite if using Symfony2Extension

@everzet Sorry for opening this originally in the Behat respository.

I have tried every config combination humanly possible, but cannot get two contexts to run. As soon as I add a 'contexts:' key to my config, even the FeatureContext class is no longer recognised.

This is my behat.yml file:

default:
    suites:
      my_suite:
        type: symfony_bundle
        bundle: MyCoolBundle
    extensions:
        Behat\Symfony2Extension: ~
        Behat\MinkExtension:
            base_url: http://ams.ldev
            selenium2: ~
            symfony2: ~
            sessions:
                default:
                    symfony2: ~

And I have the default directory structure created by the behat init command. How can I change the above config to allow me to have two context classes for the suite?

Ideally I'd like to define a 'global' context class that contains database-related code that should run on each execution of my tests. But if I can even just get this working inside one suite that'd do me for now.

Thanks for any help.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.