The State of PHP QA Tools

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    1 Favorite & 1 Group

    The State of PHP QA Tools - Presentation Transcript

    1. State of PHP QA Tools Sebastian Bergmann June 25th 2009
    2. Who I Am  Sebastian Bergmann  Involved in the PHP project since 2000  Creator of PHPUnit  Co-Founder and Principal Consultant with thePHP.cc  Developer with eZ Systems
    3. When things go wrong ...
    4. Why did I not test this?
    5.  Does my code work?  Be confident in your code!  Do not be afraid of changing your code!
    6. Does my code work? Classic Approach  Write a test program  Run the test program  Manually verify the output  Delete the test program
    7. Does my code work? Agile Approach Write a unit test  Automatic evaluation of the test result  Instant feedback  Simple test environment  Allows for the earliest possible testing of a code unit  Executable specification  Is not deleted but kept as regression test
    8. Unit Tests improve the confidence in your code as they detect problems as early as possible
    9. Show Me The Code!
    10. How do we measure Software Quality?
    11. Software Metrics  A software metric is a measure of some property of a piece of software or its specifications.  „You cannot control what you cannot measure.“ (Tom DeMarco)
    12. Software Metrics Code Coverage  Which statements, branches, and paths are executed when the tests run?  Statement Coverage  Branch Coverage  Path Coverage  100% Code Coverage is a required, but not a sufficient criteria for test completeness
    13. Software Metrics Lines of Code  Text-based metric for code size  Various definitions  Lines of Code (LOC)  Comment Lines of Code (CLOC)  Non-Comment Lines of Code (NCLOC)  Executable Lines of Code (ELOC)  Ratios can be interesting  CLOC / (E)LOC
    14. Software Metrics Lines of Code sb@thinkpad ~ % pear install phpunit/phploc downloading phploc-1.0.0.tgz ... Starting to download phploc-1.0.0.tgz (5,834 bytes) .....done: 5,834 bytes install ok: channel://pear.phpunit.de/phploc-1.0.0 sb@thinkpad ~ % phploc /usr/local/src/ezcomponents/trunk/Workflow phploc 1.0.0 by Sebastian Bergmann. Directories: 13 Files: 102 Lines of Code (LOC): 14066 Executable Lines of Code (ELOC): 5710 Comment Lines of Code (CLOC): 5228 Non-Comment Lines of Code (NCLOC): 8838 Interfaces: 7 Classes: 90 Functions/Methods: 566
    15. Software Metrics Code Duplication  Two sequences of code are duplicate when they are  textually identical  token for token identical  functionally identical  Problems  Duplicate code contradicts code reuse  Co-Evolution of clones hinders maintenance
    16. Software Metrics Code Duplication sb@thinkpad ~ % pear install phpunit/phpcpd downloading phpcpd-1.1.0.tgz ... Starting to download phpcpd-1.1.0.tgz (8,226 bytes) .....done: 8,226 bytes install ok: channel://pear.phpunit.de/phpcpd-1.1.0 sb@thinkpad ~ % phpcpd /usr/local/src/phpunit/trunk/PHPUnit phpcpd 1.1.0 by Sebastian Bergmann. Found 4 exact clones with 131 duplicated lines in 7 files: - Extensions/Database/DataSet/AbstractTable.php:156-190 Extensions/Database/DataSet/ReplacementTable.php:172-206 - Samples/BankAccountDB/BankAccountDBTest.php:84-128 Samples/BankAccountDB/BankAccountDBTestMySQL.php:84-128 - Tests/Extensions/Database/DataSet/XmlDataSetsTest.php:71-98 Tests/Extensions/Database/DataSet/YamlDataSetTest.php:70-97 - Tests/Extensions/Database/DataSet/XmlDataSetsTest.php:71-97 Tests/Extensions/Database/DataSet/CsvDataSetTest.php:70-96 0.21% duplicated lines out of 61720 total lines of code.
    17. Software Metrics Cyclomatic Complexity  Measures the complexity of a code unit  Originally defined in graph theory ccn(G) = Edges - Vertices + 2  Equivalent: Counting the branching points if, for, foreach, while, case, catch, &&, ||, ternary operator (?:)  Interpretation  Higher complexity leads to more errors  Higher complexity makes testing harder
    18. Software Metrics Cyclomatic Complexity <?php 1 function isLeapYear($year) { $result = false; 2 if ($year % 4 != 0) { $result = false; } 3 if ($year % 100 != 0) { $result = true; } 4 if ($year % 400 == 0) { $result = true; } return $result; }
    19. Software Metrics pdepend  Static Analysis of PHP Code  Software Metrics  Software Visualization  Helps to identify parts of an application that should be refactored sb@thinkpad ~ % pear channel-discover pear.pdepend.org Adding Channel "pear.pdepend.org" succeeded Discovery of channel "pear.pdepend.org" succeeded sb@thinkpad ~ % pear install pdepend/PHP_Depend downloading PHP_Depend-0.9.4.tgz ... Starting to download PHP_Depend-0.9.4.tgz (161,553 bytes) ..................................done: 161,553 bytes install ok: channel://pear.pdepend.org/PHP_Depend-0.9.4
    20. Software Metrics phpmd  Static Analysis of PHP Code  Based on PHP_Depend  Reports violations of rules that operate on raw software metrics data
    21. Software Metrics phpcs  Static Analysis of PHP Code  Based on ext/tokenizer  ”Sniffs”  Coding Standard  Software Metrics  Bug Patterns  Performance Patterns  ...
    22. QA Tools for PHP  phpunit → JUnit XML and Clover XML  phpcs → Checkstyle XML  pdepend → JDepend XML  phpmd → PMD XML  phpcpd → PMD-CPD XML
    23. The End Thank you for your interest! These slides will be posted on http://www.slideshare.net/sebastian_bergmann
    24. License   This presentation material is published under the Attribution-Share Alike 3.0 Unported license.   You are free: ✔ to Share – to copy, distribute and transmit the work. ✔ to Remix – to adapt the work.   Under the following conditions: ● Attribution. You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work). ● Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under the same, similar or a compatible license.   For any reuse or distribution, you must make clear to others the license terms of this work.   Any of the above conditions can be waived if you get permission from the copyright holder.   Nothing in this license impairs or restricts the author's moral rights.

    + Sebastian BergmannSebastian Bergmann, 4 months ago

    custom

    914 views, 1 favs, 0 embeds more stats

    Short summary of PHP quality assurance tools presen more

    More info about this document

    CC Attribution-ShareAlike LicenseCC Attribution-ShareAlike License

    Go to text version

    • Total Views 914
      • 914 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 1
    • Downloads 23
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories

    Tags

    Groups / Events