The Do's and Don't's of BDD

401 views
Skip to first unread message

Fabian Spillner

unread,
Mar 6, 2013, 3:29:40 PM3/6/13
to phpsp...@googlegroups.com
Hi phpspec users, 

first, I'm very new in BDD generally. It's hard to find good articles about working with PHPSpec, 
especially in the context with Symfony2 + Doctrine2 projects. 

So therefore, I ask you to share your experiences with BDD + PHPSpec here. 

I hope, we come up with useful information so that I can write a documentation about the "best practise" with examples. 

The questions: 

1) Do you mix phpspec and phpunit in a project? Why? If not, why not? 
Do you replace functional tests with behat (despite behat != functional test)
and phpunit with phpspec? 


2) How do you spec an entity? Do you ignore the annotation configuration 
in your spec? How do you ensure that this configuration is working? 

What about ex. Doctrine2 extensions like Timestampable, Sluggable which
you configure your entity with to get slug behavior and do you spec this behavior? And how? 

Do you spec every setter and getter methods? Or just only some methods? 


3) Do you spec your controllers and views? Why do you not write functional tests? 
Do you think, this is bad practise and we should write functional tests? And why?


4) Do you spec your forms and validators? What do you spec? 
Or just functional tests? 


I'm looking forward to discuss with you here. 

Thank you!
Fabian

Silviu Constantin Voicu

unread,
Mar 8, 2013, 8:38:06 AM3/8/13
to phpsp...@googlegroups.com
Hi,

I quess, that you are not the only one, that wants to find those information, but as you know phpspec2 is in alpha2 stage at this moment, so until a stable realse, we have to wait, right?
Then, is ok to use just phpspec2 for specbdd, or just behat for storybdd, but for me, it is more usefull to see the integration of the two in the context with Symfony2 + Doctrine2 projects.
Now, if look at the symfony2 and doctrine2 official documentation, but also to many example of code and presentation, and you are ready to start to developed your project with the knowledge we acquire from the community, and you know what is provided by default by the hole system or where you have to look closer to implement specific actions that needs more customization.
I hope , that something similar will be available also for the full bdd stack: behat + phpspec2.
Thank you, guys, for given to the php community such wonderful tools.

Luis Cordova

unread,
Apr 30, 2013, 8:40:38 PM4/30/13
to phpsp...@googlegroups.com
 my newbie experience has been the following (vide infra):

1) Do you mix phpspec and phpunit in a project? Why? If not, why not? 
Do you replace functional tests with behat (despite behat != functional test)
and phpunit with phpspec? 

generally not, if your project is legacy you have to mix both, definitely do not write specs for legacy, maybe if you do rewrite parts anew and then use is justified, else not.
Functional tests are another thing, do not confuse. You should not write functional tests with phpspec, just not the right tool for the job. The preference is to use behat and asserting with phpunit if need be. Ideally your design well specked should be bullet proof. But integration tests should be added only on good grounds in that scenario.


2) How do you spec an entity? Do you ignore the annotation configuration 
in your spec? How do you ensure that this configuration is working? 

As Kriswall Smith, go big or go home, basically your model and entities is a princess, keep them totally slim. You only spec models like managers etc, or in the worst case scenario some models but non-entity ones. Syllius uses these models but really their models are not entities. The entities belong to you and the db and you speck services and managers. Syllius has a spec for checking the bundle configuration loaded correctly. Have specks for configuration if you want to refactor configuration :)

What about ex. Doctrine2 extensions like Timestampable, Sluggable which
you configure your entity with to get slug behavior and do you spec this behavior? And how? 

I think you are not getting the point. These are two different tools for two different jobs. If you want to do that then that is saying the libraries don't do a good job. Then don't use those libraries.

Do you spec every setter and getter methods? Or just only some methods? 

of course not, only some special usually/ideally

3) Do you spec your controllers and views? Why do you not write functional tests? 
Do you think, this is bad practise and we should write functional tests? And why?

Yes those can be specked and there is a good example online on "Full stack BDD and PHPSpec" or something like that. I hope MD and EZ do the second part.

4) Do you spec your forms and validators? What do you spec? 
Or just functional tests? 

you could, i wouldn't personally, but you can do what you feel like doing.

Sorry if I don't get the point of your questions i am just trying to share from a newbie pov.

We should do have a list of libraries well done with phpspec so we can emmulate by example.

Luis Cordova

unread,
Apr 30, 2013, 8:51:14 PM4/30/13
to phpsp...@googlegroups.com

Luis Cordova

unread,
Apr 30, 2013, 10:23:38 PM4/30/13
to phpsp...@googlegroups.com
and if in case all of these were not enough here https://github.com/jakzal/12tdds/tree/master/spec

claps please for this guy for sharing what he knows about phpspec

commended Jakub, commended
Reply all
Reply to author
Forward
0 new messages