27

Don't get me wrong. I think both projects are fantastic.

But as both php and ruby developer I wonder if there are there any compelling reasons, besides possible language barrier, why would one choose Behat over Cucumber (with cuke4php) for BDD even when working with php or some php framework.

Christoph Strasen
  • 2,562
  • 1
  • 15
  • 15
Krule
  • 6,398
  • 3
  • 32
  • 53

3 Answers3

76

I'm a Behat developer.

Why I've developed Behat instead of Cucumber customization:

  1. Speed. There's no simple way to bootstrap/run PHP from Ruby code. This means that you need to implement wires/proxies and other things, which makes your tests insanely slower. And slower tests is not a test, it's just code that eats your customer's money.
  2. Extensibility. There are very few PHP developers that really know Ruby. It's a hard to use tool, that many don't understand! All examples written for Cucumber are Ruby code and you even can't look at Cucumber sources, because, let's say, you don't know Ruby. It's like buying a submarine when you just need a taxi.

In terms of features, Behat and Cucumber are almost the same (I've worked hard to achieve this). But in terms of speed/extensibility/logic from a PHP developer's perspective - Behat is better, because it's a fast and clean native PHP tool. Behat is not a Cucumber port, as you might think by first, it's built entirely from the ground on PHP 5.3. Behat is trying to simulate Cucumber with its input reading (features) and output formatting (formatters), but it's not a Cucumber port (there are no Ruby syntax constructions in PHP).

Andy
  • 16,265
  • 9
  • 48
  • 69
everzet
  • 1,715
  • 13
  • 9
  • 1
    Thank you, that is the answer I was looking for. – Krule Feb 09 '11 at 19:12
  • 12
    behat rocks! Keep going :) – Christoph Strasen May 09 '11 at 14:10
  • 3
    Yep, +1 for Behat instead of Cucumber for PHP, also if you use Symfony2 there is a Behat bundle (http://symfony2bundles.org/Behat/BehatBundle)! – InvertedAcceleration Aug 03 '11 at 09:52
  • + 1 Totally enjoy behat over capybara / cukes – branchgabriel Jan 08 '13 at 02:51
  • 1
    I'm using Behat at work now for PHP development. I did Ruby development for a few years before and used Cucumber, and I certainly miss the elegance of Ruby. I disagree that its a "hard to use tool" - IMO its much easier than PHP once you get to know it. PHP is messy and inconsistent. – Adamski Oct 06 '14 at 21:27
  • `https://cucumber.io/docs/reference/behat` `http://behat.org/en/latest/quick_start.html`: "Since v3.0, Behat is considered an official Cucumber implementation in PHP and is part of one big family of BDD tools." So that simplifies the selection, right? :) – Pysis Nov 19 '17 at 04:18
  • I agree with you @Adamski. I'm forced to work with PHP, but would much rather use a more elegant and self-consistent language like Ruby (or Python). Just because many PHP developers don't "really" know Ruby doesn't make it hard to use. – afeique Mar 26 '19 at 14:44
2

Yet another reason why you may need Behat is explained here: https://cucumber.io/blog/bdd/when-cucumbers-go-bad/

If you have PHP project, you may want to create context for internals testing (domain layer, application layer).

Jasmine Hegman
  • 553
  • 6
  • 19
Misanthrope
  • 414
  • 3
  • 11
  • This is a great response and much more in line with actually identifying a compelling advantage that BDD in PHP has over using Ruby or Python, if the codebase you're working on is written in PHP. – afeique Mar 26 '19 at 14:47
0

I wanted to toss in my two cents on this topic with an answer that addresses various use-cases in a professional setting.

If you are working with other developers on a codebase written primarily in PHP, the advantage boils down to your coworkers.

If your team is more comfortable in PHP because that's what the codebase is written in and people have trouble or are annoyed by context switching to different programming languages (most people are this way in my experience) then it is better to accommodate your team and use Behat. People will complain less and (hopefully) get more done.

If your team is fluent in a variety of languages and most people have no problems switching between using Ruby (cucumber) for acceptance tests and using PHP for everything else, use the language best suited for the job. Ruby is much more expressive than PHP, so cucumber is arguably a better choice.

If your team is more comfortable with PHP than Ruby, then go with Behat. Native compatibility ensures expressiveness and avoids weirdness, besides the fact that it's faster.

afeique
  • 345
  • 6
  • 14