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

JUnit logger crashes when test is skipped by missing PHP extension when running in separate process #5258

Closed
MauricioFauth opened this issue Feb 26, 2023 · 3 comments
Labels
feature/logging/junit Issues related to logging test results in JUnit XML format feature/logging Issues related to logging test results type/bug Something is broken version/10 Something affects PHPUnit 10

Comments

@MauricioFauth
Copy link
Contributor

MauricioFauth commented Feb 26, 2023

Q A
PHPUnit version 10.0.12
PHP version 8.1.14
Installation Method Composer

Summary

The JUnit logger crashes when a test is skipped because of missing required PHP extension when running in separate process.

Introduced by PHPUnit 10.0.12.

Current behavior

PHPUnit 10.0.12 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.1.14
Configuration: /path/phpunit-10-test/phpunit.xml

.S                                                                  2 / 2 (100%)

An error occurred inside PHPUnit.

Message:  assert($this->currentTestCase !== null)
Location: /path/phpunit-10-test/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:68

#0 /path/phpunit-10-test/vendor/phpunit/phpunit/src/TextUI/Application.php(142): PHPUnit\TextUI\TestRunner->run()
#1 /path/phpunit-10-test/vendor/phpunit/phpunit/phpunit(90): PHPUnit\TextUI\Application->run()
#2 /path/phpunit-10-test/vendor/bin/phpunit(123): include('...')
#3 {main}

How to reproduce

phpunit.xml

<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
         bootstrap="vendor/autoload.php">
    <testsuites>
        <testsuite name="default">
            <directory>tests</directory>
        </testsuite>
    </testsuites>

    <logging>
        <junit outputFile="junit.xml"/>
    </logging>
</phpunit>

tests/FooTest.php

<?php

declare(strict_types=1);

use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use PHPUnit\Framework\TestCase;

class FooTest extends TestCase
{
    public function testOne(): void
    {
        $this->assertTrue(true);
    }

    #[RunInSeparateProcess]
    #[RequiresPhpExtension('notinstalled')]
    public function testTwo(): void
    {
        $this->assertTrue(true);
    }
}

Expected behavior

PHPUnit 10.0.11 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.1.14
Configuration: /path/phpunit-10-test/phpunit.xml

.S                                                                  2 / 2 (100%)

Time: 00:00.067, Memory: 8.00 MB

OK, but some tests were skipped!
Tests: 2, Assertions: 1, Skipped: 1.
@MauricioFauth MauricioFauth added type/bug Something is broken version/10 Something affects PHPUnit 10 labels Feb 26, 2023
@sebastianbergmann
Copy link
Owner

@Slamdunk Can you have a look at this, please? Thanks!

@sebastianbergmann sebastianbergmann added the feature/logging Issues related to logging test results label Feb 27, 2023
sebastianbergmann added a commit that referenced this issue Feb 27, 2023
@sebastianbergmann
Copy link
Owner

I added a test case in def6b4f.

@sebastianbergmann
Copy link
Owner

After e1e8aab the full crash message is now:

An error occurred inside PHPUnit.

Message:  assert($this->currentTestCase !== null)
Location: /usr/local/src/phpunit/src/TextUI/TestRunner.php:68

#0 /usr/local/src/phpunit/src/TextUI/Application.php(141): PHPUnit\TextUI\TestRunner->run()
#1 /usr/local/src/phpunit/phpunit(90): PHPUnit\TextUI\Application->run()
#2 {main}

Caused by: /usr/local/src/phpunit/src/Logging/JUnit/JunitXmlLogger.php:338

#0 /usr/local/src/phpunit/src/Logging/JUnit/JunitXmlLogger.php(338): assert()
#1 /usr/local/src/phpunit/src/Logging/JUnit/JunitXmlLogger.php(208): PHPUnit\Logging\JUnit\JunitXmlLogger->handleIncompleteOrSkipped()
#2 /usr/local/src/phpunit/src/Logging/JUnit/Subscriber/TestSkippedSubscriber.php(28): PHPUnit\Logging\JUnit\JunitXmlLogger->testSkipped()
#3 /usr/local/src/phpunit/src/Event/Dispatcher/DirectDispatcher.php(99): PHPUnit\Logging\JUnit\TestSkippedSubscriber->notify()
#4 /usr/local/src/phpunit/src/Event/Dispatcher/DeferringDispatcher.php(45): PHPUnit\Event\DirectDispatcher->dispatch()
#5 /usr/local/src/phpunit/src/Event/Facade.php(97): PHPUnit\Event\DeferringDispatcher->dispatch()
#6 /usr/local/src/phpunit/src/Util/PHP/AbstractPhpProcess.php(313): PHPUnit\Event\Facade::forward()
#7 /usr/local/src/phpunit/src/Util/PHP/AbstractPhpProcess.php(166): PHPUnit\Util\PHP\AbstractPhpProcess->processChildResult()
#8 /usr/local/src/phpunit/src/Framework/TestRunner.php(343): PHPUnit\Util\PHP\AbstractPhpProcess->runTestJob()
#9 /usr/local/src/phpunit/src/Framework/TestCase.php(458): PHPUnit\Framework\TestRunner->runInSeparateProcess()
#10 /usr/local/src/phpunit/src/Framework/TestSuite.php(352): PHPUnit\Framework\TestCase->run()
#11 /usr/local/src/phpunit/src/TextUI/TestRunner.php(63): PHPUnit\Framework\TestSuite->run()
#12 /usr/local/src/phpunit/src/TextUI/Application.php(141): PHPUnit\TextUI\TestRunner->run()
#13 /usr/local/src/phpunit/phpunit(90): PHPUnit\TextUI\Application->run()
#14 {main}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/logging/junit Issues related to logging test results in JUnit XML format feature/logging Issues related to logging test results type/bug Something is broken version/10 Something affects PHPUnit 10
Projects
None yet
Development

No branches or pull requests

2 participants