SlideShare a Scribd company logo
1 of 33
Architettura e testabilità
(Architecture and testability)
Listen to your tests on steroids
Giorgio Sironi
Who am I
● PHP freelancer from 2005
● Writer for php|architect, DZone
● Perito informatico, undergraduate
in Engineering at Politecnico di
Milano
This talk
● Maintainability, and why testing
● Various techniques to favor ease
of testing AND maintainability
● Slides in English (test d'unità,
Legge di Demetra...)
Other talks
● Dependency Injection
● Testare l'ignoto
● Agile software lifecycle
What is maintainability?
● Being ready to change!
…but not too much
● Taking the first bullet
Favored by maintainability
● New requirements
● Evolving requirements
● Iterative development
● Long-term maintenance
Kinds of tests
● Unit tests
● Integration tests
● Acceptance (end-to-end) tests
and functional tests
Maintainability (1 of 2)
SOLID principles (not all of them)
● Single responsibility
● Open/closed
● Dependency Inversion
Maintainability (2 of 2)
Loose coupling
High cohesion
Information hiding
Orthogonality
...needed from day 1, like readability and testability
Good but...
Good buzzwords, but
how do I apply that in
practice?
Testing first
● Testing first → Testable code
● Testable code → Maintainable
code
Problems with tests
● A test is slow?
● A test is brittle?
● A test is difficult to write?
Solution to problems with tests
Change the design
to ease testing (listen
to your tests)
Test must change too
● Good: test suite
● Bad: no test suite
● Worse: unmaintainable test suite
Examples of listening to the tests
● Small tests => high cohesion
● Unit tests => loose coupling
4 pillars...
1. Dependency injection
● No new operator outside of
Factories
● Easy to change lifecycles and
implementations
1. Dependency Injection (without)
<?php
class Ferrari
{
private $_engine;
public function __construct()
{
$this->_engine = new
Engine();
}
}
1. Dependency Injection (with)
<?php
class Ferrari
{
private $_engine;
public function
__construct(Engine $engine)
{
$this->_engine = $engine;
}
}
2. Avoid static methods
● Explicit concept
● Orthogonality
2. Avoid static methods (before)
<?php
class Collection
{
public function find($key)
{
Sorter::sort($this);
// ..search stuff
}
}
2. Avoid using static methods (after)
<?php
class Collection
{
public function find($key)
{
$this->_sorter->sort($this);
// ..search stuff
}
}
3. Law of Demeter
● Do not walk the... arrows
● Exceptions: Factories, data
structures
3. Law of Demeter (without)
<?php
class PC
{
public function powerOn()
{
$this->_mobo->cpu->cache
->powerOn();
}
}
3. Law of Demeter (with)
<?php
class PC
{
public function powerOn()
{
foreach ($this->_powered as
$item) {
/** @var Powered $item */
$item->powerOn();
}
}
}
3. Law of Demeter (with)
<?php
class PC
{
public function powerOn()
{
$this->_mobo->powerOn();
}
}
4. Singleton vs. Factory
● Singleton is static, impossible to
mock
● Global state
● Hidden dependency
4. Singleton vs. Factory
<?php
class Authenticator
{
public function login($user,
$pass)
{
Db::select(...);
}
}
4. Singleton vs. Factory
<?php
class Authenticator
{
public function __construct(Db $db)
{ ... }
public function login($user, $pass)
{
$this->_db->select(...);
}
}
Be honest
● If you need something, inject it (or
inject its factory)
● Tell > Ask > Look
Recipe for a clear, clean Api
TDD is...
Test-Driven Design
References
● Guide: Writing Testable Code
(Misko Hevery)
● Growing Object-Oriented
Software, Guided by Tests –
Freeman, Price
Contacts
● http://giorgiosironi.blogspot.com
● @giorgiosironi
Questions?
Q/A

More Related Content

What's hot

Programming in python - Week 4
Programming in python  - Week 4Programming in python  - Week 4
Programming in python - Week 4Priya Nayak
 
Programming in python - Week 7,8
Programming in python - Week 7,8Programming in python - Week 7,8
Programming in python - Week 7,8Priya Nayak
 
Chapter 2 : Programming with Java Statements
Chapter 2 : Programming with Java StatementsChapter 2 : Programming with Java Statements
Chapter 2 : Programming with Java StatementsIt Academy
 
Interfaces and abstract classes
Interfaces and abstract classesInterfaces and abstract classes
Interfaces and abstract classesAKANSH SINGHAL
 
