diff --git a/composer.json b/composer.json index 82bd660..5cc7ac1 100644 --- a/composer.json +++ b/composer.json @@ -20,8 +20,8 @@ }, "autoload-dev": { "psr-4": { - "DeprecationTests\\": "tests/fixtures/src", - "Doctrine\\Foo\\": "tests/fixtures/vendor/doctrine/foo" + "DeprecationTests\\": "test_fixtures/src", + "Doctrine\\Foo\\": "test_fixtures/vendor/doctrine/foo" } } } diff --git a/lib/Doctrine/Deprecations/Deprecation.php b/lib/Doctrine/Deprecations/Deprecation.php index cdc8e0d..10e55bb 100644 --- a/lib/Doctrine/Deprecations/Deprecation.php +++ b/lib/Doctrine/Deprecations/Deprecation.php @@ -108,15 +108,15 @@ 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 && - strpos($backtrace[1]['file'], '/tests/') !== false - ) { - return; - } - - if (strpos($backtrace[1]['file'], '/vendor/' . $package . '/') !== false) { - return; + // first check that the caller is not from a tests folder, in which case we always let deprecations pass + if (strpos($backtrace[1]['file'], '/tests/') === false) { + if (strpos($backtrace[0]['file'], '/vendor/' . $package . '/') === false) { + return; + } + + if (strpos($backtrace[1]['file'], '/vendor/' . $package . '/') !== false) { + return; + } } if (array_key_exists($link, self::$ignoredLinks)) { diff --git a/tests/fixtures/src/Foo.php b/test_fixtures/src/Foo.php similarity index 100% rename from tests/fixtures/src/Foo.php rename to test_fixtures/src/Foo.php diff --git a/test_fixtures/src/RootDeprecation.php b/test_fixtures/src/RootDeprecation.php new file mode 100644 index 0000000..feccd48 --- /dev/null +++ b/test_fixtures/src/RootDeprecation.php @@ -0,0 +1,20 @@ +expectDeprecation(); - $this->expectDeprecationMessage('this is deprecated foo 1234 (DeprecationTest.php'); + $this->expectDeprecationMessage('this is deprecated foo 1234 (RootDeprecation.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 - ); + RootDeprecation::run(); $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)', + 'this is deprecated foo 1234 (RootDeprecation.php:%d called by DeprecationTest.php:%d, https://github.com/doctrine/deprecations/4444, package doctrine/orm)', $e->getMessage() ); $this->assertEquals(1, Deprecation::getUniqueTriggeredDeprecationsCount());