Skip to content

Commit

Permalink
Fix: deprecations should not raise exceptions (#918)
Browse files Browse the repository at this point in the history
* Reproduce the #915 bug

* Initialize the DeprecationCollector
  • Loading branch information
Slamdunk authored Dec 10, 2024
1 parent 1ad660c commit ae3c9f1
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/WrapperRunner/ApplicationForWrapperWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use PHPUnit\Runner\Baseline\CannotLoadBaselineException;
use PHPUnit\Runner\Baseline\Reader;
use PHPUnit\Runner\CodeCoverage;
use PHPUnit\Runner\DeprecationCollector\Facade as DeprecationCollector;
use PHPUnit\Runner\ErrorHandler;
use PHPUnit\Runner\Extension\ExtensionBootstrapper;
use PHPUnit\Runner\Extension\Facade as ExtensionFacade;
Expand Down Expand Up @@ -170,12 +171,6 @@ private function bootstrap(): void
$extensionRequiresCodeCoverageCollection = $extensionFacade->requiresCodeCoverageCollection();
}

CodeCoverage::instance()->init(
$this->configuration,
CodeCoverageFilterRegistry::instance(),
$extensionRequiresCodeCoverageCollection,
);

if ($this->configuration->hasLogfileJunit()) {
new JunitXmlLogger(
DefaultPrinter::from($this->configuration->logfileJunit()),
Expand Down Expand Up @@ -212,6 +207,7 @@ private function bootstrap(): void
}

TestResultFacade::init();
DeprecationCollector::init();

if ($this->configuration->source()->useBaseline()) {
$baselineFile = $this->configuration->source()->baseline();
Expand All @@ -229,6 +225,13 @@ private function bootstrap(): void
}

EventFacade::instance()->seal();

CodeCoverage::instance()->init(
$this->configuration,
CodeCoverageFilterRegistry::instance(),
$extensionRequiresCodeCoverageCollection,
);

EventFacade::emitter()->testRunnerStarted();

if ($this->configuration->executionOrder() === TestSuiteSorter::ORDER_RANDOMIZED) {
Expand Down
22 changes: 22 additions & 0 deletions test/Unit/WrapperRunner/WrapperRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,28 @@ public function testBaselineIsRespected(): void
Time: %s, Memory: %s MB
OK%a
EOF;
self::assertStringMatchesFormat($expectedOutput, $runnerResult->output);
self::assertEquals(RunnerInterface::SUCCESS_EXIT, $runnerResult->exitCode);
}

#[Group('github')]
public function testDeprecationsShouldNotRaiseException(): void
{
$this->bareOptions['--configuration'] = $this->fixture('github' . DIRECTORY_SEPARATOR . 'GH915' . DIRECTORY_SEPARATOR . 'phpunit.xml');

$runnerResult = $this->runRunner();

$expectedOutput = <<<'EOF'
Processes: %s
Runtime: PHP %s
Configuration: %s
. 1 / 1 (100%)
Time: %s, Memory: %s MB
OK%a
EOF;
self::assertStringMatchesFormat($expectedOutput, $runnerResult->output);
Expand Down
16 changes: 16 additions & 0 deletions test/fixtures/github/GH915/IssueTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace ParaTest\Tests\fixtures\github\GH915;

use PHPUnit\Framework\TestCase;

/** @internal */
final class IssueTest extends TestCase
{
public function testasd(): void
{
self::assertSame(1, 1);
}
}
12 changes: 12 additions & 0 deletions test/fixtures/github/GH915/phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../../vendor/phpunit/phpunit/phpunit.xsd"
stopOnDeprecation="true"
>
<testsuites>
<testsuite name="Github issue">
<file>IssueTest.php</file>
</testsuite>
</testsuites>
</phpunit>

0 comments on commit ae3c9f1

Please sign in to comment.