简体   繁体   中英

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!

You can bring phpspec's matchers to behat with the expect helper .

Few examples of use:

// matches if $something === 'something'
expect($something)->toBe('something');

// matches if $article->isActive() returns true
expect($article)->toBeActive(); 

// matches if $article->hasComments() returns false
expect($article)->notToHaveComments();

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.

Of course it's possible. You can use behat to describe how something should behave and phpspec for more detailed things. Good example is here: http://code.tutsplus.com/tutorials/a-bdd-workflow-with-behat-and-phpspec--cms-21601

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM