quality in php projects beyond unittests
TRANSCRIPT
![Page 1: Quality In PHP Projects Beyond Unittests](https://reader033.vdocuments.mx/reader033/viewer/2022052507/559339c21a28abed2c8b45de/html5/thumbnails/1.jpg)
Quality in PHP projects beyond Unittests
International PHP Conference 2008October 30th 2008 | Thorsten Rinne
![Page 2: Quality In PHP Projects Beyond Unittests](https://reader033.vdocuments.mx/reader033/viewer/2022052507/559339c21a28abed2c8b45de/html5/thumbnails/2.jpg)
© MAYFLOWER GmbH 2008
2
Quality in PHP projects beyond Unittests
Introduction
❙ Thorsten Rinne
❙ 31 years old
❙ Senior Developer and Team Lead at Mayflower GmbH
❙ Reporting applications
❙ Rating applications
❙ PHP consulting for QA and migration problems
❙ PHP software development since 1999
❙ Founder and main developer of open source FAQ management software phpMyFAQ since 2001
❙ Zend Certified Engineer (PHP 5)
![Page 3: Quality In PHP Projects Beyond Unittests](https://reader033.vdocuments.mx/reader033/viewer/2022052507/559339c21a28abed2c8b45de/html5/thumbnails/3.jpg)
© MAYFLOWER GmbH 2008
3
Quality in PHP projects beyond Unittests
Introduction
❙ Warm up
❙ Quality Criterias
❙ Quality Metrics
❙ Testing
❙ PHP Source Code Quality
❙ Questions and answers
![Page 4: Quality In PHP Projects Beyond Unittests](https://reader033.vdocuments.mx/reader033/viewer/2022052507/559339c21a28abed2c8b45de/html5/thumbnails/4.jpg)
© MAYFLOWER GmbH 2008
4
Quality in PHP projects beyond Unittests
Who are you?
❙ What's your profession?
❙ Software company or agency?
❙ What's your team size?
❙ Who develops using Unittests?
❙ Who uses QA supporting tools?
❙ What's your test coverage?
❙ Even for legacy code? :-)
![Page 5: Quality In PHP Projects Beyond Unittests](https://reader033.vdocuments.mx/reader033/viewer/2022052507/559339c21a28abed2c8b45de/html5/thumbnails/5.jpg)
© MAYFLOWER GmbH 2008
5
Quality in PHP projects beyond Unittests
Quality Criterias
![Page 6: Quality In PHP Projects Beyond Unittests](https://reader033.vdocuments.mx/reader033/viewer/2022052507/559339c21a28abed2c8b45de/html5/thumbnails/6.jpg)
© MAYFLOWER GmbH 2008
6
Quality in PHP projects beyond Unittests
Quality criterias:Understandability
❙ Availability of documentation
❙ Good documentation quality
❙ Complexity of software
❙ Code commenting and formatting
❙ Understandable naming
![Page 7: Quality In PHP Projects Beyond Unittests](https://reader033.vdocuments.mx/reader033/viewer/2022052507/559339c21a28abed2c8b45de/html5/thumbnails/7.jpg)
© MAYFLOWER GmbH 2008
7
Quality in PHP projects beyond Unittests
Quality criterias:Completeness
❙ Everything is already there
❙ Your application is fully implemented
❙ No mockups or temporary solutions left
❙ External interfaces are usable
❙ All needed data is available
![Page 8: Quality In PHP Projects Beyond Unittests](https://reader033.vdocuments.mx/reader033/viewer/2022052507/559339c21a28abed2c8b45de/html5/thumbnails/8.jpg)
© MAYFLOWER GmbH 2008
8
Quality in PHP projects beyond Unittests
Quality criterias:Conciseness
❙ No unneeded, overlong documentation
❙ Especially auto-generated documentation
❙ No unused libraries
❙ No dead code
❙ No duplicate code
❙ No code inside loops that could be outside
![Page 9: Quality In PHP Projects Beyond Unittests](https://reader033.vdocuments.mx/reader033/viewer/2022052507/559339c21a28abed2c8b45de/html5/thumbnails/9.jpg)
© MAYFLOWER GmbH 2008
9
Quality in PHP projects beyond Unittests
Quality criterias:Portability
❙ Easy to configure in new environments
❙ Few OS and webserver dependencies
❙ Few, documented version dependencies
❙ Language version
❙ Database version
❙ External libraries
❙ Able to survice environment updates
![Page 10: Quality In PHP Projects Beyond Unittests](https://reader033.vdocuments.mx/reader033/viewer/2022052507/559339c21a28abed2c8b45de/html5/thumbnails/10.jpg)
© MAYFLOWER GmbH 2008
10
Quality in PHP projects beyond Unittests
Quality criterias:Consistency
❙ Predictability
❙ Directory paths and filenames
❙ Class and method names
❙ Variable and constant names
❙ Documentation style and language
❙ Coding style
![Page 11: Quality In PHP Projects Beyond Unittests](https://reader033.vdocuments.mx/reader033/viewer/2022052507/559339c21a28abed2c8b45de/html5/thumbnails/11.jpg)
© MAYFLOWER GmbH 2008
11
Quality in PHP projects beyond Unittests
Quality criterias:Maintainability
❙ Easy to install and easy to upgrade
❙ Tests and debug logs to help to locate bugs
❙ Few dependencies hiding the bug
❙ No complex dependencies or effects on the platform
❙ Easy to understand and navigate source code
![Page 12: Quality In PHP Projects Beyond Unittests](https://reader033.vdocuments.mx/reader033/viewer/2022052507/559339c21a28abed2c8b45de/html5/thumbnails/12.jpg)
© MAYFLOWER GmbH 2008
12
Quality in PHP projects beyond Unittests
Quality criterias:Testability
❙ Known acceptence criteria
❙ Adequate separation of concerns
❙ Easy to use interfaces for tests
❙ No limiting dependencies
![Page 13: Quality In PHP Projects Beyond Unittests](https://reader033.vdocuments.mx/reader033/viewer/2022052507/559339c21a28abed2c8b45de/html5/thumbnails/13.jpg)
© MAYFLOWER GmbH 2008
13
Quality in PHP projects beyond Unittests
Quality criterias:Reliability
❙ The criteria formerly known as „robustness“
❙ Fault tolerance
❙ Graceful degradation
❙ Exception handling exists
❙ Is method input checked?
![Page 14: Quality In PHP Projects Beyond Unittests](https://reader033.vdocuments.mx/reader033/viewer/2022052507/559339c21a28abed2c8b45de/html5/thumbnails/14.jpg)
© MAYFLOWER GmbH 2008
14
Quality in PHP projects beyond Unittests
Quality criterias:Usability
❙ Learnability: Easyness of first time usage
❙ Efficiency: Overall speed of usage per task
❙ Memorabilty: Time to re-establish usage knowledge after absence
❙ Errors: Frequency of usage errors
❙ Satisfaction: Fun to use the software
![Page 15: Quality In PHP Projects Beyond Unittests](https://reader033.vdocuments.mx/reader033/viewer/2022052507/559339c21a28abed2c8b45de/html5/thumbnails/15.jpg)
© MAYFLOWER GmbH 2008
15
Quality in PHP projects beyond Unittests
Quality Metrics
![Page 16: Quality In PHP Projects Beyond Unittests](https://reader033.vdocuments.mx/reader033/viewer/2022052507/559339c21a28abed2c8b45de/html5/thumbnails/16.jpg)
© MAYFLOWER GmbH 2008
16
Quality in PHP projects beyond Unittests
Quality Metrics:Defect Density Metrics
❙ Code-based metric
❙ Defects per KSSI (1000 shipped source instructions) for product quality
❙ Defects per KCSI (1000 changed source instructions) for development quality
❙ (Hard to measure)
❙ Statistic needed
❙ easier for products
![Page 17: Quality In PHP Projects Beyond Unittests](https://reader033.vdocuments.mx/reader033/viewer/2022052507/559339c21a28abed2c8b45de/html5/thumbnails/17.jpg)
© MAYFLOWER GmbH 2008
17
Quality in PHP projects beyond Unittests
Quality Metrics:Customer Problem Metrics
❙ PUM: Problems per user month
❙ Defects per month / number of installations
❙ Maintainance metric: Number of bugs closed / number of bugs arrived
❙ The customer does not care how big or how complicated the software is :-)
![Page 18: Quality In PHP Projects Beyond Unittests](https://reader033.vdocuments.mx/reader033/viewer/2022052507/559339c21a28abed2c8b45de/html5/thumbnails/18.jpg)
© MAYFLOWER GmbH 2008
18
Quality in PHP projects beyond Unittests
Quality Metrics:Customer Satisfaction Metrics
❙ You only get them by survey
❙ for
❙ Functionality
❙ Usability
❙ Reliability
❙ Performance
❙ Maintainability
❙ Service
❙ Levels: Very Satisfied, Satisfied, Neutral, Dissatisfied, Very Dissatisfied
![Page 19: Quality In PHP Projects Beyond Unittests](https://reader033.vdocuments.mx/reader033/viewer/2022052507/559339c21a28abed2c8b45de/html5/thumbnails/19.jpg)
© MAYFLOWER GmbH 2008
19
Quality in PHP projects beyond Unittests
Quality Metrics:When are bugs detected?
❙ Number of pre-release bugs found while testing
❙ Number of post-release bugs
❙ found by customer
❙ found by testing
![Page 20: Quality In PHP Projects Beyond Unittests](https://reader033.vdocuments.mx/reader033/viewer/2022052507/559339c21a28abed2c8b45de/html5/thumbnails/20.jpg)
© MAYFLOWER GmbH 2008
20
Quality in PHP projects beyond Unittests
Quality Metrics:How are defects fixed?
❙ Average Time to fix a bug
❙ Average Time for bugfix release
❙ that‘s the time relevant for the customer
❙ Average engineering hours / fixed defect
![Page 21: Quality In PHP Projects Beyond Unittests](https://reader033.vdocuments.mx/reader033/viewer/2022052507/559339c21a28abed2c8b45de/html5/thumbnails/21.jpg)
© MAYFLOWER GmbH 2008
21
Quality in PHP projects beyond Unittests
Quality Metrics:Defect Impact
❙ was the defect visible to the user?
❙ has a monetary transaction been touched?
❙ has sensitive data been touched?
❙ are there security implications?
❙ has there been a marketing/image effect
❙ did data / user work get lost?
![Page 22: Quality In PHP Projects Beyond Unittests](https://reader033.vdocuments.mx/reader033/viewer/2022052507/559339c21a28abed2c8b45de/html5/thumbnails/22.jpg)
© MAYFLOWER GmbH 2008
22
Quality in PHP projects beyond Unittests
Quality Metrics:Testing Efficiency
❙ Found bugs before release / found bugs post release
❙ Found bugs by qa team / found bugs by customer
❙ Number of bugs found by QA Team / time
![Page 23: Quality In PHP Projects Beyond Unittests](https://reader033.vdocuments.mx/reader033/viewer/2022052507/559339c21a28abed2c8b45de/html5/thumbnails/23.jpg)
© MAYFLOWER GmbH 2008
23
Quality in PHP projects beyond Unittests
„We do PHPUnit!“ !== Testing
![Page 24: Quality In PHP Projects Beyond Unittests](https://reader033.vdocuments.mx/reader033/viewer/2022052507/559339c21a28abed2c8b45de/html5/thumbnails/24.jpg)
© MAYFLOWER GmbH 2008
24
Quality in PHP projects beyond Unittests
Unit Testing
❙ For PHP: PHPUnit or SimpleTest
❙ Focussing on testing a single unit of work
❙ solves depencies using mock objects
❙ should not depend on database
❙ perfect and easy to automate
❙ Reason for all refactoring
![Page 25: Quality In PHP Projects Beyond Unittests](https://reader033.vdocuments.mx/reader033/viewer/2022052507/559339c21a28abed2c8b45de/html5/thumbnails/25.jpg)
© MAYFLOWER GmbH 2008
25
Quality in PHP projects beyond Unittests
Acceptence Testing
❙ originally user acceptance testing❙ one of the final testing stages
❙ change to automated black box testing in agile environments
❙ used to test user stories❙ often contractual requirement
![Page 26: Quality In PHP Projects Beyond Unittests](https://reader033.vdocuments.mx/reader033/viewer/2022052507/559339c21a28abed2c8b45de/html5/thumbnails/26.jpg)
© MAYFLOWER GmbH 2008
26
Quality in PHP projects beyond Unittests
SOA / Service Testing
❙ in multi-tier environments every service can have several consumers
❙ black box test for the service api
❙ can easily be automated
❙ a lot of tools for SOAP
![Page 27: Quality In PHP Projects Beyond Unittests](https://reader033.vdocuments.mx/reader033/viewer/2022052507/559339c21a28abed2c8b45de/html5/thumbnails/27.jpg)
© MAYFLOWER GmbH 2008
27
Quality in PHP projects beyond Unittests
Integration Testing
❙ tests the application with all parts
❙ needed for multi-tier applications
❙ tests the interaction paths
❙ intersection with load testing: user simulation
![Page 28: Quality In PHP Projects Beyond Unittests](https://reader033.vdocuments.mx/reader033/viewer/2022052507/559339c21a28abed2c8b45de/html5/thumbnails/28.jpg)
© MAYFLOWER GmbH 2008
28
Quality in PHP projects beyond Unittests
Load Testing
❙ Simulates high load situations
❙ to detect the current platform abilities
❙ to detect resource bottlenecks (Database, CPU, Network)
❙ to detect concurreny bottlenecks (locking jams, caching effects)
❙ Scalability testing: scale up or scale out?
![Page 29: Quality In PHP Projects Beyond Unittests](https://reader033.vdocuments.mx/reader033/viewer/2022052507/559339c21a28abed2c8b45de/html5/thumbnails/29.jpg)
© MAYFLOWER GmbH 2008
29
Quality in PHP projects beyond Unittests
Usability Testing
❙ How does the user work with the application?
❙ Efficiency: time to fulfill a basic task
❙ Accuracy: how many mistakes happened?
❙ Recall: does the user recall the usage after a period of time?
❙ Emotional response: does the user feel lucky, confident or stressed about the task?
![Page 30: Quality In PHP Projects Beyond Unittests](https://reader033.vdocuments.mx/reader033/viewer/2022052507/559339c21a28abed2c8b45de/html5/thumbnails/30.jpg)
© MAYFLOWER GmbH 2008
30
Quality in PHP projects beyond Unittests
Regression Testing
❙ originally: if you find a bug, fix it and write a test
❙ PHP itself does it
❙ now often written by the test team to assure the expected default behavior
❙ modern: automated test generation
![Page 31: Quality In PHP Projects Beyond Unittests](https://reader033.vdocuments.mx/reader033/viewer/2022052507/559339c21a28abed2c8b45de/html5/thumbnails/31.jpg)
© MAYFLOWER GmbH 2008
31
Quality in PHP projects beyond Unittests
Security Testing
❙ Blackbox: Penetration Test done by external auditor just before release
❙ Graybox: using tools like fuzzers and scanners before release or while development
❙ Whitebox: internal or external source code audit, static code analysis while development
![Page 32: Quality In PHP Projects Beyond Unittests](https://reader033.vdocuments.mx/reader033/viewer/2022052507/559339c21a28abed2c8b45de/html5/thumbnails/32.jpg)
© MAYFLOWER GmbH 2008
32
Quality in PHP projects beyond Unittests
A lot more ...
❙ Compability testing for maintainability
❙ Volume testing for bigger amounts of data
❙ Stress testing for degrade and failover processes
❙ Installation testing for maintenance
❙ Recovery testing to check recovery behavior
![Page 33: Quality In PHP Projects Beyond Unittests](https://reader033.vdocuments.mx/reader033/viewer/2022052507/559339c21a28abed2c8b45de/html5/thumbnails/33.jpg)
© MAYFLOWER GmbH 2008
33
Quality in PHP projects beyond Unittests
PHP Source Code Quality
![Page 34: Quality In PHP Projects Beyond Unittests](https://reader033.vdocuments.mx/reader033/viewer/2022052507/559339c21a28abed2c8b45de/html5/thumbnails/34.jpg)
© MAYFLOWER GmbH 2008
34
Quality in PHP projects beyond Unittests
Documentation
❙ We have different forms of documentation:
❙ Inline documentation
❙ API documentation
❙ Developer documentation
❙ Security documentation
❙ Administration documentation
❙ End-user documentation
![Page 35: Quality In PHP Projects Beyond Unittests](https://reader033.vdocuments.mx/reader033/viewer/2022052507/559339c21a28abed2c8b45de/html5/thumbnails/35.jpg)
© MAYFLOWER GmbH 2008
35
Quality in PHP projects beyond Unittests
Coding Style / Formatting
❙ Coding style is defined in the developer documentation
❙ All developers have to write their code formatted in the given coding style
❙ Can be checked by CodeSniffer tools
❙ Coding style should be based on your main used libraries
❙ If you build your application on top of the Zend Framework, use the ZF coding style
❙ With IDEs like Eclipse you can format old code autpmatically
![Page 36: Quality In PHP Projects Beyond Unittests](https://reader033.vdocuments.mx/reader033/viewer/2022052507/559339c21a28abed2c8b45de/html5/thumbnails/36.jpg)
© MAYFLOWER GmbH 2008
36
Quality in PHP projects beyond Unittests
Naming Conventions
❙ Naming conventions are very important❙ No\namespaces\before\PHP\5.3❙ Easier for __autoload()
❙ Examples❙ Class names:
❙ class HTML_Template_ITX2❙ Directory: include/PEAR2/HTML/Template/ITX2.php
❙ Function names in camel caps:❙ public function blockExists($blockname)
![Page 37: Quality In PHP Projects Beyond Unittests](https://reader033.vdocuments.mx/reader033/viewer/2022052507/559339c21a28abed2c8b45de/html5/thumbnails/37.jpg)
© MAYFLOWER GmbH 2008
37
Quality in PHP projects beyond Unittests
Code Complexity
❙ Complexity costs time and money if you don‘t need it
❙ KISS principle: Keep it simple and stupid
❙ Complexity checks by CodeSniffer metrics
❙ Important for good code coverage and unittests
❙ Examples
❙ Too high number of linearly independent paths through a program's source code
❙ Too long class and method names
❙ Too many properties
❙ Too many parameters
❙ Too many methods inside a class
![Page 38: Quality In PHP Projects Beyond Unittests](https://reader033.vdocuments.mx/reader033/viewer/2022052507/559339c21a28abed2c8b45de/html5/thumbnails/38.jpg)
© MAYFLOWER GmbH 2008
38
Quality in PHP projects beyond Unittests
Anti Patterns
❙ An antipattern is a design pattern that appears obvious but is ineffective or far from optimal in practice
❙ Examples
❙ Unnecessary abstraction
❙ God objects
❙ Spaghetti code
❙ Too short or too long variable names
![Page 39: Quality In PHP Projects Beyond Unittests](https://reader033.vdocuments.mx/reader033/viewer/2022052507/559339c21a28abed2c8b45de/html5/thumbnails/39.jpg)
© MAYFLOWER GmbH 2008
39
Quality in PHP projects beyond Unittests
Anti Pattern Examples
❙ if(<EXPR>) {<empty>}❙ if(<EXPR>) {<EXPR>} else {<empty>}❙ try(<EXPR>) {<empty>}❙ try(<EXPR>) {<EXPR>} catch(Exception $e) {<empty>}
❙ define('SOME_NAME', $var)❙ include[_once]|require[_once]|readfile|virtual|file_get_contents|fopen|file|mysql_query($_GET|$_POST|$_REQUEST)
![Page 40: Quality In PHP Projects Beyond Unittests](https://reader033.vdocuments.mx/reader033/viewer/2022052507/559339c21a28abed2c8b45de/html5/thumbnails/40.jpg)
© MAYFLOWER GmbH 2008
40
Quality in PHP projects beyond Unittests
Questions?
![Page 41: Quality In PHP Projects Beyond Unittests](https://reader033.vdocuments.mx/reader033/viewer/2022052507/559339c21a28abed2c8b45de/html5/thumbnails/41.jpg)
Thank you very much!
Thorsten RinneMayflower GmbH
Mannhardtstr. 6 80538 München+49 (89) 24 20 54 - [email protected]