Testing Strategy with the Help of a Static Analyzer

Ondřej Mirtes (09.Jun.2018 at 11:45, 45 min)
Talk at Dutch PHP Conference 2018 (English - US)

Rating: 5 of 5

What if I told you that you don’t need 100% code coverage? Latest advancements in the PHP language and modern coding practices allow static analyzers to find a lot of bugs in our code. You won’t stop writing unit tests, but you will focus your efforts where they count the most, like business logic.

Compiled languages need to know about the type of every variable, return type of every method etc. before the program runs. This is why the compiler needs to make sure that the program is “correct” and will happily point out to you these kinds of mistakes in the source code, like calling an undefined method or passing a wrong number of arguments to a function. The compiler acts as a first line of defense before you are able to deploy the application into production.

On the other hand, PHP is nothing like that. If you make a mistake, the program will crash when the line of code with the mistake is executed. When testing a PHP application, whether manually or automatically, developers spend a lot of their time discovering mistakes that wouldn’t even compile in other languages, leaving less time for testing actual business logic.

There are several static analyzers available for PHP that substitute the role of the compiler from other languages. By finding bugs without even having to execute the code, they can save a lot of effort that’d be spent on tedious writing of boring unit tests. In this talk, I will share tips and tricks on how to structure your code to maximize benefits from using a static analyzer. You won’t stop writing unit tests, but you will focus your efforts on areas where they count the most.

Who are you?

Claim talk

Talk claims have been moved to the new Joind.in site.

Please login to the new site to claim your talk

Want to comment on this talk? Log in or create a new account or comment anonymously

Write a comment

 
Please note: you are not logged in and will be posting anonymously!
= two plus five

Comments

Rating: 5 of 5

11.Jun.2018 at 19:12 by Dave Liddament (67 comments) via Web2 LIVE

A great talk. Static analysis has come along a long way with PHP 7 and the message about these tools needs to get out.
Nice code ideas to show to write code in such a way to get the most out of testing and SA. I'll be making a few changes to how I code based on this talk.

© Joind.in 2018