diff --git a/lib/Doctrine/Deprecations/Deprecation.php b/lib/Doctrine/Deprecations/Deprecation.php index 971111f..516d727 100644 --- a/lib/Doctrine/Deprecations/Deprecation.php +++ b/lib/Doctrine/Deprecations/Deprecation.php @@ -58,6 +58,9 @@ class Deprecation /** @var array */ private static $ignoredLinksCount = []; + /** @var array */ + private static $ignoredLinks = []; + /** @var bool */ private static $deduplication = true; @@ -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; } @@ -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; } @@ -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; @@ -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; } } diff --git a/tests/Doctrine/Deprecations/DeprecationTest.php b/tests/Doctrine/Deprecations/DeprecationTest.php index 086baa8..ad467b2 100644 --- a/tests/Doctrine/Deprecations/DeprecationTest.php +++ b/tests/Doctrine/Deprecations/DeprecationTest.php @@ -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();