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

expectUserDeprecationMessage*() fails when test is run in separate process #6102

Open
mondrake opened this issue Jan 12, 2025 · 0 comments
Open
Assignees
Labels
feature/assertion Issues related to assertions and expectations feature/process-isolation Issues related to running tests in separate PHP processes feature/test-runner CLI test runner type/bug Something is broken version/11 Something affects PHPUnit 11 version/12 Something affects PHPUnit 12

Comments

@mondrake
Copy link
Contributor

Q A
PHPUnit version 11.5.2
PHP version 8.3.9
Installation Method Composer

Summary

expectUserDeprecationMessage*() fails when test is run in separate process.

Current behavior

A test like this

<?php

declare(strict_types=1);

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

class ExpectDeprecationTest extends TestCase {

  /**
   * Tests expectDeprecation.
   */
  public function testExpectDeprecation(): void {
    $this->expectUserDeprecationMessage('Test deprecation');
    @trigger_error('Test deprecation', E_USER_DEPRECATED);
  }

  /**
   * Tests expectDeprecation in isolated test.
   */
  #[RunInSeparateProcess]
  public function testExpectDeprecationInIsolation(): void {
    $this->expectUserDeprecationMessage('Test isolated deprecation');
    @trigger_error('Test isolated deprecation', E_USER_DEPRECATED);
  }

}

leads to an EventFacadeIsSealedException error reported by the runner:

PHPUnit 11.5.2 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.3.9
Configuration: /Users/xxx/Dev/drupal/core/phpunit.xml.dist

DE                                                                  2 / 2 (100%)

Time: 00:01.879, Memory: 14.00 MB

There was 1 error:

1) ExpectDeprecationTest::testExpectDeprecationInIsolation
PHPUnit\Event\EventFacadeIsSealedException:

--

2 tests triggered 2 deprecations:

1) /Users/xxx/Dev/drupal/core/tests/Drupal/Tests/ExpectDeprecationTest.php:15
Test deprecation

2) /Users/xxx/Dev/drupal/core/tests/Drupal/Tests/ExpectDeprecationTest.php:24
Test isolated deprecation

ERRORS!
Tests: 2, Assertions: 2, Errors: 1, Deprecations: 2.

How to reproduce

See above

Expected behavior

No exception reported, only the deprecations.

@mondrake mondrake added the type/bug Something is broken label Jan 12, 2025
@sebastianbergmann sebastianbergmann added feature/test-runner CLI test runner feature/assertion Issues related to assertions and expectations labels Jan 13, 2025
@sebastianbergmann sebastianbergmann self-assigned this Jan 13, 2025
@sebastianbergmann sebastianbergmann added feature/process-isolation Issues related to running tests in separate PHP processes version/11 Something affects PHPUnit 11 labels Jan 13, 2025
sebastianbergmann added a commit that referenced this issue Jan 13, 2025
@sebastianbergmann sebastianbergmann added the version/12 Something affects PHPUnit 12 label Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/assertion Issues related to assertions and expectations feature/process-isolation Issues related to running tests in separate PHP processes feature/test-runner CLI test runner type/bug Something is broken version/11 Something affects PHPUnit 11 version/12 Something affects PHPUnit 12
Projects
None yet
Development

No branches or pull requests

2 participants