Solit 2012, TDD и отдельные аспекты тестирования в Java, Антонина Шафранская
Solit 2012, TDD и отдельные аспекты тестирования в Java, Антонина ШафранскаяSolit 2012, TDD и отдельные аспекты тестирования в Java, Антонина Шафранская
Solit 2012, TDD и отдельные аспекты тестирования в Java, Антонина Шафранскаяsolit
 
Code review (i)
Code review (i)Code review (i)
Code review (i)嘉平 蔡
 
Object as function argument , friend and static function by shahzad younas
Object as function argument , friend and static function by shahzad younasObject as function argument , friend and static function by shahzad younas
Object as function argument , friend and static function by shahzad younasShahzad Younas
 
Conditional statements
Conditional statementsConditional statements
Conditional statementscherrybear2014
 

What's hot (16)

Programming in python - Week 4
Programming in python  - Week 4Programming in python  - Week 4
Programming in python - Week 4
 
Programming in python - Week 7,8
Programming in python - Week 7,8Programming in python - Week 7,8
Programming in python - Week 7,8
 
Interface in java
Interface in javaInterface in java
Interface in java
 
java tutorial 4
 java tutorial 4 java tutorial 4
java tutorial 4
 
06 exceptions
06 exceptions06 exceptions
06 exceptions
 
Chapter 2 : Programming with Java Statements
Chapter 2 : Programming with Java StatementsChapter 2 : Programming with Java Statements
Chapter 2 : Programming with Java Statements
 
13. interfaces
13. interfaces13. interfaces
13. interfaces
 
Interfaces and abstract classes
Interfaces and abstract classesInterfaces and abstract classes
Interfaces and abstract classes
 
Java exeception handling
Java exeception handlingJava exeception handling
Java exeception handling
 
Interfaces in java
Interfaces in javaInterfaces in java
Interfaces in java
 
Solit 2012, TDD и отдельные аспекты тестирования в Java, Антонина Шафранская
Solit 2012, TDD и отдельные аспекты тестирования в Java, Антонина ШафранскаяSolit 2012, TDD и отдельные аспекты тестирования в Java, Антонина Шафранская
Solit 2012, TDD и отдельные аспекты тестирования в Java, Антонина Шафранская
 
Exception handling
Exception handlingException handling
Exception handling
 
Code review (i)
Code review (i)Code review (i)
Code review (i)
 
Object as function argument , friend and static function by shahzad younas
Object as function argument , friend and static function by shahzad younasObject as function argument , friend and static function by shahzad younas
Object as function argument , friend and static function by shahzad younas
 
Conditional statements
Conditional statementsConditional statements
Conditional statements
 
Value Types
Value TypesValue Types
Value Types
 

Viewers also liked

Viewers also liked (12)

Senior Sem PP
Senior Sem PPSenior Sem PP
Senior Sem PP
 
마더리스크라운드 - Steroid in pregnancy
마더리스크라운드 - Steroid in pregnancy마더리스크라운드 - Steroid in pregnancy
마더리스크라운드 - Steroid in pregnancy
 
Steroids,teachback
Steroids,teachbackSteroids,teachback
Steroids,teachback
 
Anabolic Steroid Use
Anabolic Steroid UseAnabolic Steroid Use
Anabolic Steroid Use
 
Functions of fatty acids
Functions of fatty acidsFunctions of fatty acids
Functions of fatty acids
 
Glycolipid ppt
Glycolipid pptGlycolipid ppt
Glycolipid ppt
 
Nucleic Acids
Nucleic AcidsNucleic Acids
Nucleic Acids
 
Phospholipids 2003
Phospholipids 2003Phospholipids 2003
Phospholipids 2003
 
Eczema
EczemaEczema
Eczema
 
Corticosteroids
CorticosteroidsCorticosteroids
Corticosteroids
 
NEPHROTIC SYNDROME
NEPHROTIC SYNDROMENEPHROTIC SYNDROME
NEPHROTIC SYNDROME
 
Nephrotic syndrome in children
Nephrotic syndrome in childrenNephrotic syndrome in children
Nephrotic syndrome in children
 

Similar to Php day2010

PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testabilityPHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testabilityGiorgio Sironi
 
Unit Testing and TDD 2017
Unit Testing and TDD 2017Unit Testing and TDD 2017
Unit Testing and TDD 2017Xavi Hidalgo
 
Basics of writing clean code
Basics of writing clean codeBasics of writing clean code
Basics of writing clean codeKnoldus Inc.
 
