Sam
Sam

Reputation: 6610

Installing behat on a Symfony 2.0 project using deps - what versions?

I have a legacy Symfony 2.0 project (version 2.0.11 to be precise) to which I'd like to add behat tests. As it's Symfony 2.0, it uses the deps vendor system rather than composer. I'm not in a position to upgrade the Symfony version or switch to composer at the moment.

I attempted to install behat using the following deps settings:

[Mink]
    target=/Behat/Mink
    git=git://github.com/Behat/Mink.git
    version=v1.3.3

[MinkBundle]
    target=/Behat/MinkBundle
    git=git://github.com/Behat/MinkBundle.git

[BehatBundle]
    target=/Behat/BehatBundle
    git=git://github.com/Behat/BehatBundle.git

[Gherkin]
    target=/Behat/Gherkin
    git=git://github.com/Behat/Gherkin.git
    version=v2.1.1

[Behat]
    target=/Behat/Behat
    git=git://github.com/Behat/Behat.git
    version=v2.3.5

[Goutte]
    target=/Goutte
    git=git://github.com/fabpot/Goutte.git

(Yes, I know that the BehatBundle etc are outdated, but it looked like I'd need these outdated versions given that I'm using deps and sf2.0.)

When I run vendor/Behat/Behat/bin/behat, I then get the issue described here:

PHP Warning:  require_once(behat/autoload.php): failed to open stream: No such file or directory in /home/sam/wo-code/PersonaBubble/vendor/Behat/Behat/bin/behat on line 23
PHP Fatal error:  require_once(): Failed opening required 'behat/autoload.php' (include_path='.:/usr/share/php:/usr/share/pear') in /home/sam/wo-code/PersonaBubble/vendor/Behat/Behat/bin/behat on line 23

I realised that behat 2.3.5 doesn't actually have an autoload.php file. I looked through Behat's tags on Github and realised that 2.1.3 was the latest version which had an autoload.php (actually autoload.php.dist, though every earlier version also had autoload.php.dist rather than autoload.php, so I assumed that this was it).

I therefore changed my behat version number in deps to v2.1.3, deleted my vendors and re-installed. The behat command had then changed, so I ran:

php vendor/Behat/Behat/bin/behat.php

I now saw this error:

PHP Fatal error:  Class 'Symfony\Component\Console\Application' not found in /home/sam/wo-code/PersonaBubble/vendor/Behat/Behat/src/Behat/Behat/Console/BehatApplication.php on line 26

Does anyone know what the correct versions of behat etc are that I should use to get it working with Symfony 2.0 and deps? Or is there some other step that I'm missing.

PS I ended up running behat via PHAR (although this had other problems so I abandoned it as not worth it). However, I really want to know how to do it via standard vendors install, hence this post.

Upvotes: 0

Views: 562

Answers (1)

BentCoder
BentCoder

Reputation: 12740

I'm not in a position to upgrade the Symfony version or switch to composer at the moment.

I understand what you say but example below might give you a bit of hint I hope! I hope it helps a bit.

I'm sharing what I have been using for all my Symfony2 projects. Behat+Mink+Selenium

CONPOSER:

You need certain versions so that eveyone use same versions of everthing.

mySymfonyProject/composer.json:

"require": {
    "behat/behat": "2.5.*@stable",
    "behat/behat-bundle": "1.0.0",
    "behat/symfony2-extension": "1.1.2",
    "behat/mink": "1.5.0",
    "behat/mink-extension": "~1.3",
    "behat/mink-selenium2-driver": "1.1.1",
    "behat/mink-goutte-driver": "1.0.9"
},
"config": {
    "bin-dir": "bin"
},
"minimum-stability": "dev",

BEHAT

mySymfonyProject/behat.yml:

default:
    context:
        class: FeatureContext
    extensions:
        Behat\Symfony2Extension\Extension:
            mink_driver: true
            kernel:
                env: test
                debug: true
        Behat\MinkExtension\Extension:
            base_url: 'http://mysymfonyproject.local/app_test.php/'
            javascript_session: selenium2
            browser_name: firefox
            goutte: ~
            selenium2: ~
    paths:
        features: %behat.paths.base%/src
        bootstrap: %behat.paths.features%/Context

SELENIUM

Download into your project. It is here, make sure you download 2.43.1 version which is in the middle of the page.

Run it: java -jar selenium-server-standalone-2.43.1.jar

CONTEXT FEATURE

mySymfonyProject/src/Site/CommonBundle/Features/Context/FeatureContext.php

<?php

namespace Site\CommonBundle\Features\Context;

use Behat\MinkExtension\Context\MinkContext;
use Behat\Symfony2Extension\Context\KernelAwareInterface;
use Symfony\Component\HttpKernel\KernelInterface;

class FeatureContext extends MinkContext implements KernelAwareInterface
{
    /**
     * Hold Symfony kernel object.
     *
     * @var object Kernel Object.
     */
    protected $kernel;

    /**
     * Helps to use doctrine and entity manager.
     *
     * @param KernelInterface $kernelInterface Interface for getting Kernel.
     */
    public function setKernel(KernelInterface $kernelInterface)
    {
        $this->kernel = $kernelInterface;
    }

    //And your own methods
}

TESTS

When you have feature files you can run them like this (this runs all in one go. for more info read behat doc):

bin/behat @SiteCommonBundle

Upvotes: 0

Related Questions