Driving Your Development In PHP
May 26, 2015
Driving
Your
Development
In
PHP
About this guy
● Strict EmailValidator PHP library, dependency of Symfoy 2 framework
● ListenersDebugCommand, dependency of eZ Publish CMS
● Works at Packlink
● @egulias in Twitter/Github
This talk is NOT about automated testing
Because you are already testing, right?
What means “driving your development”?
"Tactics is what you do when there is something to do; strategy is what you do when there is
nothing to do."
by Ksawery Tartakower leading Polish and French chess grandmaster.
Are the tactics and tools we, software developers, have for helping us in creating software we won't
hate in 2 weeks
Development Driven (tactics)
VS
Application Architecture (strategies)
Development driven are our “tactics” for when we are developing.
And Software architecture are the “strategies” we follow to guide future development.
Which Strategies do we have?
● Hexagonal (ports and adapters) - Alistair Cockburn and adopted by Steve Freeman, and Nat Pryce in their book Growing Object Oriented Software
● Clean Architecture, by Robert C. Martin
● Layered Architecture, used by Eric Evans in Domain Driven Development
● Event Driven, by Martin Fowler
● Command Query Responsibility Segregation (CQRS) by Martin Fowler
● And many others
Which Tactics do we have?
● Test Driven Development - Kent Beck
● Domain Driven Design - Eric Evans
● Behavior Driven Development - Dan North
● Database Driven Development
● Feature Driven Development - Jeff de Luca
● And many others
TDD – 2002 – Kent Beck
DDD – 2003 – Eric Evans
BDD - ~2004 – Dan North
TEST DRIVEN DEVELOPMENT
Test Driven Development
● Make the test red
● Make it green (Implement)
● Refactor (Remove duplication)
Test Driven Development
● Assertion First ● Baby Steps
https://github.com/egulias/TagDebug/blob/master/Tests/Tag/Filter/NameTest.php
https://github.com/egulias/TagDebug/blob/master/Tests/Tag/Filter/NameTest.php
https://github.com/egulias/TagDebug/blob/master/Tag/Filter/Name.php
https://github.com/egulias/TagDebug/blob/master/Tests/Tag/Filter/NameTest.php
Test Driven Development
● Triangulation ● Oblivious Implementation
Test Driven Development
Tools
Test Driven Development
● PHPUnit– Alone
– Mockery
– Prophecy
– Phake
● Simpletest
Test Driven Development
● PHPUnit– Alone
– Mockery
– Prophecy
– Phake
● Simpletest
https://github.com/egulias/TagDebug/blob/master/Tests/Tag/Filter/NameTest.php
Test Driven Development
● PHPUnit– Alone
– Mockery
– Prophecy
– Phake
● Simpletest
https://github.com/egulias/TagDebug/blob/master/Tag/Filter/Name.php
Test Driven Development
● PHPUnit– Alone
– Mockery
– Prophecy
– Phake
● Simpletest
Test Driven Development
● PHPUnit– Alone
– Mockery
– Prophecy
– Phake
● Simpletest (2012)
100% COVERAGE
BECAUSE YEAH
DOMAIN DRIVEN DESIGN
Is NOT a silver bullet
● Objects with Business meaning and value
● Databases, Frameworks, etc are implementation details
● Focus your development on business behavior
Domain Driven Design
Domain Driven Design
There are artifacts and strategies but no tools
Entity
Aggregate
Repository
Value Object
BoundedContext
Ubiquitous Language
Factory
Service
DomainEvent
Domain Driven Design
Constraints
Specification
IntentionRevealingInterfaces
Side-effectFREE
Functions
Shared Kernel
Anti-corruptionLayer
Domain Driven Design
https://github.com/Bodaclick/EVTCore/blob/dev/src/EVT/CoreDomain/Lead/Event.php
https://github.com/Bodaclick/EVTCore/blob/dev/src/EVT/CoreDomain/Lead/Lead.php
https://github.com/Bodaclick/EVTCore/blob/dev/src/EVT/CoreDomain/RepositoryInterface.php
https://github.com/Bodaclick/EVTCore/blob/dev/src/EVT/CoreDomainBundle/Resources/config/services.yml
https://github.com/Bodaclick/EVTCore
BEHAVIOR DRIVEN DEVELOPMENT
Behavior Driven Development
● Test method names should be sentences● A simple sentence template keeps test methods
focused● An expressive test name is helpful when a test
fails● “Behavior” is a more useful word than “test”● Acceptance criteria should be executable
From http://dannorth.net/introducing-bdd/
Behavior Driven Development
Tools
Behavior Driven Development
Behathttp://docs.behat.org
https://github.com/Sylius/Sylius/blob/master/features/backend/shipping_categories.feature
https://github.com/Sylius/Sylius/blob/master/src/Sylius/Bundle/ShippingBundle/Behat/ShippingContext.php
Behavior Driven Development
phpSpechttp://phpspec.net/docs/introduction.html
Unit Testing for BDD
https://github.com/Sylius/Sylius/blob/master/src/Sylius/Component/Shipping/spec/Sylius/Component/Shipping/Calculator/FlexibleRateCalculatorSpec.php
What about the real world?
All what you have just seen, are real world examples
Real world companies
RECOMMENDED READINGS