PHP

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

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".

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

In this Post

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!

Interesse geweckt?

Wir hören gerne zu, wenn Sie Fragen oder Anmerkungen zu diesem Thema haben. Und wenn Sie ein Projekt, ein Produkt, ein Problem oder eine Idee mit uns besprechen möchten, freuen wir uns erst recht über ein Gespräch!