symfonyphpunitbehatphpspec

is it possible to use PHpspec with behat?, or just PhPunit with behat? (Symfony)


I'm playing a little with Behat these days, the thing is that I don't know if I can use PHPspec with Behat to "assert" all the stuff, this one is so readable that I would like to use it. In my case I'm using Symfony.

If not, how can I use Asserts from PHPunit in Behat. I couldn't for now, I installed PHPUnit with composer, but in the Behat Documentation they require a file, but the scenario is lightly different (they didn't installed it by using composer, is not in Vendor directory)

URL from DOC: http://docs.behat.org/quick_intro.html#more-about-features

, the require_once is little elegant.

Any idea?, any answer?, thanks!


Solution

  • You most certainly can use Bahat with PHPUnit. I didn't try with PHPSpec, but I'm certain it's possible if you can access the logic that performs assertions. Typically any test framework would expose that logic for the "outside users".

    /**
     * @Then /^the magic should happen$/
     */
    public function assertUnicornsExist()
    {
        // Make standard assertions through static calls…
        PHPUnit_Framework_TestCase::assertTrue(true);
    }
    

    Not sure I get the full picture with regards to installation, but if you're using composer you can simply configure the "autoload" part to include your sources and contexts (if they are separate). Mine works pretty much out of the box:

    {
        "require": {
            "behat/behat": "dev-master",
            "behat/mink": "dev-master",
            "behat/mink-extension": "dev-master",
            "behat/mink-browserkit-driver": "dev-master",
            "behat/mink-goutte-driver": "dev-master",
            "phpunit/dbunit": "*"
        },
        "autoload": {
            "psr-0": {
                "": "src/"
            }
        }
    }
    

    Then you just include the vendor/autoload.php. I recommend adding in a bootstrap that would run once using the @BeforeSuite hook.

    /**
     * @BeforeSuite
     */
     public static function setUpSuite(BeforeSuiteScope $scope)
     {
         // if not bootstrapped already, then include bootstrap with init'ing the autoloader, etc…
     }
    

    Also, if you're starting off with Behat 3 – the docs are not there yet, use http://behat.readthedocs.org/en/latest/. They contain the latest essentials and some decent examples.