Top Banner
The Framework as an Implementation Detail Marcello Duarte / Konstantin Kudryashov
41

The framework as an implementation detail

May 10, 2015

Download

Technology

Marcello Duarte

What would your application look like if it were written by the people who write the testing frameworks? If unit tests make classes more modular, by forcing you to test it in isolation, then what is the effect of expanding this to a less granular level, the acceptance and functional test. The more modern application architecture evolves, the more we hear the very old patterns being rediscovered and re-adopted. 1979 Trygve's MVC is a classic example, so are the SOLID principles. In this talk we will look on how Symfony allows for a really decoupled, easy to test application, by following on the footsteps of Alistair Cockburn's hexagonal architecture.
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: The framework as an implementation detail

The Framework as an Implementation DetailMarcello Duarte / Konstantin Kudryashov

Page 2: The framework as an implementation detail

@_md @everzeta SensioLabsEvent

About us

@_mdMarcello Duarte HEAD OF TRAINING, INVIQA

@everzetKonstantin Kudryashov BDD PRACTICE MANAGER, INVIQA

Page 3: The framework as an implementation detail

@_md @everzeta SensioLabsEvent

This talk

[ Convenience ][ Choices ][ Future ]

Page 4: The framework as an implementation detail

@_md @everzeta SensioLabsEvent

Choice

Convenience

http://www.flickr.com/photos/johnwinkelman/6200402992/

Page 5: The framework as an implementation detail

@_md @everzeta SensioLabsEvent

We dolove .

Page 6: The framework as an implementation detail

@_md @everzeta SensioLabsEvent

Promise

“A framework is ‘just’ one of the tools to help you develop better and faster”

– Symfony documentation

Page 7: The framework as an implementation detail

@_md @everzeta SensioLabsEvent

“The only way to go fast is to go well” – Uncle Bob

FAST SLOW

QUALITY SWITCH

Page 8: The framework as an implementation detail

@_md @everzeta SensioLabsEvent

Relative cost of repair

analysis design code test support

Page 9: The framework as an implementation detail

@_md @everzeta SensioLabsEvent

Convenientvs

Maintainable

Page 10: The framework as an implementation detail

@_md @everzeta SensioLabsEvent

A framework is “convenient” when it makes choices for you

BookController e

xtends Controlle

r

AuthorsController extends ContainerAwareController

Page 11: The framework as an implementation detail

@_md @everzeta SensioLabsEvent

The code is maintainable when the framework lets you make

the choices

Page 12: The framework as an implementation detail

@_md @everzeta SensioLabsEvent

Instability and abstractnessinstability

abstractness

Page 13: The framework as an implementation detail

@_md @everzeta SensioLabsEvent

The “convenient” code is usually not very testable

Page 14: The framework as an implementation detail

@_md @everzeta SensioLabsEvent

Symfony can be convenient

public function updateAction($id){ $em = $this->getDoctrine()->getManager(); $product = $em->getRepository('AcmeStoreBundle:Product')->find($id);

if (!$product) { throw $this->createNotFoundException( 'No product found for id '.$id ); }

$product->setName('New product name!'); $em->flush();

return $this->redirect($this->generateUrl('homepage'));}

Page 15: The framework as an implementation detail

@_md @everzeta SensioLabsEvent

The “convenient” Controllertends to ask for more

Integration Tests

Page 16: The framework as an implementation detail

@_md @everzeta SensioLabsEvent

Integration Testsstinks of coupling

Page 17: The framework as an implementation detail

@_md @everzeta SensioLabsEvent

Feedback

Outer QualityInner Quality

Acceptance TestsUnit Tests

Page 18: The framework as an implementation detail

@_md @everzeta SensioLabsEvent

Choice

Choices

http://www.flickr.com/photos/tmartin/32010732/

Page 19: The framework as an implementation detail

@_md @everzeta SensioLabsEvent

Should we always TDD? what the Start Up said what the Craftsmen said

Page 20: The framework as an implementation detail

@_md @everzeta SensioLabsEvent

We doTest Driven Design

Page 21: The framework as an implementation detail

@_md @everzeta SensioLabsEvent

Design is about choices

Page 22: The framework as an implementation detail

@_md @everzeta SensioLabsEvent

Design is a professional activity

Page 23: The framework as an implementation detail

@_md @everzeta SensioLabsEvent

TDD is about communication

Page 24: The framework as an implementation detail

@_md @everzeta SensioLabsEvent

TDD is about your stakeholders

Page 25: The framework as an implementation detail

@_md @everzeta SensioLabsEvent

The developers in the team are also stakeholders

Page 26: The framework as an implementation detail

@_md @everzeta SensioLabsEvent

TDD is for long term relationships

Page 27: The framework as an implementation detail

@_md @everzeta SensioLabsEvent

How many dependencies can you spot?

public function updateAction($id){ $em = $this->getDoctrine()->getManager(); $product = $em->getRepository('AcmeStoreBundle:Product')->find($id);

if (!$product) { throw $this->createNotFoundException( 'No product found for id '.$id ); }

$product->setName('New product name!'); $em->flush();

return $this->redirect($this->generateUrl('homepage'));}

Page 28: The framework as an implementation detail

@_md @everzeta SensioLabsEvent

How many dependencies can you spot?

public function updateAction($id){ $em = $this->getDoctrine()->getManager(); $product = $em->getRepository('AcmeStoreBundle:Product')->find($id);

if (!$product) { throw $this->createNotFoundException( 'No product found for id '.$id ); }

$product->setName('New product name!'); $em->flush();

return $this->redirect($this->generateUrl('homepage'));}

DoctrineRedirectRouterModel

Page 29: The framework as an implementation detail

@_md @everzeta SensioLabsEvent

Hexagonal Architecture

“The hexagon is not a hexagon because the number six is important, but rather to allow the people doing the drawing

to have room to insert ports and adapters as they need”

:)

[Cockburn 08]

Page 30: The framework as an implementation detail

@_md @everzeta SensioLabsEvent

http://www.flickr.com/photos/10849858@N00/2696404813

Page 31: The framework as an implementation detail

@_md @everzeta SensioLabsEvent

http://www.flickr.com/photos/mac_users_guide/3680586328/

Page 32: The framework as an implementation detail

@_md @everzeta SensioLabsEvent

your application

Page 33: The framework as an implementation detail

@_md @everzeta SensioLabsEvent

web gui app

your application

user side ports

test adapter

Page 34: The framework as an implementation detail

@_md @everzeta SensioLabsEvent

web gui app

your application

user side ports

test adapter

data side ports

db access service

in memory

db

Page 35: The framework as an implementation detail

@_md @everzeta SensioLabsEvent

Hexagonal Architecture

Dbrest

Logs

Page 36: The framework as an implementation detail

@_md @everzeta SensioLabsEvent

Dependency Inversion

Higher level modules should not depend on lower level details

[Martin 02]

Page 37: The framework as an implementation detail

@_md @everzeta SensioLabsEvent

Naive implementation

controller

use case

utility

uses

uses

Page 38: The framework as an implementation detail

@_md @everzeta SensioLabsEvent

Dependency Inversion

use case

serviceadapter

utilityadapter

service

utility

Page 39: The framework as an implementation detail

@_md @everzeta SensioLabsEvent

Choice

Let’s see some code

Page 40: The framework as an implementation detail

@_md @everzeta SensioLabsEvent

Choice

Future

Page 41: The framework as an implementation detail

@_md @everzeta SensioLabsEvent

Choice

Thanks!joind.in/9331

github.com/MarcelloDuarte/hexagonal-symfony