Using HipHop for Static Analysis

Sebastian Bergmann » 27 July 2010 » in Articles » 0 Comments

HipHop for PHP, the source code transformer that turns PHP code into C++ code that can then be compiled with g++, can also be used for static code analysis to find problems in PHP source code.

sb@vmware Money % hphp -t analyze --input-dir .
running hphp...
creating temporary directory /tmp/hphp_Zz7AXg ...
parsing inputs...
parsing inputs took 0'00" (20 ms) wall time
inferring types...
inferring types took 0'00" (10 ms) wall time
saving code errors, dependency graph and stats...
all files saved in /tmp/hphp_Zz7AXg ...
running hphp took 0'00" (208 ms) wall time

The script below takes a CodeErrors.js file (which is generated by hphp and in the example above is saved to /tmp/hphp_Zz7AXg) as its input and print an XML document in Checkstyle's format (the same XML format that is also used by PHP_CodeSniffer, for instance). This XML logfile can then be used with Hudson, for instance, in a continuous integration context.

Defined tags for this entry: , ,

GTAC 2010

Sebastian Bergmann » 23 July 2010 » in Presentations » 1 Comment

I have been invited to attend the 5th Annual Google Test Automation Conference, better known as GTAC, in Hyderabad, India in October. I am very much looking forward to discuss cutting edge challenges in test automation and evaluate potential solutions, especially with this year's focus on testability.

Another thing I like about this year's GTAC is that the participants are responsible for selecting the presentations for the conference. Here is my submission:

Challenges in Unit Testing PHP Applications

According to TIOBE, PHP is the most popular programming language after C/C++ and Java. The language has made strong inroads into large-scale, business-critical Web systems. In the six years since the release of PHP 5 -- which not only kickstarted the development of PHP-based frameworks for Web development but also the development of tools for dynamic and static testing techniques -- the PHP community as a whole has developed an increasing interest in developing software that delivers the best possible quality.

When PHP developers start to write unit tests they rarely find themselves without any constraints that are imposed by prior work of less than optimal quality. It is a well-known fact that writing unit tests for legacy code is hard. In the case of PHP it can be even harder: the legacy code has not only been written without testability in mind, but it may have been written for earlier versions of PHP that encouraged practices that make the code next to impossible to unit test.

PHPUnit, the de-facto standard framework for unit-testing PHP code, has some unique features not found in other xUnit test frameworks that allow the testing of untestable code. While developers should not use these features (as they are not required when writing tests for testable code), these features ease the pain of writing tests for legacy code and thus help developers get started with unit testing before they refactor the code for testability.

This session, presented by the creator of PHPUnit, highlights the challenges developers are facing when unit testing legacy PHP code. Some of these challenges will be familiar to developers that use other programming languages such as Java but they will see a new perspective on the problem and different approaches to solve it.

Although I am hoping, of course, that my submission will be accepted by my peers, I know that GTAC will be valuable for me even if I do not get to present: the "hallway track" of GTAC 2008 was amazing.

Defined tags for this entry: ,

PHPUnit 3.5: Refactoring to Components

Sebastian Bergmann » 23 July 2010 » in Articles » 0 Comments

When you look at the list of changes for PHPUnit 3.5, you will see that many of them deal with refactoring to components. Here is an overview of these new components:

  • PHP_CodeCoverage

    The collection, processing, and rendering of code coverage information has been factored out into a separate component. A bit more information can be found here.

  • PHPUnit_MockObject

    The functionality to automatically generate an object that can act as a test double for a specified original class has been factored out into a separate component. Do not worry, getMock() and related methods will work just as they did in previous versions of PHPUnit. The refactoring, however, makes the usage of other mock object libraries (such as Mockery or Phake, for instance) easier.

  • DbUnit

    The database testing functionality that is provided by the DbUnit extension and the respective DatabaseTestCase class has been moved to a separate component. Michael Lively Jr, the author of DbUnit, is now able to make releases of the database testing extension on a release schedule that is separate from PHPUnit itself, meaning that I will be even less involved in its development than I have before.

  • PHPUnit_Selenium

    SeleniumTestCase, the Selenium RC integration for PHPUnit, has been moved to a separate component to allow a release cycle separate from PHPUnit itself.

  • File_Iterator, PHP_Timer, Text_Template

    Utility methods to collect files and report resource usage as well as a simple templating mechanism have been moved to separate components so that they can be reused by other tools such as phpcb, phpcs, phpcpd, and pdepend.

Defined tags for this entry:

PHPUnit 3.5 Beta 1

Sebastian Bergmann » 08 June 2010 » in Announcements » 4 Comments

To celebrate the 15th birthday of PHP, I have released PHPUnit 3.5 Beta 1 today. The refactoring towards components is a "new feature" that is already visible upon installation:

