Skip to content

Commit

Permalink
[GH-20] Bugfix: Do trigger when root package deprecation from /tests/
Browse files Browse the repository at this point in the history
  • Loading branch information
beberlei committed Mar 11, 2021
1 parent db319bc commit 98cd98d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/Doctrine/Deprecations/Deprecation.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,12 @@ public static function triggerIfCalledFromOutside(string $package, string $link,
// dependency and the caller is not a file in that package.
// When $package is installed as a root package, then this deprecation
// is always ignored
if (strpos($backtrace[0]['file'], 'vendor/' . $package . '/') === false) {
if (strpos($backtrace[0]['file'], '/vendor/' . $package . '/') === false &&
strpos($backtrace[1]['file'], '/tests/') !== false) {
return;
}

if (strpos($backtrace[1]['file'], 'vendor/' . $package . '/') !== false) {
if (strpos($backtrace[1]['file'], '/vendor/' . $package . '/') !== false) {
return;
}

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

public function testDeprecationCalledFromOutside(): void
{
Deprecation::enableWithTriggerError();

$this->expectDeprecation();
$this->expectDeprecationMessage('this is deprecated foo 1234 (DeprecationTest.php');

$this->expectDeprecationWithIdentifier('https://github.com/doctrine/deprecations/4444');

$e = null;
try {
Deprecation::triggerIfCalledFromOutside(
'doctrine/orm',
'https://github.com/doctrine/deprecations/4444',
'this is deprecated %s %d',
'foo',
1234
);

$this->fail('Should never be reached because of deprecation exception');
} catch (Throwable $e) {
$this->assertStringMatchesFormat(
'this is deprecated foo 1234 (DeprecationTest.php:%d called by TestCase.php:%d, https://github.com/doctrine/deprecations/4444, package doctrine/orm)',
$e->getMessage()
);
$this->assertEquals(1, Deprecation::getUniqueTriggeredDeprecationsCount());
$this->assertEquals(['https://github.com/doctrine/deprecations/4444' => 1], Deprecation::getTriggeredDeprecations());

throw $e;
}
}
}

0 comments on commit 98cd98d

Please sign in to comment.