Improving QA on PHP projects - confoo 2011

4,036 views

Published on

Everyone talks about raising the bar on quality of code, but it's always hard to start implementing it when you have no clue where to start. With this talk I'm showing that there are many levels developers can improve themselves by using the right tools.

* Syntax checking with PHPLint (php -l)
* Validating code with PHP_CodeSniffer
* Testing code with PHPUnit
* Debugging code with XDebug
* Documenting code with PHPDocumentator
* Building with Phing
* Packaging with Phar

0 Comments
7 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,036
On SlideShare
0
From Embeds
0
Number of Embeds
41
Actions
Shares
0
Downloads
63
Comments
0
Likes
7
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Improving QA on PHP projects - confoo 2011

    1. 1. Improving QA on PHP projects Confoo 2011, Montreal (Canada)
    2. 2. Michelangelo van Dam• Independent Consultant• Zend Certified Engineer (ZCE)• President of PHPBenelux
    3. 3. What’s the benefit of QA?• early detection of issues• cleaner & consistent code• knowledge about the codebase• increase of confidence
    4. 4. Sebastian Bergmann• QA expert• wrote the tools• speaker and inspirer
    5. 5. Usual Suspects PHP_CodeSniffer
    6. 6. Example Code•- Zend Framework QuickStart app http://framework.zend.com/manual/en/learning.quickstart.intro.html
    7. 7. VirtualHost Settings<VirtualHost *:80> DocumentRoot /srv/www/quickstart/public ServerName quickstart.local ServerAdmin root@localhost <Directory /srv/www/quickstart/public> Options Indexes FollowSymlinks AllowOverride All Order allow,deny Allow from all DirectoryIndex index.php </Directory> Alias /reports /srv/www/quickstart/reports <Directory /srv/www/quickstart/reports> Options Indexes FollowSymlinks AllowOverride All Order allow,deny Allow from all DirectoryIndex index.php index.html </Directory></VirtualHost>
    8. 8. Showtime
    9. 9. Syntax Checking•- PHPLint comes with PHP binary - validates code for syntax errors• Website - http://www.icosaedro.it/phplint/
    10. 10. Demo PHPLint
    11. 11. Code Documentation•- PHPDocumentator creates automated API documentation - based on inline code blocks• Installation - pear install PhpDocumentor• Website - http://www.phpdoc.org
    12. 12. Demo PHPDoc
    13. 13. Output PHPDoc
    14. 14. Coding Standards•- PHP_CodeSniffer sniffs for coding standard violations - ensures code is clean and consistent - using standard and custom coding standards• Installation - pear install PHP_CodeSniffer• Website - http://pear.php.net/package/PHP_CodeSniffer
    15. 15. Demo PHP_CodeSniffer
    16. 16. PHPCPD•- PHP Copy/Paste Detector detects code duplication•- Installation pear channel-discover pear.phpunit.de - pear channel-discover components.ez.no - pear install --alldeps phpunit/phpcpd• Website - http://github.com/sebastianbergmann/phpcpd
    17. 17. Demo PHPCPD
    18. 18. Output
    19. 19. Mess Detection•- PDepend & PHPMD detects code mess•- Installation pear channel-discover pear.pdepend.org - pear install pdepend/PHP_Depend - pear channel-discover pear.phpmd.org - pear install phpmd/PHP_PMD• Websites - http://www.pdepend.org - http://www.phpmd.org
    20. 20. Demo detecting mess
    21. 21. Output codesize
    22. 22. Output unused code
    23. 23. Unit Testing•- PHPUnit tests code on unit level - includes database tests - integrates well with many PHP frameworks• Installation - pear channel-discover pear.phpunit.de - pear install phpunit/PHPUnit• Website - http://www.phpunit.de
    24. 24. See other presentation http://slideshare.net/DragonBe/unit-testing-after-zf-18
    25. 25. Packaging•- Phar PHP Archive (equivalent of Java jar) - compresses and collects like - included in PHP build (as of PHP 5.3.0)• Installation (before PHP 5.3.0) - pecl install phar• Website: - http://php.net/phar
    26. 26. Code example<?phpinclude_once ‘phar://MyApp.phar/path/to/Class.php’;$application = new Class;$application->run();
    27. 27. Usage• libraries• modules• images• plugins• deployment
    28. 28. Automated builds•- Phing automated build tool - like Apache Ant - integrates well with other PHP tools• Installation - pear channel-discover pear.phing.info - pear install phing/phing• Website - http://phing.info
    29. 29. build.xml<?xml version="1.0"?><project name="zfqs" description="Zend Framework QuickStart" default="build" > <target name="version"> <version releasetype="Bugfix" file="build.version" property="version.number"/> </target> <target name="phplint"> <mkdir dir="./reports/phplint" /> <phplint file="./application/models" haltonfailure="false" tofile="./reports/phplint/errors.txt"/> </target> <target name="pdepend"> <mkdir dir="./reports/pdepend" /> <copy file="./build_pdepend.html" tofile="./reports/pdepend/index.html" overwrite="true" /> <exec command="/usr/bin/pdepend --summary-xml=./reports/pdepend/summary.xml --jdepend-chart=./reports/pdepend/jdepend.svg --overview-pyramid=./reports/pdepend/pyramid.svg ./application/models" dir="./" /> </target> <target name="phpmd"> <mkdir dir="./reports/phpmd" /> <exec command="/usr/bin/phpmd ./application/models html codesize --reportfile ./reports/phpmd/codesize.html" dir="./" /> <exec command="/usr/bin/phpmd ./application/models html unusedcode --reportfile ./reports/phpmd/unusedcode.html" dir="./" /> </target> <target name="phpcs"> <mkdir dir="./reports/phpcs" /> <exec command="/usr/bin/phpcs -n --standard=Zend --report=summary ./application/models > ./reports/phpcs/summary.txt" dir="./" /> <exec command="/usr/bin/phpcs -n --standard=Zend --report=source ./application/models > ./reports/phpcs/source.txt" dir="./" /> <exec command="/usr/bin/phpcs -n --standard=Zend --report=checkstyle ./application/models > ./reports/phpcs/checkstyle.xml" dir="./" /> </target> <target name="phpcpd"> <mkdir dir="./reports/phpcpd" /> <exec command="/usr/bin/phpcpd --log-pmd ./reports/phpcpd/pmd-cpd.xml ./application/models" dir="./" /> </target> <target name="phpdoc"> <mkdir dir="./reports/phpdoc" /> <exec command="phpdoc -d ./application/models -q -t ./reports/phpdoc -o HTML:frames:earthli" dir="./" /> </target> <target name="build" depends="version,phplint,pdepend,phpmd,phpcs,phpcpd,phpdoc"> <echo msg="Finishing build process ${version.number}" /> </target></project>
    30. 30. project definition<?xml version="1.0"?><project name="zfqs" description="Zend Framework QuickStart" default="build" >…</project>
    31. 31. target version<target name="version"> <version releasetype="Bugfix" file="build.version" property="version.number"/></target>In file “build.version” we have the version number as the following sequence:MAJOR.MINOR.BUGFIX (starting at 0.0.0)
    32. 32. target phplint<target name="phplint"> <mkdir dir="./reports/phplint" /> <phplint file="./application/models" haltonfailure="false" tofile="./reports/phplint/errors.txt"/></target>
    33. 33. target pdepend<target name="pdepend"> <mkdir dir="./reports/pdepend" /> <copy file="./build_pdepend.html" tofile="./reports/pdepend/index.html" overwrite="true" /> <exec command="/usr/bin/pdepend --summary-xml=./reports/pdepend/summary.xml --jdepend-chart=./reports/pdepend/jdepend.svg --overview-pyramid=./reports/pdepend/pyramid.svg ./application/models" dir="./" /></target>
    34. 34. target phpmd<target name="phpmd"> <mkdir dir="./reports/phpmd" /> <exec command="/usr/bin/phpmd ./application/models html codesize --reportfile ./reports/phpmd/codesize.html" dir="./" /> <exec command="/usr/bin/phpmd ./application/models html unusedcode --reportfile ./reports/phpmd/unusedcode.html" dir="./" /></target>
    35. 35. target phpcs<target name="phpcs"> <mkdir dir="./reports/phpcs" /> <exec command="/usr/bin/phpcs -n --standard=Zend --report=summary ./application/models > ./reports/phpcs/summary.txt" dir="./" /> <exec command="/usr/bin/phpcs -n --standard=Zend --report=source ./application/models > ./reports/phpcs/source.txt" dir="./" /> <exec command="/usr/bin/phpcs -n --standard=Zend --report=checkstyle ./application/models > ./reports/phpcs/checkstyle.xml" dir="./" /></target>
    36. 36. target phpcpd<target name="phpcpd"> <mkdir dir="./reports/phpcpd" /> <exec command="/usr/bin/phpcpd --log-pmd ./reports/phpcpd/pmd-cpd.xml ./application/models" dir="./" /></target>
    37. 37. target phpdoc<target name="phpdoc"> <mkdir dir="./reports/phpdoc" /> <exec command="phpdoc -d ./application/models -q -t ./reports/phpdoc -o HTML:frames:earthli" dir="./" /></target>
    38. 38. target build<target name="build" depends="version,phplint,pdepend,phpmd,phpcs,phpcpd,phpdoc"> <echo msg="Finishing build process ${version.number}" /></target>
    39. 39. Demo building all
    40. 40. Demo building target
    41. 41. Our reports section
    42. 42. Summary PHP offers lots of toolsmore consistent and clean code automated process
    43. 43. Questions• http://www.slideshare.net/DragonBe/improving-qa-on- php-projects-confoo2011• http://twitter.com/DragonBe• http://facebook.com/DragonBe• http://joind.in/2822

    ×