Tag: PHP ¦ Atom ¦ RSS

Vim: checking PHP code (and Python and...)

Do you hate it as much as I do when you are writing some PHP (or Python or whatever) code in your favorite editor, hit 'save', reload the page in the browser in the hopes that you will see the new most awesome feature you ever wrote, but instead you are greeted by an unfriendly PARSE_ERROR_YOU_FORGOT_A_CLOSING_BRACKET_YOU_STUPID-error? Right, it feels like you just built a rocket, but upon launch you discover you didn't foresee a doorknob and can't get in anymore...

Luckily, if you are using Vim there is a nice plugin to quickly catch these errors (and more). The plugin I'm talking about is Syntastic. The plugin is built as a generic framework to run and process the result of a syntax checker. The syntax checkers themselves are specific for each language. Most of the syntax checkers start an external syntax checker or linter and return the output to Syntastic, telling it how to parse it.

By default Syntastic will automatically run the correct checker every time you save the …

UnitTesting PHP

Once you've discovered the advantages of unittests you'll never want to write one single line of code without a test for it (well allmost ;)). You'll become "test-infected" :).

A few months ago, while doing a project in .NET, I discovered these advantages. Having unittests for your code helps you to refactor your code and add new/modified features to your application without having to fear that you'll break your code. Ofcourse you can still break your code, but if you have good unittests you'll immediately notice that you broke something and, depending on how good your tests are, you will also know where you broke something. When you have UnitTests you'll feel a lot safer when touching your code.

Today allmost every language has one or more unittesting frameworks. Most of them are based on JUnit, and are called xUnit frameworks. One example is NUnit, which is the JUnit port to .NET. Also PHP has it's unittesting frameworks, of which PHPUnit and SimpleTest are the best known.

SimpleTest is not just …