Upgrade to Pro — share decks privately, control downloads, hide ads and more …

All About Test

All About Test

Inspired by Bulat Shakirzyanov "Clean Code" - Internal Sharing
If you interesting, please check the original slide :p
http://www.slideshare.net/avalanche123/clean-code-5609451

Shih-Yung Lee

March 11, 2012
Tweet

More Decks by Shih-Yung Lee

Other Decks in Technology

Transcript

  1. Why Testing? • Debugging is a time consuming process •

    You can see the class in action, which lets you easily understand its intent and proper use • Real measure of project health and code quality •When new comes, how about old one?
  2. Who would do this... (Laugh) When you go to buy

    something... Hey, take the wallet from my pocket
  3. Dependency Injection Why: •Testable Code •No hidden dependencies = Better

    API = Maintainability •All common initialization logic can be extracted Law of Demeter http://terryyin.blogspot.com/2009/01/law-of-demeter.html
  4. Mock Objects By mocking out external dependencies, we can achieve

    faster and more granular tests. Test Double: http://www.phpunit.de/manual/3. 5/en/test-doubles.html
  5. Functions must becomes methods! <?php $fp = fopen('/tmp/file.txt', 'w+'); fwrite($fp,

    'content'); <?php $file = new File('/tmp/file.txt', 'w+'); $file->write('content');
  6. Test Driven Development Red • write a failing test case,

    use mock objects to represent classes that are not implemented Green • when the test makes sense and the intent is clear, write method bodies Refactor • now that your tests are green, see what needs to be extracted (create dependencies, remove duplication)
  7. One for All, All for One • Checkstyle (for processing

    PHP_CodeSniffer logfiles in Checkstyle format) ◦ It is an essential development tool that ensures your code remains clean and consistent. • Clover (for processing PHPUnit code coverage xml output)
  8. One for All, All for One • DRY (for processing

    phpcpd logfiles in PMD-CPD format) ◦ provide an alternative to them when you just need to get a quick overview of duplicated code in a project • HTML Publisher (for publishing the PHPUnit code coverage report, for instance)
  9. One for All, All for One • JDepend (for processing

    PHP_Depend logfiles in JDepend format) • Plot (for processing phploc CSV output) ◦ phploc is a tool for quickly measuring the size of a PHP project. • PHPDocumentor ◦ A standard auto-documentation tool
  10. One for All, All for One • PMD (for processing

    PHPMD logfiles in PMD format) It takes a given PHP source code base and look for several potential problems within that source. • Violations (for processing various logfiles) • xUnit (for processing PHPUnit logfiles in JUnit format)