KEMBAR78
Continuous Integration In Php | PDF
Continuous Integration in PHP
    Why, what and how?
             Wilco Jansen

              October 4th 2009

      Tdose, at the Fontys University of
  Applied Science in Eindhoven, Netherlands
Wilco Jansen


Formerly Involved in Joomla
•   Board member Open Source matters
•   Core team member
•   (first ever) Development coordinator
•   Creator of the Joomla bug-squad
•   Google Summer of Code program
    manager 2006, 2007 and 2008 editions
•   Google Highly Open participation content program manager in
    2008
This presentation is about development tools
Continuous integration in PHP
That help build better software in PHP
Things to think about before you run out of time...
Tools will solve some problems
Why use continuous integration?


●   The earliest possible detection of problems in the software
●   Detection of integration problems, no last minute hiatus
    before releases
●   Early warning of broken/incompatible code
●   Early warning of conflicting changes
●   Immediate unit testing of all changes
●   Constant availability of a “current” build for testing, demo
    or release purposes
●   The immediate impact of checking in incomplete or broken
    code acts as an incentive to developers to learn to work
    more incrementally with shorter feedback cycles
Why use continuous integration?
The classic approach
The classic approach


●   Write a test program (or be the tester)
●   Run the test program (or perform the test
    yourself)
●   Manually verify the output
●   Delete the test program
A fundamental shift
Continuous integration emerged from Extreme
                programming
Question you would like to answer...
Does my code work?

                   And
Does it still work after I committed new code?
Agile approach
Write a unit test!




●   Executable specification
●   Automatic evaluation
●   A simple test environment
●   Instant feedback
●   Used as regression test
Detect problems in the earliest possible stage
●   Defacto standard for unit testing of PHP
    applications
●   Member of the xUnit family
●   Inspired by tools like Junit, TestNG, Junitour,
    JExample etc.
●   Latest stable version 3.4.0 (released 16
    September 2009)
Things to keep in mind...
Unit tests should run in less than 1 ms
Software testing categories


●   Small – Unit tests
    ●   Check conditional logic in the code
    ●   No debugger required
    ●   Runs in less than 1 ms
●   Small – Functional tests
    ●   Check whether the interface between classes abide
        by their contacts
Does PHP Unit only run tests?
Other things PHPUnit can do



●   Skeleton generation
●   Integration of Selennium
PHP Unit and code coverage analyses
PHP Unit and code coverage analyses


●   Helps you with analyzing which statements,
    branches and paths are executed within the
    test run:
    ●   Statement coverage
    ●   Branch coverage
    ●   Path coverage
●   100% code coverage is preferred, but does not
    say anything about the test completeness!
Coding standards...
PHP Code Sniffer (phpcs)
PHP Code Sniffer “Sniffs”...


●   PHP
●   Javascript
●   CSS
To detect violations of defined coding standards
with as main goal to ensure code remains clean
and consistent.
Following coding standards are default available:
MySource, PHPCS, Zend, PEAR and Squiz
An example run
Other available tools


 ●   PHP copy/paste detector
 ●   PHP Depend – software metric tool
 ●   PHP Loc – Lines of code analyses
 ●   PHP PMD – Project Mess Detector




Note: only copy/paste detection will be part of this presentation
Copy/paste detection
Code duplication (phpcd)


●   Code is marked duplicate when two sequences
    of code are:
    ●   Textually identical
    ●   Token for token identical
    ●   Functionally identical
●   Problems
    ●   Duplication of code contradicts code reuse
    ●   Co-evolution of clones hinders maintenance
Example run
How it all can be put together?
Pick your continuous build environment
General mode of operation


●   Developer commits code
●   Commit triggers a build (initiated by versioning
    system, or by polling the version system)
●   Build script is run
●   Output is processed, notification send
Cruisecontrol and PHPUndercontrol
Ant is used to process the build
Remember...
A fool with a tool is still a fool!
One of the hardest things to express about
       continuous integration is that makes a
  fundamental shift to the whole development
pattern, one that isn't easy to see if you've never
worked in an environment that practices it. In fact
 most people do see this atmosphere if they are
 working solo - because then they only integrate
     with themselves. For many people team
 development just comes with certain problems
     that are part of the territory. Continuous
    integration reduces these problems, in
   exchange for a certain amount of discipline.
The end...


Acknowledgement                              Links
●   Part of this presentation was inspired    ●   PHPUnit - http://www.phpunit.de
    by “The State of QA Tools for PHP”        ●   PHP Code sniffer -
    from Sabastian Bergmann
                                                  http://pear.php.net/package/PHP_CodeSniffer/
About me and this presentation                ●   PHP copy/paste detector -
●   Personal blog can be found on                 http://github.com/sebastianbergmann/phpcpd/
    http://www.jfoobar.org                    ●   Cruisecontrol -
●   Slides will be uploaded to                    http://cruisecontrol.sourceforge.net/
    http://slideshare.net/willebil            ●   PHP Under control - http://phpundercontrol.org/
●   Follow me on twitter:                     ●   Bamboo -
    http://twitter.com/willebil
                                                  http://www.atlassian.com/software/bamboo/
                                              ●   PHP lines of code -
                                                  http://github.com/sebastianbergmann/phploc