2016 10-04: tdd++: tdd made easier
2016 10-04: tdd++: tdd made easier2016 10-04: tdd++: tdd made easier
2016 10-04: tdd++: tdd made easierChristian Hujer
 
Keeping code clean
Keeping code cleanKeeping code clean
Keeping code cleanBrett Child
 
Getting Started with Test-Driven Development at Longhorn PHP 2023
Getting Started with Test-Driven Development at Longhorn PHP 2023Getting Started with Test-Driven Development at Longhorn PHP 2023
Getting Started with Test-Driven Development at Longhorn PHP 2023Scott Keck-Warren
 
Working With Legacy Code
Working With Legacy CodeWorking With Legacy Code
Working With Legacy CodeAndrea Polci
 
Unit testing legacy code
Unit testing legacy codeUnit testing legacy code
Unit testing legacy codeLars Thorup
 
An insight to test driven development and unit testing
An insight to test driven development and unit testingAn insight to test driven development and unit testing
An insight to test driven development and unit testingDharmendra Prasad
 
Software Design Principles and Best Practices - Satyajit Dey
Software Design Principles and Best Practices - Satyajit DeySoftware Design Principles and Best Practices - Satyajit Dey
Software Design Principles and Best Practices - Satyajit DeyCefalo
 
Codeception: introduction to php testing (v2 - Aberdeen php)
Codeception: introduction to php testing (v2 - Aberdeen php)Codeception: introduction to php testing (v2 - Aberdeen php)
Codeception: introduction to php testing (v2 - Aberdeen php)Engineor
 
How to establish ways of working that allows shifting-left of the automation ...
How to establish ways of working that allows shifting-left of the automation ...How to establish ways of working that allows shifting-left of the automation ...
How to establish ways of working that allows shifting-left of the automation ...Max Barrass
 
Pragmatic Introduction to PHP Unit Testing (2015)
Pragmatic Introduction to PHP Unit Testing (2015)Pragmatic Introduction to PHP Unit Testing (2015)
Pragmatic Introduction to PHP Unit Testing (2015)Peter Kofler
 
Codeception: introduction to php testing
Codeception: introduction to php testingCodeception: introduction to php testing
Codeception: introduction to php testingEngineor
 

Similar to Php day2010 (20)

PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testabilityPHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testability
 
Unit Testing and TDD 2017
Unit Testing and TDD 2017Unit Testing and TDD 2017
Unit Testing and TDD 2017
 
Test Automation
Test AutomationTest Automation
Test Automation
 
Basics of writing clean code
Basics of writing clean codeBasics of writing clean code
Basics of writing clean code
 
Automated testing
Automated testingAutomated testing
Automated testing
 
2016 10-04: tdd++: tdd made easier
2016 10-04: tdd++: tdd made easier2016 10-04: tdd++: tdd made easier
2016 10-04: tdd++: tdd made easier
 
Unit testing
Unit testingUnit testing
Unit testing
 
Keeping code clean
Keeping code cleanKeeping code clean
Keeping code clean
 
Core java
Core javaCore java
Core java
 
Getting Started with Test-Driven Development at Longhorn PHP 2023
Getting Started with Test-Driven Development at Longhorn PHP 2023Getting Started with Test-Driven Development at Longhorn PHP 2023
Getting Started with Test-Driven Development at Longhorn PHP 2023
 
Refactoring
RefactoringRefactoring
Refactoring
 
Working With Legacy Code
Working With Legacy CodeWorking With Legacy Code
Working With Legacy Code
 
Unit testing legacy code
Unit testing legacy codeUnit testing legacy code
Unit testing legacy code
 
An insight to test driven development and unit testing
An insight to test driven development and unit testingAn insight to test driven development and unit testing
An insight to test driven development and unit testing
 
Workshop - E2e tests with protractor
Workshop - E2e tests with protractorWorkshop - E2e tests with protractor
Workshop - E2e tests with protractor
 
Software Design Principles and Best Practices - Satyajit Dey
Software Design Principles and Best Practices - Satyajit DeySoftware Design Principles and Best Practices - Satyajit Dey
Software Design Principles and Best Practices - Satyajit Dey
 
Codeception: introduction to php testing (v2 - Aberdeen php)
Codeception: introduction to php testing (v2 - Aberdeen php)Codeception: introduction to php testing (v2 - Aberdeen php)
Codeception: introduction to php testing (v2 - Aberdeen php)
 