sb@vmware ~ % pear install phpunit/PHPUnit-beta
phpunit/PHPUnit can optionally use PHP extension "dbus"
downloading PHPUnit-3.5.0beta1.tgz ...
Starting to download PHPUnit-3.5.0beta1.tgz (105,588 bytes)
........................done: 105,588 bytes
downloading DbUnit-1.0.0beta1.tgz ...
Starting to download DbUnit-1.0.0beta1.tgz (38,209 bytes)
...done: 38,209 bytes
downloading File_Iterator-1.2.1.tgz ...
Starting to download File_Iterator-1.2.1.tgz (3,225 bytes)
...done: 3,225 bytes
downloading Text_Template-1.0.0.tgz ...
Starting to download Text_Template-1.0.0.tgz (2,493 bytes)
...done: 2,493 bytes
downloading PHP_CodeCoverage-1.0.0beta1.tgz ...
Starting to download PHP_CodeCoverage-1.0.0beta1.tgz (108,640 bytes)
...done: 108,640 bytes
downloading PHP_Timer-1.0.0.tgz ...
Starting to download PHP_Timer-1.0.0.tgz (2,536 bytes)
...done: 2,536 bytes
downloading PHPUnit_MockObject-1.0.0beta1.tgz ...
Starting to download PHPUnit_MockObject-1.0.0beta1.tgz (15,816 bytes)
...done: 15,816 bytes
downloading PHPUnit_Selenium-1.0.0beta1.tgz ...
Starting to download PHPUnit_Selenium-1.0.0beta1.tgz (15,298 bytes)
...done: 15,298 bytes
downloading PHP_TokenStream-1.0.0beta1.tgz ...
Starting to download PHP_TokenStream-1.0.0beta1.tgz (7,023 bytes)
...done: 7,023 bytes
install ok: channel://pear.phpunit.de/File_Iterator-1.2.1
install ok: channel://pear.phpunit.de/Text_Template-1.0.0
install ok: channel://pear.phpunit.de/PHP_Timer-1.0.0
install ok: channel://pear.phpunit.de/PHP_TokenStream-1.0.0beta1
install ok: channel://pear.phpunit.de/PHP_CodeCoverage-1.0.0beta1
install ok: channel://pear.phpunit.de/PHPUnit-3.5.0beta1
install ok: channel://pear.phpunit.de/DbUnit-1.0.0beta1
install ok: channel://pear.phpunit.de/PHPUnit_MockObject-1.0.0beta1
install ok: channel://pear.phpunit.de/PHPUnit_Selenium-1.0.0beta1

Happy Birthday PHP! And have fun testing (with) PHPUnit 3.5!

Defined tags for this entry: ,

thePHP.cc at IPC:SE 2010

Sebastian Bergmann » 26 May 2010 » in Events » 2 Comments

thePHP.cc - The PHP Consulting Company

thePHP.cc - The PHP Consulting Company will present the following workshops and sessions at this year's International PHP Conference: Spring Edition in Berlin:

Continuous Inspection and Integration of PHP Projects

Sebastian Bergmann, 30.05.2010, 09:15 - 13:00, Room: Salon 4

Continuous Integration with automated code analysis and test execution has seen broad adoption in recent years. The ideas behind this have changed how companies look at Build Management, Release Management, Deployment Automation, and Test Orchestration. This session presents the best practices and available tools that provide an insight into the development progress and code quality.

The Cake is a Lie

Sebastian Bergmann, 31.05.2010, 09:15 - 10:15, Room: Salon 6

Even if you have not played the game "Portal" you might have come across the phrase "The cake is a lie". According to the Urban Dictionary, it roughly translates to "your promised reward is merely a fictitious motivator". Scaffolding, the meta-programming method of building software applications, promises easier development and a faster time-to-market. But the "code generation bliss" can lead to problems later on, for instance with regard to maintainability and scalability. This session takes a sceptical look at frameworks such as CakePHP and Symfony.

Building a PHP Preprocessor with Plain PHP

Arne Blankerts, 31.05.2010, 15:15 - 16:15, Room: Salon 6

Ever wished to have a preprocessor for PHP? Now you can! In this session we will implement a simple yet powerful preprocessor using the streamwrapper technology that works out of the box on any PHP installation. This opens up a whole new world of possibilities like annotation parsing, AOP, or dependency resolution in PHP development - all transparently done in the background.

Continuous Integration and Unit Testing in Agile Environments

Sebastian Bergmann, 01.06.2010, 16:00 - 17:00, Room: Salon 7

As part of the Agile Day, this session will shine a light on the roles that Continuous Integration and Unit Testing play in agile environments.

Diapers: When They Smell, Change Them

Stefan Priebsch, 30.05.2010 - 02.06.2010, Room: $HOME

Stefan Priebsch can not join us this year for the International PHP Conference: Spring Edition in Berlin. Earlier this month he became the proud father of two beautiful twins, Lara and Patrick. We hope that he will be at the International PHP Conference this fall in Mainz.

Arne and I are looking forward to see you in Berlin next week!

Defined tags for this entry: ,