Skip to content

Commit

Permalink
Fix calculation of triggered deprecations after disable()
Browse files Browse the repository at this point in the history
  • Loading branch information
beberlei committed Jun 30, 2020
1 parent f1c9075 commit 05f305b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/Doctrine/Deprecations/Deprecation.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ public static function disable() : void
{
self::$type = self::TYPE_NONE;
self::$logger = null;

foreach (self::$ignoredLinks as $link => $count) {
self::$ignoredLinks[$link] = 0;
}
}

public static function ignorePackage(string $packageName, string $version = "0.0.1") : void
Expand All @@ -148,7 +152,9 @@ public static function ignoreDeprecations(...$links) : void

public static function getUniqueTriggeredDeprecationsCount() : int
{
return count(self::$ignoredLinks);
return array_reduce(self::$ignoredLinks, function (int $carry, int $count) {
return $carry + $count;
}, 0);
}

/**
Expand Down
19 changes: 19 additions & 0 deletions tests/Doctrine/Deprecations/DeprecationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,25 @@ public function testDeprecation()
}
}

public function testDeprecationResetsCounts()
{
try {
Deprecation::trigger(
"doctrine/orm",
"2.7",
"https://github.com/doctrine/deprecations/1234",
"this is deprecated %s %d",
"foo",
1234
);
} catch(\Exception $e) {
Deprecation::disable();

$this->assertEquals(0, Deprecation::getUniqueTriggeredDeprecationsCount());
$this->assertEquals(["https://github.com/doctrine/deprecations/1234" => 0], Deprecation::getTriggeredDeprecations());
}
}

public function testDeprecationWithNumericLinkPointingToGithubIssue()
{
Deprecation::enableWithTriggerError();
Expand Down

0 comments on commit 05f305b

Please sign in to comment.