Continuous Integration In Php

  • 1.
    Continuous Integration inPHP Why, what and how? Wilco Jansen October 4th 2009 Tdose, at the Fontys University of Applied Science in Eindhoven, Netherlands
  • 2.
    Wilco Jansen Formerly Involvedin Joomla • Board member Open Source matters • Core team member • (first ever) Development coordinator • Creator of the Joomla bug-squad • Google Summer of Code program manager 2006, 2007 and 2008 editions • Google Highly Open participation content program manager in 2008
  • 3.
    This presentation isabout development tools
  • 4.
  • 5.
    That help buildbetter software in PHP
  • 6.
    Things to thinkabout before you run out of time...
  • 7.
    Tools will solvesome problems
  • 8.
    Why use continuousintegration? ● The earliest possible detection of problems in the software ● Detection of integration problems, no last minute hiatus before releases ● Early warning of broken/incompatible code ● Early warning of conflicting changes ● Immediate unit testing of all changes ● Constant availability of a “current” build for testing, demo or release purposes ● The immediate impact of checking in incomplete or broken code acts as an incentive to developers to learn to work more incrementally with shorter feedback cycles
  • 9.
    Why use continuousintegration?
  • 10.
  • 11.
    The classic approach ● Write a test program (or be the tester) ● Run the test program (or perform the test yourself) ● Manually verify the output ● Delete the test program
  • 12.
  • 13.
    Continuous integration emergedfrom Extreme programming
  • 14.
    Question you wouldlike to answer...
  • 15.
    Does my codework? And Does it still work after I committed new code?
  • 16.
  • 17.
    Write a unittest! ● Executable specification ● Automatic evaluation ● A simple test environment ● Instant feedback ● Used as regression test
  • 18.
    Detect problems inthe earliest possible stage
  • 20.
    Defacto standard for unit testing of PHP applications ● Member of the xUnit family ● Inspired by tools like Junit, TestNG, Junitour, JExample etc. ● Latest stable version 3.4.0 (released 16 September 2009)
  • 21.
    Things to keepin mind...
  • 22.
    Unit tests shouldrun in less than 1 ms
  • 23.
    Software testing categories ● Small – Unit tests ● Check conditional logic in the code ● No debugger required ● Runs in less than 1 ms ● Small – Functional tests ● Check whether the interface between classes abide by their contacts
  • 24.
    Does PHP Unitonly run tests?
  • 25.
    Other things PHPUnitcan do ● Skeleton generation ● Integration of Selennium
  • 26.
    PHP Unit andcode coverage analyses
  • 27.
    PHP Unit andcode coverage analyses ● Helps you with analyzing which statements, branches and paths are executed within the test run: ● Statement coverage ● Branch coverage ● Path coverage ● 100% code coverage is preferred, but does not say anything about the test completeness!
  • 28.
  • 29.
  • 30.
    PHP Code Sniffer“Sniffs”... ● PHP ● Javascript ● CSS To detect violations of defined coding standards with as main goal to ensure code remains clean and consistent. Following coding standards are default available: MySource, PHPCS, Zend, PEAR and Squiz
  • 31.
  • 32.
    Other available tools ● PHP copy/paste detector ● PHP Depend – software metric tool ● PHP Loc – Lines of code analyses ● PHP PMD – Project Mess Detector Note: only copy/paste detection will be part of this presentation
  • 33.
  • 34.
    Code duplication (phpcd) ● Code is marked duplicate when two sequences of code are: ● Textually identical ● Token for token identical ● Functionally identical ● Problems ● Duplication of code contradicts code reuse ● Co-evolution of clones hinders maintenance
  • 35.
  • 36.
    How it allcan be put together?
  • 37.
    Pick your continuousbuild environment
  • 38.
    General mode ofoperation ● Developer commits code ● Commit triggers a build (initiated by versioning system, or by polling the version system) ● Build script is run ● Output is processed, notification send
  • 39.
  • 41.
    Ant is usedto process the build
  • 42.
  • 43.
    A fool witha tool is still a fool!
  • 44.
    One of thehardest things to express about continuous integration is that makes a fundamental shift to the whole development pattern, one that isn't easy to see if you've never worked in an environment that practices it. In fact most people do see this atmosphere if they are working solo - because then they only integrate with themselves. For many people team development just comes with certain problems that are part of the territory. Continuous integration reduces these problems, in exchange for a certain amount of discipline.
  • 46.
    The end... Acknowledgement Links ● Part of this presentation was inspired ● PHPUnit - http://www.phpunit.de by “The State of QA Tools for PHP” ● PHP Code sniffer - from Sabastian Bergmann http://pear.php.net/package/PHP_CodeSniffer/ About me and this presentation ● PHP copy/paste detector - ● Personal blog can be found on http://github.com/sebastianbergmann/phpcpd/ http://www.jfoobar.org ● Cruisecontrol - ● Slides will be uploaded to http://cruisecontrol.sourceforge.net/ http://slideshare.net/willebil ● PHP Under control - http://phpundercontrol.org/ ● Follow me on twitter: ● Bamboo - http://twitter.com/willebil http://www.atlassian.com/software/bamboo/ ● PHP lines of code - http://github.com/sebastianbergmann/phploc