Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning in console when phpunit.xml exclusions are not sorted properly #3248

Closed
lunfel opened this issue Aug 10, 2018 · 5 comments · Fixed by elecena/nano#2
Closed

Warning in console when phpunit.xml exclusions are not sorted properly #3248

lunfel opened this issue Aug 10, 2018 · 5 comments · Fixed by elecena/nano#2

Comments

@lunfel
Copy link

lunfel commented Aug 10, 2018

Q A
PHPUnit version 7.3.1
PHP version 7.2.8
Installation Method Composer

I recently updated my version of PHPUnit. I don't know exactly which version I was running before. Now that I have updated it, I get this warning

PHPUnit 7.3.1 by Sebastian Bergmann and contributors.

  Warning - The configuration file did not pass validation!
  The following problems have been detected:

  Line 21:
  - Element 'directory': This element is not expected. Expected is ( file ).

  Test results may not be as expected.

With my long unchanged phpunit.xml. (From standard Laravel 5.6)

<filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">./app</directory>
            <exclude>
                <file>./app/Http/routes.php</file>
                <directory>./app/Exceptions</directory>  <-- This is line 21 in my phpunit.xml
                <directory>./app/Providers</directory>
            </exclude>
        </whitelist>
    </filter>

Everything works fine, but the warning is quite annoying. So I tried to fix it. I checked if the way to exclude directory was different. Apparently, from the latest doc, it hasn't changed. So I started to mess around with my config. It ended up that moving the nodes around made the warning disappear.

<whitelist processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">./app</directory>
            <exclude>
                <directory>./app/Exceptions</directory>
                <directory>./app/Providers</directory>
                <file>./app/Http/routes.php</file>
            </exclude>
        </whitelist>

I don't really know if this is bug or a validation rule. But as far as I know, usually the order of nodes in an XML file should not be relevant. So I am posting this here to validate if it is a bug or validation rule?

@theseer
Copy link
Collaborator

theseer commented Aug 12, 2018

That's a bug in the XSD schema file.

XML itself does not have any understanding of order. It's just nodes and children.
But of course depending on how such a structure is processed, the order may be or become relevant. That's why the XSD schema language has xs:sequence to enforce a given order.

For this case, the way we use xs:sequence though is lacking the information to tell the order is not relevant.

Nice catch!

PR coming up.

@gsouf
Copy link

gsouf commented May 17, 2019

@theseer still seeing similar message (Element 'blacklist': This element is not expected.) with phpunit 8 and this xml content:

	<filter>
		<whitelist processUncoveredFilesFromWhitelist="true">
			<directory suffix=".php">./</directory>
		</whitelist>
		<blacklist>
			<directory>./.coverage</directory>
			<directory>./doc</directory>
			<directory>./Tests</directory>
		</blacklist>
	</filter>

@theseer
Copy link
Collaborator

theseer commented May 17, 2019

That's correct and expected.

The <blacklist> Element has been removed since PHPUnit 5.0. You probably want to use <exclude> (see https://phpunit.readthedocs.io/en/8.1/configuration.html#whitelisting-files-for-code-coverage).

@gsouf
Copy link

gsouf commented May 18, 2019

@theseer I understand, thanks for details and sorry for my ignorance on the subject

@whatthefrog
Copy link

@lunfel I got the same warning, and manage to get rid of it by simply wrapping the phpunit.xml content with

<?xml version="1.0" encoding="UTF-8"?>
<phpunit>

</phpunit>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants