Written by: Matthias
Published on: 24/11/2013

How to use an XML schema for PHPUnit configuration files to get autocompletion in PHPStorm

PHP
Back in 2011, one of our team members published an XML schema for the PHPUnit configuration file in his blog. And as of writing, it is among the top results when you google for "phpunit xsd".

Now it turned out that there is also an "official" schema available but mentioned nowhere in the docs.

That was easy to change and now folks will get the

<phpunit
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/3.7/phpunit.xsd" …

markup when they pick the example file from the documentation as a starting point.

Why?

Adding the schema definition is less important for validating the configuration file. The primary benefit is that every decent IDE should be able to give you autocompletion and code suggestions based on it.

When using PHPStorm, the schema URL will initially be displayed in red and marked as an error. You need to place the cursor on it, press Alt+Enter and choose "fetch external resource". After that, PHPStorm will keep a local copy of the schema file and use it also for every other project.

Sie möchten ein PHP-Projekt realisieren?

Als PHP Agentur haben wir langjährige Erfahrung in der Umsetzung von Softwareprojekten in PHP. Wenn Sie ein Projekt in PHP realisieren wollen und einen Partner suchen, sprechen Sie uns gerne an!