Top Banner
Driving Your Development In PHP
62

Driving development in PHP

May 26, 2015

Download

Software

Eduardo Gulias

When developing we have a lot of options on how to do it.
From nothing to let us guide by methodologies from the first to the last line of code.
In this slides we will visit which options (among many others) do we have and we will center on TDD, DDD and BDD, their concepts and tools that exist in PHP.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Driving development in PHP

Driving

Your

Development

In

PHP

Page 2: Driving 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

Page 3: Driving development in PHP

This talk is NOT about automated testing

Page 4: Driving development in PHP

Because you are already testing, right?

Page 5: Driving development in PHP
Page 6: Driving development in PHP

What means “driving your development”?

Page 7: Driving development in PHP

"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.

Page 8: Driving development in PHP

Are the tactics and tools we, software developers, have for helping us in creating software we won't

hate in 2 weeks

Page 9: Driving development in PHP

Development Driven (tactics)

VS

Application Architecture (strategies)

Page 10: Driving development in PHP

Development driven are our “tactics” for when we are developing.

Page 11: Driving development in PHP

And Software architecture are the “strategies” we follow to guide future development.

Page 12: Driving development in PHP

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

Page 13: Driving development in PHP

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

Page 14: Driving development in PHP
Page 15: Driving development in PHP

TDD – 2002 – Kent Beck

DDD – 2003 – Eric Evans

BDD - ~2004 – Dan North

Page 16: Driving development in PHP

TEST DRIVEN DEVELOPMENT

Page 17: Driving development in PHP

Test Driven Development

● Make the test red

● Make it green (Implement)

● Refactor (Remove duplication)

Page 18: Driving development in PHP

Test Driven Development

● Assertion First ● Baby Steps

Page 19: Driving development in PHP

https://github.com/egulias/TagDebug/blob/master/Tests/Tag/Filter/NameTest.php

Page 20: Driving development in PHP

https://github.com/egulias/TagDebug/blob/master/Tests/Tag/Filter/NameTest.php

Page 21: Driving development in PHP

https://github.com/egulias/TagDebug/blob/master/Tag/Filter/Name.php

Page 22: Driving development in PHP

https://github.com/egulias/TagDebug/blob/master/Tests/Tag/Filter/NameTest.php

Page 23: Driving development in PHP

Test Driven Development

● Triangulation ● Oblivious Implementation

Page 24: Driving development in PHP

Test Driven Development

Tools

Page 25: Driving development in PHP

Test Driven Development

● PHPUnit– Alone

– Mockery

– Prophecy

– Phake

● Simpletest

Page 26: Driving development in PHP

Test Driven Development

● PHPUnit– Alone

– Mockery

– Prophecy

– Phake

● Simpletest

Page 27: Driving development in PHP

https://github.com/egulias/TagDebug/blob/master/Tests/Tag/Filter/NameTest.php

Page 28: Driving development in PHP

Test Driven Development

● PHPUnit– Alone

– Mockery

– Prophecy

– Phake

● Simpletest

Page 29: Driving development in PHP

https://github.com/egulias/TagDebug/blob/master/Tag/Filter/Name.php

Page 30: Driving development in PHP

Test Driven Development

● PHPUnit– Alone

– Mockery

– Prophecy

– Phake

● Simpletest

Page 31: Driving development in PHP

Test Driven Development

● PHPUnit– Alone

– Mockery

– Prophecy

– Phake

● Simpletest (2012)

Page 32: Driving development in PHP

100% COVERAGE

BECAUSE YEAH

Page 33: Driving development in PHP

DOMAIN DRIVEN DESIGN

Page 34: Driving development in PHP

Is NOT a silver bullet

Page 35: Driving development in PHP

● Objects with Business meaning and value

● Databases, Frameworks, etc are implementation details

● Focus your development on business behavior

Domain Driven Design

Page 36: Driving development in PHP

Domain Driven Design

There are artifacts and strategies but no tools

Page 37: Driving development in PHP

Entity

Aggregate

Repository

Value Object

BoundedContext

Ubiquitous Language

Factory

Service

DomainEvent

Domain Driven Design

Page 38: Driving development in PHP

Constraints

Specification

IntentionRevealingInterfaces

Side-effectFREE

Functions

Shared Kernel

Anti-corruptionLayer

Domain Driven Design

Page 39: Driving development in PHP

https://github.com/Bodaclick/EVTCore/blob/dev/src/EVT/CoreDomain/Lead/Event.php

Page 40: Driving development in PHP

https://github.com/Bodaclick/EVTCore/blob/dev/src/EVT/CoreDomain/Lead/Lead.php

Page 41: Driving development in PHP

https://github.com/Bodaclick/EVTCore/blob/dev/src/EVT/CoreDomain/RepositoryInterface.php

Page 42: Driving development in PHP

https://github.com/Bodaclick/EVTCore/blob/dev/src/EVT/CoreDomainBundle/Resources/config/services.yml

Page 43: Driving development in PHP

https://github.com/Bodaclick/EVTCore

Page 44: Driving development in PHP
Page 45: Driving development in PHP

BEHAVIOR DRIVEN DEVELOPMENT

Page 46: Driving development in PHP

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/

Page 47: Driving development in PHP

Behavior Driven Development

Tools

Page 48: Driving development in PHP

Behavior Driven Development

Behathttp://docs.behat.org

Page 49: Driving development in PHP

https://github.com/Sylius/Sylius/blob/master/features/backend/shipping_categories.feature

Page 50: Driving development in PHP

https://github.com/Sylius/Sylius/blob/master/src/Sylius/Bundle/ShippingBundle/Behat/ShippingContext.php

Page 51: Driving development in PHP

Behavior Driven Development

phpSpechttp://phpspec.net/docs/introduction.html

Unit Testing for BDD

Page 52: Driving development in PHP

https://github.com/Sylius/Sylius/blob/master/src/Sylius/Component/Shipping/spec/Sylius/Component/Shipping/Calculator/FlexibleRateCalculatorSpec.php

Page 53: Driving development in PHP
Page 54: Driving development in PHP

What about the real world?

Page 55: Driving development in PHP

All what you have just seen, are real world examples

Page 56: Driving development in PHP

Real world companies

Page 57: Driving development in PHP

RECOMMENDED READINGS

Page 58: Driving development in PHP
Page 59: Driving development in PHP
Page 60: Driving development in PHP
Page 61: Driving development in PHP
Page 62: Driving development in PHP