How to establish ways of working that allows shifting-left of the automation ...
How to establish ways of working that allows shifting-left of the automation ...How to establish ways of working that allows shifting-left of the automation ...
How to establish ways of working that allows shifting-left of the automation ...
 
Pragmatic Introduction to PHP Unit Testing (2015)
Pragmatic Introduction to PHP Unit Testing (2015)Pragmatic Introduction to PHP Unit Testing (2015)
Pragmatic Introduction to PHP Unit Testing (2015)
 
Codeception: introduction to php testing
Codeception: introduction to php testingCodeception: introduction to php testing
Codeception: introduction to php testing
 

More from Giorgio Sironi

Case study: Khan Academy
Case study: Khan AcademyCase study: Khan Academy
Case study: Khan AcademyGiorgio Sironi
 
Case study: iTunes for K-12
Case study: iTunes for K-12Case study: iTunes for K-12
Case study: iTunes for K-12Giorgio Sironi
 
Case study: Innovascuola
Case study: InnovascuolaCase study: Innovascuola
Case study: InnovascuolaGiorgio Sironi
 
Case study: e-Learning for Kids
Case study: e-Learning for KidsCase study: e-Learning for Kids
Case study: e-Learning for KidsGiorgio Sironi
 
Case study: Chocolat 3B
Case study: Chocolat 3BCase study: Chocolat 3B
Case study: Chocolat 3BGiorgio Sironi
 
Pursuing practices of Domain-Driven Design in PHP
Pursuing practices of Domain-Driven Design in PHPPursuing practices of Domain-Driven Design in PHP
Pursuing practices of Domain-Driven Design in PHPGiorgio Sironi
 
Pursuing Domain-Driven Design practices in PHP
Pursuing Domain-Driven Design practices in PHPPursuing Domain-Driven Design practices in PHP
Pursuing Domain-Driven Design practices in PHPGiorgio Sironi
 
Blind detection of image manipulation @ PoliMi
Blind detection of image manipulation @ PoliMiBlind detection of image manipulation @ PoliMi
Blind detection of image manipulation @ PoliMiGiorgio Sironi
 
Cohesion and coupling metrics for workflow process design
Cohesion and coupling metrics for workflow process designCohesion and coupling metrics for workflow process design
Cohesion and coupling metrics for workflow process designGiorgio Sironi
 
Chansonnier: web application for multimedia search on song videos
Chansonnier: web application for multimedia search on song videosChansonnier: web application for multimedia search on song videos
Chansonnier: web application for multimedia search on song videosGiorgio Sironi
 

More from Giorgio Sironi (20)

Case study: Khan Academy
Case study: Khan AcademyCase study: Khan Academy
Case study: Khan Academy
 
Case study: iTunes for K-12
Case study: iTunes for K-12Case study: iTunes for K-12
Case study: iTunes for K-12
 
Case study: Insegnalo
Case study: InsegnaloCase study: Insegnalo
Case study: Insegnalo
 
Case study: Innovascuola
Case study: InnovascuolaCase study: Innovascuola
Case study: Innovascuola
 
Case study: e-Learning for Kids
Case study: e-Learning for KidsCase study: e-Learning for Kids
Case study: e-Learning for Kids
 
Case study: Chocolat 3B
Case study: Chocolat 3BCase study: Chocolat 3B
Case study: Chocolat 3B
 
Khan Academy
Khan AcademyKhan Academy
Khan Academy
 
Itunes K-12
Itunes K-12Itunes K-12
Itunes K-12
 
Insegnalo
InsegnaloInsegnalo
Insegnalo
 
Innovascuola
InnovascuolaInnovascuola
Innovascuola
 
e-Learning for kids
e-Learning for kidse-Learning for kids
e-Learning for kids
 
Chocolat 3B
Chocolat 3BChocolat 3B
Chocolat 3B
 
Pursuing practices of Domain-Driven Design in PHP
Pursuing practices of Domain-Driven Design in PHPPursuing practices of Domain-Driven Design in PHP
Pursuing practices of Domain-Driven Design in PHP
 
Testing in isolation
Testing in isolationTesting in isolation
Testing in isolation
 
Pursuing Domain-Driven Design practices in PHP
Pursuing Domain-Driven Design practices in PHPPursuing Domain-Driven Design practices in PHP
Pursuing Domain-Driven Design practices in PHP
 
An year of Pomodoros
An year of PomodorosAn year of Pomodoros
An year of Pomodoros
 
