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

TestSuite\Loaded event has incomplete Event\TestSuite\TestSuite value object #5366

Closed
sebastianbergmann opened this issue May 19, 2023 · 5 comments
Assignees
Labels
feature/events Issues related to PHPUnit's event system feature/test-runner CLI test runner type/bug Something is broken version/10 Something affects PHPUnit 10

Comments

@sebastianbergmann
Copy link
Owner

This can be reproduced using this var_dump() call:

diff --git a/src/Event/Emitter/DispatchingEmitter.php b/src/Event/Emitter/DispatchingEmitter.php
index 1b89c1e5a..d2f19fe62 100644
--- a/src/Event/Emitter/DispatchingEmitter.php
+++ b/src/Event/Emitter/DispatchingEmitter.php
@@ -136,6 +136,8 @@ public function testRunnerBootstrappedExtension(string $className, array $parame
      */
     public function testSuiteLoaded(TestSuite $testSuite): void
     {
+        var_dump($testSuite);
+
         $this->dispatcher->dispatch(
             new TestSuiteLoaded(
                 $this->telemetryInfo(),

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.1/phpunit.xsd">
    <testsuites>
        <testsuite name="default">
            <directory>tests</directory>
        </testsuite>
    </testsuites>
</phpunit>

tests/Test.php

<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;

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

Invoking the test runner without an argument

This does not work as expected (the tests array is empty):

phpunit --no-output
object(PHPUnit\Event\TestSuite\TestSuiteWithName)#90 (3) {
  ["name":"PHPUnit\Event\TestSuite\TestSuite":private]=>
  string(0) ""
  ["count":"PHPUnit\Event\TestSuite\TestSuite":private]=>
  int(1)
  ["tests":"PHPUnit\Event\TestSuite\TestSuite":private]=>
  object(PHPUnit\Event\Code\TestCollection)#92 (1) {
    ["tests":"PHPUnit\Event\Code\TestCollection":private]=>
    array(0) {
    }
  }
}

Invoking the test runner with the path to a test source file as an argument

This works as expected:

$ phpunit --no-output tests/Test.php
object(PHPUnit\Event\TestSuite\TestSuiteForTestClass)#324 (6) {
  ["name":"PHPUnit\Event\TestSuite\TestSuite":private]=>
  string(4) "Test"
  ["count":"PHPUnit\Event\TestSuite\TestSuite":private]=>
  int(1)
  ["tests":"PHPUnit\Event\TestSuite\TestSuite":private]=>
  object(PHPUnit\Event\Code\TestCollection)#325 (1) {
    ["tests":"PHPUnit\Event\Code\TestCollection":private]=>
    array(1) {
      [0]=>
      object(PHPUnit\Event\Code\TestMethod)#91 (7) {
        ["file":"PHPUnit\Event\Code\Test":private]=>
        string(27) "/home/sb/bug/tests/Test.php"
        ["className":"PHPUnit\Event\Code\TestMethod":private]=>
        string(4) "Test"
        ["methodName":"PHPUnit\Event\Code\TestMethod":private]=>
        string(7) "testOne"
        ["line":"PHPUnit\Event\Code\TestMethod":private]=>
        int(6)
        ["testDox":"PHPUnit\Event\Code\TestMethod":private]=>
        object(PHPUnit\Event\Code\TestDox)#92 (3) {
          ["prettifiedClassName":"PHPUnit\Event\Code\TestDox":private]=>
          string(13) "Unnamed Tests"
          ["prettifiedMethodName":"PHPUnit\Event\Code\TestDox":private]=>
          string(3) "One"
          ["prettifiedAndColorizedMethodName":"PHPUnit\Event\Code\TestDox":private]=>
          string(3) "One"
        }
        ["metadata":"PHPUnit\Event\Code\TestMethod":private]=>
        object(PHPUnit\Metadata\MetadataCollection)#328 (1) {
          ["metadata":"PHPUnit\Metadata\MetadataCollection":private]=>
          array(0) {
          }
        }
        ["testData":"PHPUnit\Event\Code\TestMethod":private]=>
        object(PHPUnit\Event\TestData\TestDataCollection)#93 (2) {
          ["data":"PHPUnit\Event\TestData\TestDataCollection":private]=>
          array(0) {
          }
          ["fromDataProvider":"PHPUnit\Event\TestData\TestDataCollection":private]=>
          NULL
        }
      }
    }
  }
  ["className":"PHPUnit\Event\TestSuite\TestSuiteForTestClass":private]=>
  string(4) "Test"
  ["file":"PHPUnit\Event\TestSuite\TestSuiteForTestClass":private]=>
  string(27) "/home/sb/bug/tests/Test.php"
  ["line":"PHPUnit\Event\TestSuite\TestSuiteForTestClass":private]=>
  int(4)
}
@sebastianbergmann sebastianbergmann added type/bug Something is broken feature/test-runner CLI test runner feature/events Issues related to PHPUnit's event system version/10 Something affects PHPUnit 10 labels May 19, 2023
@sebastianbergmann sebastianbergmann self-assigned this May 19, 2023
@sebastianbergmann
Copy link
Owner Author

CC @Ocramius @theseer

@sebastianbergmann
Copy link
Owner Author

This is likely caused by missing recursive iteration in PHPUnit\Event\TestSuite\TestSuiteBuilder::from() which builds an PHPUnit\Event\TestSuite\TestSuite value object from a PHPUnit\Framework\TestSuite object.

@Ocramius
Copy link
Sponsor Contributor

Whoa, really elegant solution! 💪

Mine was a blob of ugly recursive code...

@sebastianbergmann
Copy link
Owner Author

Whoa, really elegant solution! 💪

Looks like I need to find a different solution. But not today :)

@sebastianbergmann
Copy link
Owner Author

The tests added in 4984c50 will prevent the regression reported in #5393 when I have another go at this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/events Issues related to PHPUnit's event system feature/test-runner CLI test runner type/bug Something is broken version/10 Something affects PHPUnit 10
Projects
None yet
Development

No branches or pull requests

2 participants