Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: symfony/phpunit-bridge
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v5.4.16
Choose a base ref
...
head repository: symfony/phpunit-bridge
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v5.4.17
Choose a head ref
  • 2 commits
  • 6 files changed
  • 2 contributors

Commits on Dec 20, 2022

  1. Copy the full SHA
    9379abd View commit details

Commits on Dec 27, 2022

  1. [PhpUnitBridge] Use verbose deprecation output for quiet types only w…

    …hen it reaches the threshold
    ogizanagi committed Dec 27, 2022
    Copy the full SHA
    2232d32 View commit details
10 changes: 5 additions & 5 deletions DeprecationErrorHandler.php
Original file line number Diff line number Diff line change
@@ -200,7 +200,7 @@ public function shutdown()
// store failing status
$isFailing = !$configuration->tolerates($this->deprecationGroups);

$this->displayDeprecations($groups, $configuration, $isFailing);
$this->displayDeprecations($groups, $configuration);

$this->resetDeprecationGroups();

@@ -213,7 +213,7 @@ public function shutdown()
}

$isFailingAtShutdown = !$configuration->tolerates($this->deprecationGroups);
$this->displayDeprecations($groups, $configuration, $isFailingAtShutdown);
$this->displayDeprecations($groups, $configuration);

if ($configuration->isGeneratingBaseline()) {
$configuration->writeBaseline();
@@ -289,11 +289,10 @@ private static function colorize($str, $red)
/**
* @param string[] $groups
* @param Configuration $configuration
* @param bool $isFailing
*
* @throws \InvalidArgumentException
*/
private function displayDeprecations($groups, $configuration, $isFailing)
private function displayDeprecations($groups, $configuration)
{
$cmp = function ($a, $b) {
return $b->count() - $a->count();
@@ -320,7 +319,8 @@ private function displayDeprecations($groups, $configuration, $isFailing)
fwrite($handle, "\n".self::colorize($deprecationGroupMessage, 'legacy' !== $group && 'indirect' !== $group)."\n");
}

if ('legacy' !== $group && !$configuration->verboseOutput($group) && !$isFailing) {
// Skip the verbose output if the group is quiet and not failing according to its threshold:
if ('legacy' !== $group && !$configuration->verboseOutput($group) && $configuration->toleratesForGroup($group, $this->deprecationGroups)) {
continue;
}
$notices = $this->deprecationGroups[$group]->notices();
26 changes: 26 additions & 0 deletions DeprecationErrorHandler/Configuration.php
Original file line number Diff line number Diff line change
@@ -165,6 +165,32 @@ public function tolerates(array $deprecationGroups)
return true;
}

/**
* @param array<string,DeprecationGroup> $deprecationGroups
*
* @return bool true if the threshold is not reached for the deprecation type nor for the total
*/
public function toleratesForGroup(string $groupName, array $deprecationGroups): bool
{
$grandTotal = 0;

foreach ($deprecationGroups as $type => $group) {
if ('legacy' !== $type) {
$grandTotal += $group->count();
}
}

if ($grandTotal > $this->thresholds['total']) {
return false;
}

if (\in_array($groupName, ['self', 'direct', 'indirect'], true) && $deprecationGroups[$groupName]->count() > $this->thresholds[$groupName]) {
return false;
}

return true;
}

/**
* @return bool
*/
2 changes: 1 addition & 1 deletion Legacy/SymfonyTestsListenerTrait.php
Original file line number Diff line number Diff line change
@@ -138,7 +138,7 @@ public function startTestSuite($suite)
if (!class_exists(AnnotationRegistry::class, false) && class_exists(AnnotationRegistry::class)) {
if (method_exists(AnnotationRegistry::class, 'registerUniqueLoader')) {
AnnotationRegistry::registerUniqueLoader('class_exists');
} else {
} elseif (method_exists(AnnotationRegistry::class, 'registerLoader')) {
AnnotationRegistry::registerLoader('class_exists');
}
}
97 changes: 97 additions & 0 deletions Tests/DeprecationErrorHandler/ConfigurationTest.php
Original file line number Diff line number Diff line change
@@ -234,6 +234,103 @@ public function testOutputIsNotVerboseInWeakMode()
$this->assertFalse($configuration->verboseOutput('other'));
}

/**
* @dataProvider provideDataForToleratesForGroup
*/
public function testToleratesForIndividualGroups(string $deprecationsHelper, array $deprecationsPerType, array $expected)
{
$configuration = Configuration::fromUrlEncodedString($deprecationsHelper);

$groups = $this->buildGroups($deprecationsPerType);

foreach ($expected as $groupName => $tolerates) {
$this->assertSame($tolerates, $configuration->toleratesForGroup($groupName, $groups), sprintf('Deprecation type "%s" is %s', $groupName, $tolerates ? 'tolerated' : 'not tolerated'));
}
}

public function provideDataForToleratesForGroup() {

yield 'total threshold not reached' => ['max[total]=1', [
'unsilenced' => 0,
'self' => 0,
'legacy' => 1, // Legacy group is ignored in total threshold
'other' => 0,
'direct' => 1,
'indirect' => 0,
], [
'unsilenced' => true,
'self' => true,
'legacy' => true,
'other' => true,
'direct' => true,
'indirect' => true,
]];

yield 'total threshold reached' => ['max[total]=1', [
'unsilenced' => 0,
'self' => 0,
'legacy' => 1,
'other' => 0,
'direct' => 1,
'indirect' => 1,
], [
'unsilenced' => false,
'self' => false,
'legacy' => false,
'other' => false,
'direct' => false,
'indirect' => false,
]];

yield 'direct threshold reached' => ['max[total]=99&max[direct]=0', [
'unsilenced' => 0,
'self' => 0,
'legacy' => 1,
'other' => 0,
'direct' => 1,
'indirect' => 1,
], [
'unsilenced' => true,
'self' => true,
'legacy' => true,
'other' => true,
'direct' => false,
'indirect' => true,
]];

yield 'indirect & self threshold reached' => ['max[total]=99&max[direct]=0&max[self]=0', [
'unsilenced' => 0,
'self' => 1,
'legacy' => 1,
'other' => 1,
'direct' => 1,
'indirect' => 1,
], [
'unsilenced' => true,
'self' => false,
'legacy' => true,
'other' => true,
'direct' => false,
'indirect' => true,
]];

yield 'indirect & self threshold not reached' => ['max[total]=99&max[direct]=2&max[self]=2', [
'unsilenced' => 0,
'self' => 1,
'legacy' => 1,
'other' => 1,
'direct' => 1,
'indirect' => 1,
], [
'unsilenced' => true,
'self' => true,
'legacy' => true,
'other' => true,
'direct' => true,
'indirect' => true,
]];
}

private function buildGroups($counts)
{
$groups = [];
36 changes: 36 additions & 0 deletions Tests/DeprecationErrorHandler/partially_quiet2.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
--TEST--
Test DeprecationErrorHandler quiet on everything but self/direct deprecations
--FILE--
<?php

$k = 'SYMFONY_DEPRECATIONS_HELPER';
putenv($k.'='.$_SERVER[$k] = $_ENV[$k] = 'max[self]=0&max[direct]=0&quiet[]=unsilenced&quiet[]=indirect&quiet[]=other');
putenv('ANSICON');
putenv('ConEmuANSI');
putenv('TERM');

$vendor = __DIR__;
while (!file_exists($vendor.'/vendor')) {
$vendor = dirname($vendor);
}
define('PHPUNIT_COMPOSER_INSTALL', $vendor.'/vendor/autoload.php');
require PHPUNIT_COMPOSER_INSTALL;
require_once __DIR__.'/../../bootstrap.php';
require __DIR__.'/fake_vendor/autoload.php';
require __DIR__.'/fake_vendor/acme/lib/deprecation_riddled.php';
require __DIR__.'/fake_vendor/acme/outdated-lib/outdated_file.php';

?>
--EXPECTF--
Unsilenced deprecation notices (3)

Remaining direct deprecation notices (2)

1x: root deprecation

1x: silenced bar deprecation
1x in FooTestCase::testNonLegacyBar

Remaining indirect deprecation notices (1)

Legacy deprecation notices (2)
2 changes: 1 addition & 1 deletion bootstrap.php
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@
if (!class_exists(AnnotationRegistry::class, false) && class_exists(AnnotationRegistry::class)) {
if (method_exists(AnnotationRegistry::class, 'registerUniqueLoader')) {
AnnotationRegistry::registerUniqueLoader('class_exists');
} else {
} elseif (method_exists(AnnotationRegistry::class, 'registerLoader')) {
AnnotationRegistry::registerLoader('class_exists');
}
}