Blind detection of image manipulation @ PoliMi
Blind detection of image manipulation @ PoliMiBlind detection of image manipulation @ PoliMi
Blind detection of image manipulation @ PoliMi
 
CouchDB @ PoliMi
CouchDB @ PoliMiCouchDB @ PoliMi
CouchDB @ PoliMi
 
Cohesion and coupling metrics for workflow process design
Cohesion and coupling metrics for workflow process designCohesion and coupling metrics for workflow process design
Cohesion and coupling metrics for workflow process design
 
Chansonnier: web application for multimedia search on song videos
Chansonnier: web application for multimedia search on song videosChansonnier: web application for multimedia search on song videos
Chansonnier: web application for multimedia search on song videos
 

Recently uploaded

Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 

Recently uploaded (20)

Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 

Php day2010

  • 1. Architettura e testabilità (Architecture and testability) Listen to your tests on steroids Giorgio Sironi
  • 2. Who am I ● PHP freelancer from 2005 ● Writer for php|architect, DZone ● Perito informatico, undergraduate in Engineering at Politecnico di Milano
  • 3. This talk ● Maintainability, and why testing ● Various techniques to favor ease of testing AND maintainability ● Slides in English (test d'unità, Legge di Demetra...)
  • 4. Other talks ● Dependency Injection ● Testare l'ignoto ● Agile software lifecycle
  • 5. What is maintainability? ● Being ready to change! …but not too much ● Taking the first bullet
  • 6. Favored by maintainability ● New requirements ● Evolving requirements ● Iterative development ● Long-term maintenance
  • 7. Kinds of tests ● Unit tests ● Integration tests ● Acceptance (end-to-end) tests and functional tests
  • 8. Maintainability (1 of 2) SOLID principles (not all of them) ● Single responsibility ● Open/closed ● Dependency Inversion
  • 9. Maintainability (2 of 2) Loose coupling High cohesion Information hiding Orthogonality ...needed from day 1, like readability and testability
  • 10. Good but... Good buzzwords, but how do I apply that in practice?
  • 11. Testing first ● Testing first → Testable code ● Testable code → Maintainable code
  • 12. Problems with tests ● A test is slow? ● A test is brittle? ● A test is difficult to write?
  • 13. Solution to problems with tests Change the design to ease testing (listen to your tests)
  • 14. Test must change too ● Good: test suite ● Bad: no test suite ● Worse: unmaintainable test suite
  • 15. Examples of listening to the tests ● Small tests => high cohesion ● Unit tests => loose coupling 4 pillars...
  • 16. 1. Dependency injection ● No new operator outside of Factories ● Easy to change lifecycles and implementations
  • 17. 1. Dependency Injection (without) <?php class Ferrari { private $_engine; public function __construct() { $this->_engine = new Engine(); } }
  • 18. 1. Dependency Injection (with) <?php class Ferrari { private $_engine; public function __construct(Engine $engine) { $this->_engine = $engine; } }
  • 19. 2. Avoid static methods ● Explicit concept ● Orthogonality
  • 20. 2. Avoid static methods (before) <?php class Collection { public function find($key) { Sorter::sort($this); // ..search stuff } }
  • 21. 2. Avoid using static methods (after) <?php class Collection { public function find($key) { $this->_sorter->sort($this); // ..search stuff } }
  • 22. 3. Law of Demeter ● Do not walk the... arrows ● Exceptions: Factories, data structures
  • 23. 3. Law of Demeter (without) <?php class PC { public function powerOn() { $this->_mobo->cpu->cache ->powerOn(); } }
  • 24. 3. Law of Demeter (with) <?php class PC { public function powerOn() { foreach ($this->_powered as $item) { /** @var Powered $item */ $item->powerOn(); } } }
  • 25. 3. Law of Demeter (with) <?php class PC { public function powerOn() { $this->_mobo->powerOn(); } }
  • 26. 4. Singleton vs. Factory ● Singleton is static, impossible to mock ● Global state ● Hidden dependency
  • 27. 4. Singleton vs. Factory <?php class Authenticator { public function login($user, $pass) { Db::select(...); } }
  • 28. 4. Singleton vs. Factory <?php class Authenticator { public function __construct(Db $db) { ... } public function login($user, $pass) { $this->_db->select(...); } }
  • 29. Be honest ● If you need something, inject it (or inject its factory) ● Tell > Ask > Look Recipe for a clear, clean Api
  • 31. References ● Guide: Writing Testable Code (Misko Hevery) ● Growing Object-Oriented Software, Guided by Tests – Freeman, Price