Continuous Integration In Php

46
Continuous Integration in PHP Why, what and how? Wilco Jansen October 4 th 2009 Tdose, at the Fontys University of Applied Science in Eindhoven, Netherlands

description

Presentation given 4th of October on T-Dose event about continuous Integration In Php.

Transcript of Continuous Integration In Php

Page 1: Continuous Integration In Php

Continuous Integration in PHPWhy, what and how?

Wilco Jansen

October 4th 2009

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

Page 2: Continuous Integration In Php

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 programmanager 2006, 2007 and 2008 editions

• Google Highly Open participation content program manager in 2008

Page 3: Continuous Integration In Php

This presentation is about development tools

Page 4: Continuous Integration In Php

Continuous integration in PHP

Page 5: Continuous Integration In Php

That help build better software in PHP

Page 6: Continuous Integration In Php

Things to think about before you run out of time...

Page 7: Continuous Integration In Php

Tools will solve some problems

Page 8: Continuous Integration In Php

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

Page 9: Continuous Integration In Php

Why use continuous integration?

Page 10: Continuous Integration In Php

The classic approach

Page 11: Continuous Integration In Php

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

Page 12: Continuous Integration In Php

A fundamental shift

Page 13: Continuous Integration In Php

Continuous integration emerged from Extreme programming

Page 14: Continuous Integration In Php

Question you would like to answer...

Page 15: Continuous Integration In Php

Does my code work?

And

Does it still work after I committed new code?

Page 16: Continuous Integration In Php

Agile approach

Page 17: Continuous Integration In Php

Write a unit test!

● Executable specification● Automatic evaluation● A simple test environment● Instant feedback● Used as regression test

Page 18: Continuous Integration In Php

Detect problems in the earliest possible stage

Page 19: Continuous Integration In Php
Page 20: Continuous Integration In Php

● 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)

Page 21: Continuous Integration In Php

Things to keep in mind...

Page 22: Continuous Integration In Php

Unit tests should run in less than 1 ms

Page 23: Continuous Integration In Php

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

Page 24: Continuous Integration In Php

Does PHP Unit only run tests?

Page 25: Continuous Integration In Php

Other things PHPUnit can do

● Skeleton generation● Integration of Selennium

Page 26: Continuous Integration In Php

PHP Unit and code coverage analyses

Page 27: Continuous Integration In Php

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!

Page 28: Continuous Integration In Php

Coding standards...

Page 29: Continuous Integration In Php

PHP Code Sniffer (phpcs)

Page 30: Continuous Integration In Php

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

Page 31: Continuous Integration In Php

An example run

Page 32: Continuous Integration In Php

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

Page 33: Continuous Integration In Php

Copy/paste detection

Page 34: Continuous Integration In Php

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

Page 35: Continuous Integration In Php

Example run

Page 36: Continuous Integration In Php

How it all can be put together?

Page 37: Continuous Integration In Php

Pick your continuous build environment

Page 38: Continuous Integration In Php

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

Page 39: Continuous Integration In Php

Cruisecontrol and PHPUndercontrol

Page 40: Continuous Integration In Php
Page 41: Continuous Integration In Php

Ant is used to process the build

Page 42: Continuous Integration In Php

Remember...

Page 43: Continuous Integration In Php

A fool with a tool is still a fool!

Page 44: Continuous Integration In Php

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.

Page 45: Continuous Integration In Php
Page 46: Continuous Integration In Php

The end...

Acknowledgement

● Part of this presentation was inspired by “The State of QA Tools for PHP” from Sabastian Bergmann

About me and this presentation

● Personal blog can be found on http://www.jfoobar.org

● Slides will be uploaded to http://slideshare.net/willebil

● Follow me on twitter: http://twitter.com/willebil

Links

● PHPUnit - http://www.phpunit.de

● PHP Code sniffer - http://pear.php.net/package/PHP_CodeSniffer/

● PHP copy/paste detector - http://github.com/sebastianbergmann/phpcpd/

● Cruisecontrol - http://cruisecontrol.sourceforge.net/

● PHP Under control - http://phpundercontrol.org/

● Bamboo - http://www.atlassian.com/software/bamboo/

● PHP lines of code - http://github.com/sebastianbergmann/phploc