SlideShare una empresa de Scribd logo
1 de 62
Things to consider for testable code Frank Kleine, 27.10.2009
The Speaker: Frank Kleine ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Separation of Concerns ,[object Object]
Business logic
Logging
Error handling
Environment handling
Didn't we forget something really important?
Construction of Objects!
Construction of objects ,[object Object]
Construction of objects ,[object Object],[object Object]
Construction of objects ,[object Object],[object Object],[object Object],[object Object]
Construction of objects ,[object Object],[object Object],[object Object],[object Object],[object Object]
Construction of objects II ,[object Object],class Car { public function __construct() { $this->engine = new Engine(); $this->tire  = TireFactory::createTire(); } }
Construction of objects II ,[object Object],class Car { public function __construct() { $this->engine = new Engine(); $this->tire  = TireFactory::createTire(); } } Work in constructor (Anti-Pattern)
Construction of objects II ,[object Object],class Car { public function __construct() { $this->engine = new Engine(); $this->tire  = TireFactory::createTire(); } } Work in constructor (Anti-Pattern) Hard to test
Construction of objects II ,[object Object],[object Object],class Car { public function __construct() { $this->engine = new Engine(); $this->tire  = TireFactory::createTire(); } } class Car { public function __construct(Engine $eng, Tire $tire) { $this->engine = $eng; $this->tire  = $tire; } } Work in constructor (Anti-Pattern) Hard to test
Construction of objects II ,[object Object],[object Object],class Car { public function __construct() { $this->engine = new Engine(); $this->tire  = TireFactory::createTire(); } } class Car { public function __construct(Engine $eng, Tire $tire) { $this->engine = $eng; $this->tire  = $tire; } } Work in constructor (Anti-Pattern) Hard to test Piece of cake to test
Construction of objects II ,[object Object],[object Object],class Car { public function __construct() { $this->engine = new Engine(); $this->tire  = TireFactory::createTire(); } } class Car { public function __construct(Engine $eng, Tire $tire) { $this->engine = $eng; $this->tire  = $tire; } } Work in constructor (Anti-Pattern) Dependency Injection Hard to test Piece of cake to test
Dependency Injection ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object]
Law of Demeter ,[object Object],class Driver { public function drive($miles) { $this->vehicle->engine->start(); $this->vehicle->drive($miles); $this->vehicle->engine->stop(); }
Law of Demeter ,[object Object],class Driver { public function drive($miles) { $this->vehicle->engine->start(); $this->vehicle->drive($miles); $this->vehicle->engine->stop(); } Driver coupled to Engine
Law of Demeter ,[object Object],class Driver { public function drive($miles) { $this->vehicle->engine->start(); $this->vehicle->drive($miles); $this->vehicle->engine->stop(); } Hard to test: test always needs Engine or a mock of it Driver coupled to Engine
Law of Demeter ,[object Object],class Driver { public function drive($miles) { $this->vehicle->engine->start(); $this->vehicle->drive($miles); $this->vehicle->engine->stop(); } Internal state of Vehicle revealed Driver coupled to Engine Hard to test: test always needs Engine or a mock of it
Law of Demeter ,[object Object],[object Object],class Driver { public function drive($miles) { $this->vehicle->engine->start(); $this->vehicle->drive($miles); $this->vehicle->engine->stop(); } Internal state of Vehicle revealed class Driver { public function drive($miles) { $this->vehicle->start(); $this->vehicle->drive($miles); $this->vehicle->stop(); } Hard to test: test always needs Engine or a mock of it Driver coupled to Engine
Law of Demeter ,[object Object],[object Object],class Driver { public function drive($miles) { $this->vehicle->engine->start(); $this->vehicle->drive($miles); $this->vehicle->engine->stop(); } Internal state of Vehicle revealed class Driver { public function drive($miles) { $this->vehicle->start(); $this->vehicle->drive($miles); $this->vehicle->stop(); } Driver coupled to Engine Hard to test: test always needs Engine or a mock of it Driver not coupled to Engine: simpler to maintain
Law of Demeter ,[object Object],[object Object],class Driver { public function drive($miles) { $this->vehicle->engine->start(); $this->vehicle->drive($miles); $this->vehicle->engine->stop(); } Internal state of Vehicle revealed class Driver { public function drive($miles) { $this->vehicle->start(); $this->vehicle->drive($miles); $this->vehicle->stop(); } Piece of cake to test Hard to test: test always needs Engine or a mock of it Driver coupled to Engine Driver not coupled to Engine: simpler to maintain
Law of Demeter ,[object Object],[object Object],class Driver { public function drive($miles) { $this->vehicle->engine->start(); $this->vehicle->drive($miles); $this->vehicle->engine->stop(); } Internal state of Vehicle revealed class Driver { public function drive($miles) { $this->vehicle->start(); $this->vehicle->drive($miles); $this->vehicle->stop(); } Piece of cake to test Less prone to errors Driver coupled to Engine Hard to test: test always needs Engine or a mock of it Driver not coupled to Engine: simpler to maintain
Global state ,[object Object],[object Object]
Global state ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Global state: Singletons ,[object Object],[object Object]
Global state: Singletons ,[object Object],[object Object],[object Object],[object Object],[object Object]
Singleton with DI framework $binder->bind('Session') ->to('PhpSession')
Singleton with DI framework $binder->bind('Session') ->to('PhpSession') Configure the binding
Singleton with DI framework $binder->bind('Session') ->to('PhpSession') ->in(stubBindingScopes::$SINGLETON); Configure the binding Enforce singletoness: DI framework will only create one instance of PhpSession and inject always this same instance
Singleton with DI framework $binder->bind('Session') ->to('PhpSession') ->in(stubBindingScopes::$SINGLETON); class Processor { protected $session; /** * @Inject */ public function __construct(Session $session) { $this->session = $session; } … } Configure the binding Enforce singletoness: DI framework will only create one instance of PhpSession and inject always this same instance
Singleton with DI framework $binder->bind('Session') ->to('PhpSession') ->in(stubBindingScopes::$SINGLETON); class Processor { protected $session; /** * @Inject */ public function __construct(Session $session) { $this->session = $session; } … } Configure the binding Enforce singletoness: DI framework will only create one instance of PhpSession and inject always this same instance Dependency Injection
Singleton with DI framework $binder->bind('Session') ->to('PhpSession') ->in(stubBindingScopes::$SINGLETON); class Processor { protected $session; /** * @Inject */ public function __construct(Session $session) { $this->session = $session; } … } Configure the binding Enforce singletoness: DI framework will only create one instance of PhpSession and inject always this same instance Dependency Injection Tell DI framework to inject required parameters on creation of Processor
Singleton with DI framework $binder->bind('Session') ->to('PhpSession') ->in(stubBindingScopes::$SINGLETON); class Processor { protected $session; /** * @Inject */ public function __construct(Session $session) { $this->session = $session; } … } Configure the binding Enforce singletoness: DI framework will only create one instance of PhpSession and inject always this same instance Dependency Injection Piece of cake to test: independent of PhpSession Tell DI framework to inject required parameters on creation of Processor
Global state:  static  methods ,[object Object],[object Object],[object Object],[object Object]
Global state:  $_GET, $_POST, … ,[object Object]
Global state:  $_GET, $_POST, … ,[object Object],[object Object]
Global state:  $_GET, $_POST, … ,[object Object],[object Object],[object Object],[object Object]
Global state:  $_GET, $_POST, … ,[object Object],[object Object],[object Object],[object Object],[object Object]
Global state:  $_GET, $_POST, … ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Global state: Registry ,[object Object]
Global state: Registry ,[object Object],[object Object]
Global state: Registry ,[object Object],[object Object],[object Object]
Global state: Registry ,[object Object],[object Object],[object Object],[object Object]
 
Modify
Simplify Modify
Simplify Improve Modify
Finally… ,[object Object]
Singletons are really, really (and I mean really)
Singletons are really, really (and I mean really) EVIL
The End ,[object Object]
The End ,[object Object],[object Object]
Commercial break ,[object Object]
Commercial break ,[object Object],[object Object]
Commercial break ,[object Object],[object Object],[object Object]

Más contenido relacionado

La actualidad más candente

Dutch php a short tale about state machine
Dutch php   a short tale about state machineDutch php   a short tale about state machine
Dutch php a short tale about state machineŁukasz Chruściel
 
PHPSpec - the only Design Tool you need - 4Developers
PHPSpec - the only Design Tool you need - 4DevelopersPHPSpec - the only Design Tool you need - 4Developers
PHPSpec - the only Design Tool you need - 4DevelopersKacper Gunia
 
Good karma: UX Patterns and Unit Testing in Angular with Karma
Good karma: UX Patterns and Unit Testing in Angular with KarmaGood karma: UX Patterns and Unit Testing in Angular with Karma
Good karma: UX Patterns and Unit Testing in Angular with KarmaExoLeaders.com
 
Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?Nikita Popov
 
jQuery from the very beginning
jQuery from the very beginningjQuery from the very beginning
jQuery from the very beginningAnis Ahmad
 
James Thomas - Serverless Machine Learning With TensorFlow - Codemotion Berli...
James Thomas - Serverless Machine Learning With TensorFlow - Codemotion Berli...James Thomas - Serverless Machine Learning With TensorFlow - Codemotion Berli...
James Thomas - Serverless Machine Learning With TensorFlow - Codemotion Berli...Codemotion
 
Concurrent test frameworks
Concurrent test frameworksConcurrent test frameworks
Concurrent test frameworksAndrea Giuliano
 
Ditching JQuery
Ditching JQueryDitching JQuery
Ditching JQueryhowlowck
 
Testing most things in JavaScript - LeedsJS 31/05/2017
Testing most things in JavaScript - LeedsJS 31/05/2017Testing most things in JavaScript - LeedsJS 31/05/2017
Testing most things in JavaScript - LeedsJS 31/05/2017Colin Oakley
 
Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Fwdays
 
OOP in JavaScript
OOP in JavaScriptOOP in JavaScript
OOP in JavaScriptEyal Vardi
 
Optimizing Magento by Preloading Data
Optimizing Magento by Preloading DataOptimizing Magento by Preloading Data
Optimizing Magento by Preloading DataIvan Chepurnyi
 
Using of TDD practices for Magento
Using of TDD practices for MagentoUsing of TDD practices for Magento
Using of TDD practices for MagentoIvan Chepurnyi
 

La actualidad más candente (20)

Dutch php a short tale about state machine
Dutch php   a short tale about state machineDutch php   a short tale about state machine
Dutch php a short tale about state machine
 
PHPSpec - the only Design Tool you need - 4Developers
PHPSpec - the only Design Tool you need - 4DevelopersPHPSpec - the only Design Tool you need - 4Developers
PHPSpec - the only Design Tool you need - 4Developers
 
Good karma: UX Patterns and Unit Testing in Angular with Karma
Good karma: UX Patterns and Unit Testing in Angular with KarmaGood karma: UX Patterns and Unit Testing in Angular with Karma
Good karma: UX Patterns and Unit Testing in Angular with Karma
 
Frontin like-a-backer
Frontin like-a-backerFrontin like-a-backer
Frontin like-a-backer
 
Barely Enough Design
Barely Enough DesignBarely Enough Design
Barely Enough Design
 
Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?
 
jQuery from the very beginning
jQuery from the very beginningjQuery from the very beginning
jQuery from the very beginning
 
James Thomas - Serverless Machine Learning With TensorFlow - Codemotion Berli...
James Thomas - Serverless Machine Learning With TensorFlow - Codemotion Berli...James Thomas - Serverless Machine Learning With TensorFlow - Codemotion Berli...
James Thomas - Serverless Machine Learning With TensorFlow - Codemotion Berli...
 
Concurrent test frameworks
Concurrent test frameworksConcurrent test frameworks
Concurrent test frameworks
 
QA for PHP projects
QA for PHP projectsQA for PHP projects
QA for PHP projects
 
Refactoring
RefactoringRefactoring
Refactoring
 
Ditching JQuery
Ditching JQueryDitching JQuery
Ditching JQuery
 
Testing most things in JavaScript - LeedsJS 31/05/2017
Testing most things in JavaScript - LeedsJS 31/05/2017Testing most things in JavaScript - LeedsJS 31/05/2017
Testing most things in JavaScript - LeedsJS 31/05/2017
 
TDD with PhpSpec
TDD with PhpSpecTDD with PhpSpec
TDD with PhpSpec
 
Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"
 
PHPSpec BDD for PHP
PHPSpec BDD for PHPPHPSpec BDD for PHP
PHPSpec BDD for PHP
 
OOP in JavaScript
OOP in JavaScriptOOP in JavaScript
OOP in JavaScript
 
Optimizing Magento by Preloading Data
Optimizing Magento by Preloading DataOptimizing Magento by Preloading Data
Optimizing Magento by Preloading Data
 
Using of TDD practices for Magento
Using of TDD practices for MagentoUsing of TDD practices for Magento
Using of TDD practices for Magento
 
Test driven development_for_php
Test driven development_for_phpTest driven development_for_php
Test driven development_for_php
 

Destacado

What A Wonderful World Av Annie
What A Wonderful World Av AnnieWhat A Wonderful World Av Annie
What A Wonderful World Av AnnieAnnie Lindgren
 
Frontend-Performance mit PHP
Frontend-Performance mit PHPFrontend-Performance mit PHP
Frontend-Performance mit PHPFrank Kleine
 
Modello - Riccardo Colombo
Modello - Riccardo ColomboModello - Riccardo Colombo
Modello - Riccardo ColomboNaba Design
 
Fake Food - Work In Progress
Fake Food - Work In ProgressFake Food - Work In Progress
Fake Food - Work In ProgressNaba Design
 

Destacado (7)

What A Wonderful World Av Annie
What A Wonderful World Av AnnieWhat A Wonderful World Av Annie
What A Wonderful World Av Annie
 
Vackra Bilder 2
Vackra Bilder  2Vackra Bilder  2
Vackra Bilder 2
 
Frontend-Performance mit PHP
Frontend-Performance mit PHPFrontend-Performance mit PHP
Frontend-Performance mit PHP
 
Gott Nytt År!
Gott Nytt År!Gott Nytt År!
Gott Nytt År!
 
Barnbarn Pps
Barnbarn PpsBarnbarn Pps
Barnbarn Pps
 
Modello - Riccardo Colombo
Modello - Riccardo ColomboModello - Riccardo Colombo
Modello - Riccardo Colombo
 
Fake Food - Work In Progress
Fake Food - Work In ProgressFake Food - Work In Progress
Fake Food - Work In Progress
 

Similar a Things to consider for testable Code

Symfony 4 Workshop - Limenius
Symfony 4 Workshop - LimeniusSymfony 4 Workshop - Limenius
Symfony 4 Workshop - LimeniusIgnacio Martín
 
"Full Stack frameworks or a story about how to reconcile Front (good) and Bac...
"Full Stack frameworks or a story about how to reconcile Front (good) and Bac..."Full Stack frameworks or a story about how to reconcile Front (good) and Bac...
"Full Stack frameworks or a story about how to reconcile Front (good) and Bac...Fwdays
 
2012 02-04 fosdem 2012 - drools planner
2012 02-04 fosdem 2012 - drools planner2012 02-04 fosdem 2012 - drools planner
2012 02-04 fosdem 2012 - drools plannerGeoffrey De Smet
 
JUDCon London 2011 - Bin packing with drools planner by example
JUDCon London 2011 - Bin packing with drools planner by exampleJUDCon London 2011 - Bin packing with drools planner by example
JUDCon London 2011 - Bin packing with drools planner by exampleGeoffrey De Smet
 
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testabilityPHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testabilityGiorgio Sironi
 
Curso Symfony - Clase 4
Curso Symfony - Clase 4Curso Symfony - Clase 4
Curso Symfony - Clase 4Javier Eguiluz
 
Using Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkUsing Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkDirk Haun
 
Magento Live Australia 2016: Request Flow
Magento Live Australia 2016: Request FlowMagento Live Australia 2016: Request Flow
Magento Live Australia 2016: Request FlowVrann Tulika
 
Getting started with TDD - Confoo 2014
Getting started with TDD - Confoo 2014Getting started with TDD - Confoo 2014
Getting started with TDD - Confoo 2014Eric Hogue
 
Why is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenariosWhy is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenariosDivante
 
4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk
4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk
4Developers 2015: Be pragmatic, be SOLID - Krzysztof MenżykPROIDEA
 
ActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group PresentationActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group Presentationipolevoy
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applicationschartjes
 
Total Compensationbuild.xml Builds, tests, and runs th.docx
Total Compensationbuild.xml      Builds, tests, and runs th.docxTotal Compensationbuild.xml      Builds, tests, and runs th.docx
Total Compensationbuild.xml Builds, tests, and runs th.docxturveycharlyn
 
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020Andrzej Jóźwiak
 
Testing persistence in PHP with DbUnit
Testing persistence in PHP with DbUnitTesting persistence in PHP with DbUnit
Testing persistence in PHP with DbUnitPeter Wilcsinszky
 

Similar a Things to consider for testable Code (20)

Symfony 4 Workshop - Limenius
Symfony 4 Workshop - LimeniusSymfony 4 Workshop - Limenius
Symfony 4 Workshop - Limenius
 
"Full Stack frameworks or a story about how to reconcile Front (good) and Bac...
"Full Stack frameworks or a story about how to reconcile Front (good) and Bac..."Full Stack frameworks or a story about how to reconcile Front (good) and Bac...
"Full Stack frameworks or a story about how to reconcile Front (good) and Bac...
 
2012 02-04 fosdem 2012 - drools planner
2012 02-04 fosdem 2012 - drools planner2012 02-04 fosdem 2012 - drools planner
2012 02-04 fosdem 2012 - drools planner
 
JUDCon London 2011 - Bin packing with drools planner by example
JUDCon London 2011 - Bin packing with drools planner by exampleJUDCon London 2011 - Bin packing with drools planner by example
JUDCon London 2011 - Bin packing with drools planner by example
 
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testabilityPHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testability
 
Curso Symfony - Clase 4
Curso Symfony - Clase 4Curso Symfony - Clase 4
Curso Symfony - Clase 4
 
Using Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkUsing Geeklog as a Web Application Framework
Using Geeklog as a Web Application Framework
 
PHP Unit Testing
PHP Unit TestingPHP Unit Testing
PHP Unit Testing
 
Unittests für Dummies
Unittests für DummiesUnittests für Dummies
Unittests für Dummies
 
Magento Live Australia 2016: Request Flow
Magento Live Australia 2016: Request FlowMagento Live Australia 2016: Request Flow
Magento Live Australia 2016: Request Flow
 
Getting started with TDD - Confoo 2014
Getting started with TDD - Confoo 2014Getting started with TDD - Confoo 2014
Getting started with TDD - Confoo 2014
 
Why is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenariosWhy is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenarios
 
4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk
4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk
4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk
 
Be pragmatic, be SOLID
Be pragmatic, be SOLIDBe pragmatic, be SOLID
Be pragmatic, be SOLID
 
ActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group PresentationActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group Presentation
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applications
 
Going web native
Going web nativeGoing web native
Going web native
 
Total Compensationbuild.xml Builds, tests, and runs th.docx
Total Compensationbuild.xml      Builds, tests, and runs th.docxTotal Compensationbuild.xml      Builds, tests, and runs th.docx
Total Compensationbuild.xml Builds, tests, and runs th.docx
 
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020
 
Testing persistence in PHP with DbUnit
Testing persistence in PHP with DbUnitTesting persistence in PHP with DbUnit
Testing persistence in PHP with DbUnit
 

Último

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 

Último (20)

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 

Things to consider for testable Code

  • 1. Things to consider for testable code Frank Kleine, 27.10.2009
  • 2.
  • 3.
  • 8. Didn't we forget something really important?
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34. Singleton with DI framework $binder->bind('Session') ->to('PhpSession')
  • 35. Singleton with DI framework $binder->bind('Session') ->to('PhpSession') Configure the binding
  • 36. Singleton with DI framework $binder->bind('Session') ->to('PhpSession') ->in(stubBindingScopes::$SINGLETON); Configure the binding Enforce singletoness: DI framework will only create one instance of PhpSession and inject always this same instance
  • 37. Singleton with DI framework $binder->bind('Session') ->to('PhpSession') ->in(stubBindingScopes::$SINGLETON); class Processor { protected $session; /** * @Inject */ public function __construct(Session $session) { $this->session = $session; } … } Configure the binding Enforce singletoness: DI framework will only create one instance of PhpSession and inject always this same instance
  • 38. Singleton with DI framework $binder->bind('Session') ->to('PhpSession') ->in(stubBindingScopes::$SINGLETON); class Processor { protected $session; /** * @Inject */ public function __construct(Session $session) { $this->session = $session; } … } Configure the binding Enforce singletoness: DI framework will only create one instance of PhpSession and inject always this same instance Dependency Injection
  • 39. Singleton with DI framework $binder->bind('Session') ->to('PhpSession') ->in(stubBindingScopes::$SINGLETON); class Processor { protected $session; /** * @Inject */ public function __construct(Session $session) { $this->session = $session; } … } Configure the binding Enforce singletoness: DI framework will only create one instance of PhpSession and inject always this same instance Dependency Injection Tell DI framework to inject required parameters on creation of Processor
  • 40. Singleton with DI framework $binder->bind('Session') ->to('PhpSession') ->in(stubBindingScopes::$SINGLETON); class Processor { protected $session; /** * @Inject */ public function __construct(Session $session) { $this->session = $session; } … } Configure the binding Enforce singletoness: DI framework will only create one instance of PhpSession and inject always this same instance Dependency Injection Piece of cake to test: independent of PhpSession Tell DI framework to inject required parameters on creation of Processor
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.  
  • 55.
  • 56. Singletons are really, really (and I mean really)
  • 57. Singletons are really, really (and I mean really) EVIL
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.

Notas del editor

  1. Simplify – remove accidental complexity Improve – smaller methods, better namings. You need unit tests for this.
  2. Simplify – remove accidental complexity Improve – smaller methods, better namings. You need unit tests for this.
  3. Simplify – remove accidental complexity Improve – smaller methods, better namings. You need unit tests for this.
  4. Simplify – remove accidental complexity Improve – smaller methods, better namings. You need unit tests for this.