Phpunit: Uncaught Notice: Undefined index: warnings

Created on 18 Dec 2019  路  6Comments  路  Source: sebastianbergmann/phpunit

| Q | A
| --------------------| ---------------
| PHPUnit version | 8.3.5
| PHP version | 7.2.24
| Installation Method | Composer

Summary

Hello, I am using Symfony 3.4 and when I execute tests I simply get the PHP version:

./vendor/bin/simple-phpunit --stop-on-error --stop-on-failure
PHPUnit 8.3.5 by Sebastian Bergmann and contributors.

It doesn't execute any test and in the log I get this error:

[2019-12-18 09:34:44] php.CRITICAL: Uncaught Notice: Undefined index: warnings {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\ContextErrorException(code: 0): Notice: Undefined index: warnings at /home/luca/Sites/luisaviaroma/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:334)"} []

This is my phpunit.xml.dist:

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

<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.8/phpunit.xsd"
         backupGlobals="false"
         colors="true"
         bootstrap="vendor/autoload.php"
>
    <php>
        <ini name="error_reporting" value="-1" />
        <server name="KERNEL_CLASS" value="AppKernel" />
    </php>

    <testsuites>
        <testsuite name="Project Test Suite">
            <directory>tests</directory>
        </testsuite>
    </testsuites>

    <filter>
        <whitelist>
            <directory>src</directory>
            <exclude>
                <directory>src/*Bundle/Resources</directory>
                <directory>src/*/*Bundle/Resources</directory>
                <directory>src/*/Bundle/*Bundle/Resources</directory>
            </exclude>
        </whitelist>
    </filter>

    <listeners>
        <listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" />
    </listeners>
</phpunit>

Current behavior

It isn't executing any test.

How to reproduce

I got this error after launching a composer update on a 6-months-old project.

    "require": {
        "php": ">=5.5.9",
        "doctrine/doctrine-bundle": "^1.6",
        "doctrine/doctrine-fixtures-bundle": "^3.0",
        "doctrine/orm": "^2.5",
        "friendsofsymfony/rest-bundle": "^2.3",
        "greenskies/web-log-viewer-bundle": "^0.0.8",
        "guzzlehttp/guzzle": "~6.0",
        "incenteev/composer-parameter-handler": "^2.0",
        "jms/serializer-bundle": "^2.4",
        "joshtronic/php-loremipsum": "^1.0",
        "kunicmarko/sonata-annotation-bundle": "^1.1",
        "monolog/monolog": "^1.22",
        "nelmio/api-doc-bundle": "^3.4",
        "php-translation/symfony-bundle": "^0.8.1",
        "scienta/doctrine-json-functions": "~4.0",
        "sensio/distribution-bundle": "^5.0.19",
        "sensio/framework-extra-bundle": "^5.0.0",
        "sonata-project/admin-bundle": "^3.35",
        "sonata-project/doctrine-orm-admin-bundle": "^3.6",
        "sonata-project/easy-extends-bundle": "^2.5",
        "sonata-project/formatter-bundle": "^4.1",
        "sonata-project/media-bundle": "^3.13",
        "sonata-project/translation-bundle": "^2.3",
        "sonata-project/user-bundle": "^4.1",
        "stof/doctrine-extensions-bundle": "^1.3",
        "symfony/monolog-bundle": "^3.1.0",
        "symfony/polyfill-apcu": "^1.0",
        "symfony/swiftmailer-bundle": "^2.6.4",
        "symfony/symfony": "3.4.*",
        "twig/twig": "^1.0||^2.0"
    },
    "require-dev": {
        "johnkary/phpunit-speedtrap": "^3.1",
        "liip/functional-test-bundle": "~2.0@alpha",
        "liuggio/fastest": "^1.6",
        "phpstan/phpstan": "^0.9.2",
        "sensio/generator-bundle": "^3.0",
        "symfony/phpunit-bridge": "^5.0"
    },

Expected behavior

Tests are executed.

typbug

All 6 comments

It appears that you have different installations of PHPUnit mixed up.

For instance, you may have used Composer to install PHPUnit and have configured the autoloader generated by Composer as PHPUnit's bootstrap script but then you invoke PHPUnit using an executable other than vendor/bin/phpunit.

I don't have a global phpunit installation, it is installed (I think) by simple-phpunit (package symfony/phpunit-bridge).

I have very same problem. My phpunit installation is also provided by symfony/phpunit-bridge

I'm using the symfony phpunit-bridge as well, so I'm using simple-phpunit to start.

It turns out that this phpunit bridge downloads 8.3.(5) version of phpunit which does not use the 'warnings' argument yet (this is from 8.5 onwards).

But, it might be possible (in my case at least) that another phpunit has been installed in vendor/phpunit, either directly as dependency in your composer.json, or as subdependency by another tool (composer why phpunit/phpunit should figure that out). If installed, it might be that a 8.5 version is installed (composer info phpunit/phpunit to find out).

In that case, it confuses phpunit a lot as there are two different versions of phpunit present and executed.

If you cannot remove the phpunit dependency, (in my case, i can't as I want to use additional packages like johnkary/phpunit-speedtrap, which automatically installs phpunit as well), you can "downgrade" your phpunit version to 8.3.

    composer require --dev phpunit/phpunit ^8.3.0

It's not a permanent solution because you must update to the version used in simple-phpunit, but it works for now.

Mine was caused from having a different version installed globally than the local project version. After I updated the global dependencies the warning went away.

On version phpunit 7.5 evrything works, on default 8.5 it dont find classes. Any progress on this bug?

Was this page helpful?
0 / 5 - 0 ratings