Anyone that came from Ruby probably knows what is BDD, Cucumber and it’s advantages over the plain unit tests. For the rest, BDD is way to test models AND controllers with easy to read “scenarios”.
Great thing is that Cucumber (Ruby’s BDD framework) is ported to PHP and it’s called Behat . Example of working with behat can be checked here .
Anyone tried to integrate behat with Yii? I’m working with Yii for almost 2 years, and used it for several large projects so far. Currently, my team is preparing for another large project and we’re thinking to make this integration ourselves. Any help (code or ideas) will be appreciated and we will of course share our integration (although cannot promise future maintenance)
Of course, it would be best if Yii team decide to make it since it woule be included in future versions of framework. That’s why I put it in here
Difference is that Unit tests are testing only models, not how they are implemented in controllers. With behat, you test both controllers and models, otherwise you have to use selenium or similar (unreliable) tools to test controllers. Other differences are: test are easy to understand even for common people and you can use it as some kind of documentation, use cases for testers and etc. And to be honest, creating unit tests is boring even we denied this because it helps us a lot. Creating scenarios (tests in BDD) can be fun and when they are finished,they give you great overview on what needs to be done and in which order.
My advice is that you try BDD on simple examples (without Yii) and soon you’ll see the difference
Can’t agree more - but don’t you still need to write the unit tests below BDD? Or did i get this wrong? I can’t imagine that BDD auto generates unit tests for you
You can create unit tests with behat as a part of scenario… check out link I posted before At the bottom of the page you can see assets presented in ascii-like table and of course given scenario will use those and create unit test for models
Sounds like a good suggestion. If PHPUnit is implementing a similar solution, would it be more backwards-compatible for Yii to stick with PHPUnit for BDD implementation?
I was really looking forward for PhpUnit Stories support. Unfortunately Mr. Bergmann decided not to support them any more. One thing that really scares me in Behat is the use of regex to match implementations:
/** @Given /^I am in a directory "([^"]*)"$/ */
Also, I was under the impression that, compared to php_unit, it requires a lots of additional steps to get going. A little bit like walking that way. Maybe that’s because I didn’t give it a lot time.
I’m really interested in this too. Just come to Yii from Rails, and my last project was using Cucumber (plus a bit of RSpec) for BDD. I found it so useful and made the whole process of development really flow, at the same time leaving a trail of meaningful tests which can be used at any time to test part or all of the system. Helps to make really solid apps without the worry of hidden bugs plus “user stories” that integrate with code.
Would love to see something like this for Yii… perhaps Behat can be integrated somehow?
Behat AND BDD for PHP sound more interesting then TDD development, and it would be good if Yii would support BDD in addition to current support for TDD development(unit tests).