Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Event/Emitter/DispatchingEmitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -1208,6 +1208,13 @@ public function testSuiteFinished(TestSuite $testSuite): void
*/
public function testRunnerTriggeredPhpunitDeprecation(string $message): void
{
try {
if (TestMethodBuilder::fromCallStack()->metadata()->isIgnorePhpunitDeprecations()->isNotEmpty()) {
return;
}
} catch (NoTestCaseObjectOnCallStackException) {
}

$this->dispatcher->dispatch(
new TestRunner\DeprecationTriggered(
$this->telemetryInfo(),
Expand Down
8 changes: 4 additions & 4 deletions src/Metadata/Parser/AnnotationParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,14 @@ public function forClass(string $className): MetadataCollection
if (!empty($result) &&
!isset(self::$deprecationEmittedForClass[$className]) &&
!str_starts_with($className, 'PHPUnit\TestFixture')) {
self::$deprecationEmittedForClass[$className] = true;

EventFacade::emitter()->testRunnerTriggeredPhpunitDeprecation(
sprintf(
'Metadata found in doc-comment for class %s. Metadata in doc-comments is deprecated and will no longer be supported in PHPUnit 12. Update your test code to use attributes instead.',
$className,
),
);

self::$deprecationEmittedForClass[$className] = true;
}

return MetadataCollection::fromArray($result);
Expand Down Expand Up @@ -429,15 +429,15 @@ public function forMethod(string $className, string $methodName): MetadataCollec
if (!empty($result) &&
!isset(self::$deprecationEmittedForMethod[$className . '::' . $methodName]) &&
!str_starts_with($className, 'PHPUnit\TestFixture')) {
self::$deprecationEmittedForMethod[$className . '::' . $methodName] = true;

EventFacade::emitter()->testRunnerTriggeredPhpunitDeprecation(
sprintf(
'Metadata found in doc-comment for method %s::%s(). Metadata in doc-comments is deprecated and will no longer be supported in PHPUnit 12. Update your test code to use attributes instead.',
$className,
$methodName,
),
);

self::$deprecationEmittedForMethod[$className . '::' . $methodName] = true;
}

return MetadataCollection::fromArray($result);
Expand Down
29 changes: 29 additions & 0 deletions tests/end-to-end/regression/6304-class-metadata.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--TEST--
https://github.com/sebastianbergmann/phpunit/issues/6304
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = '--display-phpunit-deprecations';
$_SERVER['argv'][] = __DIR__ . '/6304/Issue6304ClassMetadataTest.php';

require __DIR__ . '/../../bootstrap.php';

(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

Runtime: %s

. 1 / 1 (100%)

Time: %s, Memory: %s MB

There were 2 PHPUnit test runner deprecations:

1) Metadata found in doc-comment for class Issue6304ClassMetadataTest. Metadata in doc-comments is deprecated and will no longer be supported in PHPUnit 12. Update your test code to use attributes instead.

2) Metadata found in doc-comment for class Issue6304ClassMetadataTest. Metadata in doc-comments is deprecated and will no longer be supported in PHPUnit 12. Update your test code to use attributes instead.

OK, but there were issues!
Tests: 1, Assertions: 1, PHPUnit Deprecations: 2.
27 changes: 27 additions & 0 deletions tests/end-to-end/regression/6304-method-metadata.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--TEST--
https://github.com/sebastianbergmann/phpunit/issues/6304
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = '--display-phpunit-deprecations';
$_SERVER['argv'][] = __DIR__ . '/6304/Issue6304MethodMetadataTest.php';

require __DIR__ . '/../../bootstrap.php';

(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

Runtime: %s

. 1 / 1 (100%)

Time: %s, Memory: %s MB

There was 1 PHPUnit test runner deprecation:

1) Metadata found in doc-comment for method Issue6304MethodMetadataTest::testOne(). Metadata in doc-comments is deprecated and will no longer be supported in PHPUnit 12. Update your test code to use attributes instead.

OK, but there were issues!
Tests: 1, Assertions: 1, PHPUnit Deprecations: 1.
25 changes: 25 additions & 0 deletions tests/end-to-end/regression/6304/Issue6304ClassMetadataTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use PHPUnit\Framework\TestCase;

/**
* @group test
*
* @runTestsInSeparateProcesses
*/
final class Issue6304ClassMetadataTest extends TestCase
{
public function testOne(): void
{
$this->assertTrue(true);
}
}
25 changes: 25 additions & 0 deletions tests/end-to-end/regression/6304/Issue6304MethodMetadataTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use PHPUnit\Framework\TestCase;

final class Issue6304MethodMetadataTest extends TestCase
{
/**
* @group test
*
* @runTestsInSeparateProcesses
*/
public function testOne(): void
{
$this->assertTrue(true);
}
}
22 changes: 22 additions & 0 deletions tests/end-to-end/regression/6329-runner-deprecation-ignored.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
https://github.com/sebastianbergmann/phpunit/issues/6329
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = '--display-phpunit-deprecations';
$_SERVER['argv'][] = __DIR__ . '/6329/Issue6329DeprecationIgnoredTest.php';

require __DIR__ . '/../../bootstrap.php';

(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

Runtime: %s

. 1 / 1 (100%)

Time: %s, Memory: %s MB

OK (1 test, 1 assertion)
27 changes: 27 additions & 0 deletions tests/end-to-end/regression/6329-runner-deprecation.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--TEST--
https://github.com/sebastianbergmann/phpunit/issues/6329
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = '--display-phpunit-deprecations';
$_SERVER['argv'][] = __DIR__ . '/6329/Issue6329DeprecationTest.php';

require __DIR__ . '/../../bootstrap.php';

(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

Runtime: %s

. 1 / 1 (100%)

Time: %s, Memory: %s MB

There was 1 PHPUnit test runner deprecation:

1) A runner deprecation!

OK, but there were issues!
Tests: 1, Assertions: 1, PHPUnit Deprecations: 1.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use PHPUnit\Event\Facade as EventFacade;
use PHPUnit\Framework\Attributes\IgnorePhpunitDeprecations;
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
use PHPUnit\Framework\TestCase;

#[RunTestsInSeparateProcesses]
final class Issue6329DeprecationIgnoredTest extends TestCase
{
#[IgnorePhpunitDeprecations]
public function testOne(): void
{
EventFacade::emitter()->testRunnerTriggeredPhpunitDeprecation(
'A runner deprecation!',
);

$this->assertTrue(true);
}
}
27 changes: 27 additions & 0 deletions tests/end-to-end/regression/6329/Issue6329DeprecationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use PHPUnit\Event\Facade as EventFacade;
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
use PHPUnit\Framework\TestCase;

#[RunTestsInSeparateProcesses]
final class Issue6329DeprecationTest extends TestCase
{
public function testOne(): void
{
EventFacade::emitter()->testRunnerTriggeredPhpunitDeprecation(
'A runner deprecation!',
);

$this->assertTrue(true);
}
}
Loading