Most of us have been writing phpunit tests for awhile, and if you're like me, might've read what the 'other side of the fence' has been writing about phpspec.  It had been introduced to me as a BDD test suite, but I thought of it as a bit of malarkey since I'd bought into Behat as the synonym to BDD.  I decided to give it a go!  I think I was sold the second I considered never having to write an XML suite ever again.

What sucked though, was the immediate need for the ServiceManager.  There was no glue available for phpspec that I could find, just a bunch of slides about why phpspec or BDD are awesome.

I think I've got it.

Setup

First, install my little phpspec package for zf2:

composer require saeven/phpspec-zf2

Then, set up your phpspec.yml and write tests!  I've got some examples of my phpspec.yml and a factory specification in the README which you can see here:

https://github.com/Saeven/phpspec-zf2

Let me know if it helps you, if you run into any snags, or have recommendations!

 

Where This Fits

For me, this would never replace Behat despite their competition for the BDD acronym in documentation; I also don't think it would do well to qualify things like controllers -- but it has been a godsend to test model and service objects.

I hope this plugin helps you too!