I won’t try to convince you to test your project. If you are a techie, you’re probably tired to eat: TDD, CI… in each conference, slide or blog post (even here). Instead here’s a tip to mix my favorite tools together: behat & atoum.
Quick introduction to atoum and behat
To skip if you already know the toolsAtoum is a modern “unit test” framework write in PHP. I already expressed my opinion about it
Behat is a “Behavior Driven Development” aka “BDD” framework write in PHP by @everzet. Initially based on cucumber in Ruby, the tool has a great evolution and some Ruby nerds consider it as good as cucumber (and sometimes, even better. Sorry I don’t have the link to the tweet). In short, it’s IMHO, the best tool to do this job for PHP. Behat also uses the gherkin syntax and allows your tests to be readable by anyone involved in your project.
Atoum asserter into your Behat context
Behat is a modern tool (i.e: loosely coupled) and the best thing: it doesn’t try to reinvent the wheel. You’re free to pick any “asserter” you want! If you enjoy the atoum fluent syntax, you probably want to import the same goodness inside Behat. It’s easy and you just have to follow the classic 3-steps: “Install-Configure-Enjoy”.
Install
First, install Behat and atoum: pear, git clone… If you’re lazy or smart, you probably rely on composer:
"require-dev": {
"behat/behat": "2.4@stable",
"mageekguy/atoum": "dev-master",
}
Configure
Then, inside your Behat FeatureContext class, use the atoum’s asserter namespace and don’t forget to (auto)load everything.
This is really simple, but some people were mixing wrong behat/atoum concepts. For example: it’s a really bad idea to use the atoum test class inside Behat. I don’t know what kind of “hope” you could have doing that, but I can predict you a nice headache.
Enjoy
Now you will be able to code your Behat steps using the atoum style:
1 Notes/ Hide
-
testonsteroid posted this