Full Stack BDD for Symfony2 Marcello Duarte Konstantin Kudryashov
Jan 15, 2015
Full Stack BDD for Symfony2
Marcello DuarteKonstantin Kudryashov
Marcello DuarteHead of Training
Konstantin KudryashovLead Developer
About us
• Where are we coming from
• Why BDD
• Behat Best Practices
• Introducing a new tool
This talk
fromCucumber to
Adults don’t think their way into a new
way of acting
They act their way into a new way of
thinking
Adults don’t think their way into a new
way of acting
Ask Why
PHPSpec
from xUnit to xSpec
Test
? ???
? ? ?
?
??
?
?
?
?
?
?
? ?
xUnit
assert
code coverage
structure
private
database mocking
Language matter
public function testUpdateWithEqualTypes() { $installer = $this->createInstallerMock(); $manager = new InstallationManager('vendor'); $manager->addInstaller($installer);
$initial = $this->createPackageMock(); $target = $this->createPackageMock(); $operation = new UpdateOperation($initial, $target, 'test');
$initial ->expects($this->once()) ->method('getType') ->will($this->returnValue('library')); $target ->expects($this->once()) ->method('getType') ->will($this->returnValue('library'));
$installer ->expects($this->once()) ->method('supports') ->with('library') ->will($this->returnValue(true));
$installer ->expects($this->once()) ->method('update') ->with($this->repository, $initial, $target);
Tools matter
Why BDD?
[Royce 1970]
Requirements
Analysis
Design
Develop
Test
9 months 3 months 2 months 12 months ...
Most of the cost in software development
is infeedback delay
Refactoring
Code
Test
Requirements
Acceptance
~20 minutes
[Beck & Cunningham 1996-99]
Let’s reduce feedback delay
Let’s rename a few things
Incremental Design
Implement
Describe Object
Narratives (Why?)
Examples (What do you
mean?)
How!
[North 03]
Building a simple
Student can enrol on a course
feature
• No examples until you have a red step
• No code until you have a red example
• No more code than enough to make it green
• Don’t get carried away!
BDD Rules
• Favour MinkAwareInterface over MinkContext
• Extract context per role
• Group features under feature folder
• Use Mink API
• Integrate with framework at config level
Behat tips
• Describe classes not configuration
• Concentrate on messages/behaviours
PHPSpec2 tips
Questions
? ???
? ? ?
?
??
?
?
?
?
?
?
? ?
joind.in/7064
Thanks! :)