SlideShare a Scribd company logo
1 of 33
Download to read offline
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

Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
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
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Karmanjay Verma
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsYoss Cohen
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfAarwolf Industries LLC
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 

Recently uploaded (20)

Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
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
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platforms
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdf
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 

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