Skip to content

Commit

Permalink
Fix Deprecation::ignoreDeprecations
Browse files Browse the repository at this point in the history
Turns out that `Deprecation::ignoreDeprecations` does not work at all.
  • Loading branch information
ruudk committed Jun 2, 2023
1 parent 077a19a commit 4f4dea5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/Doctrine/Deprecations/Deprecation.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class Deprecation
/** @var array<string,int> */
private static $ignoredLinksCount = [];

/** @var array<string,bool> */
private static $ignoredLinks = [];

/** @var bool */
private static $deduplication = true;

Expand All @@ -84,6 +87,10 @@ public static function trigger(string $package, string $link, string $message, .
self::$ignoredLinksCount[$link] = 1;
}

if (isset(self::$ignoredLinks[$link])) {
return;
}

if (self::$deduplication === true && self::$ignoredLinksCount[$link] > 1) {
return;
}
Expand Down Expand Up @@ -147,6 +154,10 @@ public static function triggerIfCalledFromOutside(string $package, string $link,
self::$ignoredLinksCount[$link] = 1;
}

if (isset(self::$ignoredLinks[$link])) {
return;
}

if (self::$deduplication === true && self::$ignoredLinksCount[$link] > 1) {
return;
}
Expand Down Expand Up @@ -235,6 +246,7 @@ public static function disable(): void
self::$type = self::TYPE_NONE;
self::$logger = null;
self::$deduplication = true;
self::$ignoredLinks = [];

foreach (self::$ignoredLinksCount as $link => $count) {
self::$ignoredLinksCount[$link] = 0;
Expand All @@ -249,7 +261,7 @@ public static function ignorePackage(string $packageName): void
public static function ignoreDeprecations(string ...$links): void
{
foreach ($links as $link) {
self::$ignoredLinksCount[$link] = 0;
self::$ignoredLinks[$link] = true;
}
}

Expand Down
17 changes: 17 additions & 0 deletions tests/Doctrine/Deprecations/DeprecationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,23 @@ public function testDeprecationWithIgnoredPackage(): void
$this->assertEquals(['https://github.com/doctrine/orm/issue/1234' => 1], Deprecation::getTriggeredDeprecations());
}

public function testDeprecationWithIgnoredLink(): void
{
Deprecation::enableWithTriggerError();
Deprecation::ignoreDeprecations('https://github.com/doctrine/orm/issue/1234');

Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/issue/1234',
'this is deprecated %s %d',
'foo',
1234
);

$this->assertEquals(1, Deprecation::getUniqueTriggeredDeprecationsCount());
$this->assertEquals(['https://github.com/doctrine/orm/issue/1234' => 1], Deprecation::getTriggeredDeprecations());
}

public function testDeprecationIfCalledFromOutside(): void
{
Deprecation::enableWithTriggerError();
Expand Down

0 comments on commit 4f4dea5

Please sign in to comment.