Merge branch '5.2' into 5.x
* 5.2: [SecurityBundle] role_names variable instead of roles [PhpUnitBridge] fix reporting deprecations when they come from DebugClassLoader Fix Request with DNS issue not retried Bump Symfony version to 5.2.4 Update VERSION for 5.2.3 Update CHANGELOG for 5.2.3 [ErrorHandler] fix parsing return types in DebugClassLoader [ErrorHandler] fix handling messages with null bytes from anonymous classes Restore priority for eventSubscribers
This commit is contained in:
commit
60118f14aa
@ -7,6 +7,17 @@ in 5.2 minor versions.
|
||||
To get the diff for a specific change, go to https://github.com/symfony/symfony/commit/XXX where XXX is the change hash
|
||||
To get the diff between two versions, go to https://github.com/symfony/symfony/compare/v5.2.0...v5.2.1
|
||||
|
||||
* 5.2.3 (2021-02-03)
|
||||
|
||||
* bug #39954 [Mailer][Mime] Fix case-sensitive handling of header names (piku235)
|
||||
* bug #40055 [Messenger] Fix Doctrine setup when using a migration (fabpot)
|
||||
* bug #40018 [TwigBridge] take into account all label related options (xabbuh)
|
||||
* bug #40023 [Finder] use proper keys to not override appended files (xabbuh)
|
||||
* bug #40019 [ErrorHandler] Fix strpos error when trying to call a method without a name (Deuchnord)
|
||||
* bug #40027 [DoctrineBridge] add missing `@experimental` annotation on Uid generators (nicolas-grekas)
|
||||
* bug #40004 [Serializer] Prevent access to private properties without getters (julienfalque)
|
||||
* bug #40003 [Uid] Fix time to float conversion (fancyweb)
|
||||
|
||||
* 5.2.2 (2021-01-27)
|
||||
|
||||
* bug #38900 [Serializer] Exclude non-initialized properties accessed with getters (BoShurik)
|
||||
|
3
phpunit
3
phpunit
@ -16,9 +16,6 @@ if (!getenv('SYMFONY_PHPUNIT_VERSION')) {
|
||||
putenv('SYMFONY_PHPUNIT_VERSION=9.5');
|
||||
}
|
||||
}
|
||||
if (!getenv('SYMFONY_PATCH_TYPE_DECLARATIONS')) {
|
||||
putenv('SYMFONY_PATCH_TYPE_DECLARATIONS=deprecations=1');
|
||||
}
|
||||
if (getcwd() === realpath(__DIR__.'/src/Symfony/Bridge/PhpUnit')) {
|
||||
putenv('SYMFONY_DEPRECATIONS_HELPER=disabled');
|
||||
}
|
||||
|
@ -164,11 +164,22 @@ class ContainerAwareEventManager extends EventManager
|
||||
private function initializeSubscribers()
|
||||
{
|
||||
$this->initializedSubscribers = true;
|
||||
|
||||
$eventListeners = $this->listeners;
|
||||
// reset eventListener to respect priority: EventSubscribers have a higher priority
|
||||
$this->listeners = [];
|
||||
foreach ($this->subscribers as $id => $subscriber) {
|
||||
if (\is_string($subscriber)) {
|
||||
parent::addEventSubscriber($this->subscribers[$id] = $this->container->get($subscriber));
|
||||
}
|
||||
}
|
||||
foreach ($eventListeners as $event => $listeners) {
|
||||
if (!isset($this->listeners[$event])) {
|
||||
$this->listeners[$event] = [];
|
||||
}
|
||||
$this->listeners[$event] += $listeners;
|
||||
}
|
||||
$this->subscribers = [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -146,11 +146,14 @@ class ContainerAwareEventManagerTest extends TestCase
|
||||
|
||||
public function testGetListenersForEvent()
|
||||
{
|
||||
$this->evm = new ContainerAwareEventManager($this->container, ['lazy2']);
|
||||
|
||||
$this->container->set('lazy', $listener1 = new MyListener());
|
||||
$this->container->set('lazy2', $subscriber1 = new MySubscriber(['foo']));
|
||||
$this->evm->addEventListener('foo', 'lazy');
|
||||
$this->evm->addEventListener('foo', $listener2 = new MyListener());
|
||||
|
||||
$this->assertSame([$listener1, $listener2], array_values($this->evm->getListeners('foo')));
|
||||
$this->assertSame([$subscriber1, $listener1, $listener2], array_values($this->evm->getListeners('foo')));
|
||||
}
|
||||
|
||||
public function testGetListeners()
|
||||
|
1
src/Symfony/Bridge/PhpUnit/.gitignore
vendored
1
src/Symfony/Bridge/PhpUnit/.gitignore
vendored
@ -1,4 +1,3 @@
|
||||
vendor/
|
||||
composer.lock
|
||||
phpunit.xml
|
||||
Tests/DeprecationErrorHandler/fake_vendor/symfony/error-handler/DebugClassLoader.php
|
||||
|
@ -125,18 +125,20 @@ class DeprecationErrorHandler
|
||||
return \call_user_func(self::getPhpUnitErrorHandler(), $type, $msg, $file, $line, $context);
|
||||
}
|
||||
|
||||
$deprecation = new Deprecation($msg, debug_backtrace(), $file);
|
||||
$trace = debug_backtrace();
|
||||
|
||||
if (isset($trace[1]['function'], $trace[1]['args'][0]) && ('trigger_error' === $trace[1]['function'] || 'user_error' === $trace[1]['function'])) {
|
||||
$msg = $trace[1]['args'][0];
|
||||
}
|
||||
|
||||
$deprecation = new Deprecation($msg, $trace, $file);
|
||||
if ($deprecation->isMuted()) {
|
||||
return null;
|
||||
}
|
||||
if ($this->getConfiguration()->isBaselineDeprecation($deprecation)) {
|
||||
return null;
|
||||
}
|
||||
$group = 'other';
|
||||
|
||||
if ($deprecation->originatesFromAnObject()) {
|
||||
$class = $deprecation->originatingClass();
|
||||
$method = $deprecation->originatingMethod();
|
||||
$msg = $deprecation->getMessage();
|
||||
|
||||
if (error_reporting() & $type) {
|
||||
@ -157,11 +159,13 @@ class DeprecationErrorHandler
|
||||
|
||||
exit(1);
|
||||
}
|
||||
if ('legacy' !== $group) {
|
||||
$this->deprecationGroups[$group]->addNoticeFromObject($msg, $class, $method);
|
||||
} else {
|
||||
|
||||
if ('legacy' === $group) {
|
||||
$this->deprecationGroups[$group]->addNotice();
|
||||
}
|
||||
} else if ($deprecation->originatesFromAnObject()) {
|
||||
$class = $deprecation->originatingClass();
|
||||
$method = $deprecation->originatingMethod();
|
||||
$this->deprecationGroups[$group]->addNoticeFromObject($msg, $class, $method);
|
||||
} else {
|
||||
$this->deprecationGroups[$group]->addNoticeFromProceduralCode($msg);
|
||||
}
|
||||
|
@ -60,25 +60,33 @@ class Deprecation
|
||||
}
|
||||
|
||||
$this->trace = $trace;
|
||||
|
||||
if ('trigger_error' === ($trace[1]['function'] ?? null)
|
||||
&& (DebugClassLoader::class === ($class = $trace[2]['class'] ?? null) || LegacyDebugClassLoader::class === $class)
|
||||
&& 'checkClass' === ($trace[2]['function'] ?? null)
|
||||
&& null !== ($extraFile = $trace[2]['args'][1] ?? null)
|
||||
&& '' !== $extraFile
|
||||
&& false !== $extraFile = realpath($extraFile)
|
||||
) {
|
||||
$this->getOriginalFilesStack();
|
||||
array_splice($this->originalFilesStack, 2, 1, $extraFile);
|
||||
}
|
||||
|
||||
$this->message = $message;
|
||||
$i = \count($this->trace);
|
||||
while (1 < $i && $this->lineShouldBeSkipped($this->trace[--$i])) {
|
||||
|
||||
$i = \count($trace);
|
||||
while (1 < $i && $this->lineShouldBeSkipped($trace[--$i])) {
|
||||
// No-op
|
||||
}
|
||||
$line = $this->trace[$i];
|
||||
|
||||
$line = $trace[$i];
|
||||
$this->triggeringFile = $file;
|
||||
|
||||
for ($j = 1; $j < $i; ++$j) {
|
||||
if (!isset($trace[$j]['function'], $trace[1 + $j]['class'], $trace[1 + $j]['args'][0])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ('trigger_error' === $trace[$j]['function'] && !isset($trace[$j]['class'])) {
|
||||
if (\in_array($trace[1 + $j]['class'], [DebugClassLoader::class, LegacyDebugClassLoader::class], true)) {
|
||||
$class = $trace[1 + $j]['args'][0];
|
||||
$this->triggeringFile = isset($trace[1 + $j]['args'][1]) ? realpath($trace[1 + $j]['args'][1]) : (new \ReflectionClass($class))->getFileName();
|
||||
$this->getOriginalFilesStack();
|
||||
array_splice($this->originalFilesStack, 0, $j, [$this->triggeringFile]);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($line['object']) || isset($line['class'])) {
|
||||
set_error_handler(function () {});
|
||||
$parsedMsg = unserialize($this->message);
|
||||
@ -101,12 +109,19 @@ class Deprecation
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($line['class']) && 0 === strpos($line['class'], SymfonyTestsListenerFor::class)) {
|
||||
if (!isset($line['class'], $trace[$i - 2]['function']) || 0 !== strpos($line['class'], SymfonyTestsListenerFor::class)) {
|
||||
$this->originClass = isset($line['object']) ? \get_class($line['object']) : $line['class'];
|
||||
$this->originMethod = $line['function'];
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->originClass = isset($line['object']) ? \get_class($line['object']) : $line['class'];
|
||||
$this->originMethod = $line['function'];
|
||||
if ('trigger_error' !== $trace[$i - 2]['function'] || isset($trace[$i - 2]['class'])) {
|
||||
$this->originClass = \get_class($line['args'][0]);
|
||||
$this->originMethod = $line['args'][0]->getName();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -140,7 +155,9 @@ class Deprecation
|
||||
throw new \LogicException('Check with originatesFromAnObject() before calling this method.');
|
||||
}
|
||||
|
||||
return $this->originClass;
|
||||
$class = $this->originClass;
|
||||
|
||||
return false !== strpos($class, "@anonymous\0") ? (get_parent_class($class) ?: key(class_implements($class)) ?: 'class').'@anonymous' : $class;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -168,8 +185,7 @@ class Deprecation
|
||||
*/
|
||||
public function isLegacy()
|
||||
{
|
||||
$class = $this->originatingClass();
|
||||
if ((new \ReflectionClass($class))->isInternal()) {
|
||||
if (!$this->originClass || (new \ReflectionClass($this->originClass))->isInternal()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -178,8 +194,8 @@ class Deprecation
|
||||
return 0 === strpos($method, 'testLegacy')
|
||||
|| 0 === strpos($method, 'provideLegacy')
|
||||
|| 0 === strpos($method, 'getLegacy')
|
||||
|| strpos($class, '\Legacy')
|
||||
|| \in_array('legacy', Test::getGroups($class, $method), true);
|
||||
|| strpos($this->originClass, '\Legacy')
|
||||
|| \in_array('legacy', Test::getGroups($this->originClass, $method), true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -205,11 +221,10 @@ class Deprecation
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
$triggeringFilePathType = $this->getPathType($this->triggeringFile);
|
||||
if (self::PATH_TYPE_SELF === $triggeringFilePathType) {
|
||||
if (self::PATH_TYPE_SELF === $pathType = $this->getPathType($this->triggeringFile)) {
|
||||
return self::TYPE_SELF;
|
||||
}
|
||||
if (self::PATH_TYPE_UNDETERMINED === $triggeringFilePathType) {
|
||||
if (self::PATH_TYPE_UNDETERMINED === $pathType) {
|
||||
return self::TYPE_UNDETERMINED;
|
||||
}
|
||||
$erroringFile = $erroringPackage = null;
|
||||
@ -218,10 +233,10 @@ class Deprecation
|
||||
if ('-' === $file || 'Standard input code' === $file || !realpath($file)) {
|
||||
continue;
|
||||
}
|
||||
if (self::PATH_TYPE_SELF === $this->getPathType($file)) {
|
||||
if (self::PATH_TYPE_SELF === $pathType = $this->getPathType($file)) {
|
||||
return self::TYPE_DIRECT;
|
||||
}
|
||||
if (self::PATH_TYPE_UNDETERMINED === $this->getPathType($file)) {
|
||||
if (self::PATH_TYPE_UNDETERMINED === $pathType) {
|
||||
return self::TYPE_UNDETERMINED;
|
||||
}
|
||||
if (null !== $erroringFile && null !== $erroringPackage) {
|
||||
@ -243,7 +258,7 @@ class Deprecation
|
||||
if (null === $this->originalFilesStack) {
|
||||
$this->originalFilesStack = [];
|
||||
foreach ($this->trace as $frame) {
|
||||
if (!isset($frame['file']) || \in_array($frame['function'], ['require', 'require_once', 'include', 'include_once'], true)) {
|
||||
if (!isset($frame['file'], $frame['function']) || (!isset($frame['class']) && \in_array($frame['function'], ['require', 'require_once', 'include', 'include_once'], true))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -269,13 +284,10 @@ class Deprecation
|
||||
$relativePath = substr($path, \strlen($vendorRoot) + 1);
|
||||
$vendor = strstr($relativePath, \DIRECTORY_SEPARATOR, true);
|
||||
if (false === $vendor) {
|
||||
throw new \RuntimeException(sprintf('Could not find directory separator "%s" in path "%s".', \DIRECTORY_SEPARATOR, $relativePath));
|
||||
return 'symfony';
|
||||
}
|
||||
|
||||
return rtrim($vendor.'/'.strstr(substr(
|
||||
$relativePath,
|
||||
\strlen($vendor) + 1
|
||||
), \DIRECTORY_SEPARATOR, true), '/');
|
||||
return rtrim($vendor.'/'.strstr(substr($relativePath, \strlen($vendor) + 1), \DIRECTORY_SEPARATOR, true), '/');
|
||||
}
|
||||
}
|
||||
|
||||
@ -289,6 +301,13 @@ class Deprecation
|
||||
{
|
||||
if (null === self::$vendors) {
|
||||
self::$vendors = $paths = [];
|
||||
self::$vendors[] = \dirname(__DIR__).\DIRECTORY_SEPARATOR.'Legacy';
|
||||
if (class_exists(DebugClassLoader::class, false)) {
|
||||
self::$vendors[] = \dirname((new \ReflectionClass(DebugClassLoader::class))->getFileName());
|
||||
}
|
||||
if (class_exists(LegacyDebugClassLoader::class, false)) {
|
||||
self::$vendors[] = \dirname((new \ReflectionClass(LegacyDebugClassLoader::class))->getFileName());
|
||||
}
|
||||
foreach (get_declared_classes() as $class) {
|
||||
if ('C' === $class[0] && 0 === strpos($class, 'ComposerAutoloaderInit')) {
|
||||
$r = new \ReflectionClass($class);
|
||||
@ -364,10 +383,9 @@ class Deprecation
|
||||
$reflection->setAccessible(true);
|
||||
$reflection->setValue($exception, $this->trace);
|
||||
|
||||
return 'deprecation triggered by '.$this->originatingClass().'::'.$this->originatingMethod().':'.
|
||||
"\n".$this->message.
|
||||
"\nStack trace:".
|
||||
"\n".str_replace(' '.getcwd().\DIRECTORY_SEPARATOR, ' ', $exception->getTraceAsString()).
|
||||
"\n";
|
||||
return ($this->originatesFromAnObject() ? 'deprecation triggered by '.$this->originatingClass().'::'.$this->originatingMethod().":\n" : '')
|
||||
.$this->message."\n"
|
||||
."Stack trace:\n"
|
||||
.str_replace(' '.getcwd().\DIRECTORY_SEPARATOR, ' ', $exception->getTraceAsString())."\n";
|
||||
}
|
||||
}
|
||||
|
@ -183,6 +183,11 @@ class DeprecationTest extends TestCase
|
||||
public function providerGetTypeUsesRightTrace()
|
||||
{
|
||||
$vendorDir = self::getVendorDir();
|
||||
$fakeTrace = [
|
||||
['function' => 'trigger_error'],
|
||||
['class' => SymfonyTestsListenerTrait::class, 'function' => 'endTest'],
|
||||
['class' => SymfonyTestsListenerForV7::class, 'function' => 'endTest'],
|
||||
];
|
||||
|
||||
return [
|
||||
'no_file_in_stack' => [Deprecation::TYPE_DIRECT, '', [['function' => 'myfunc1'], ['function' => 'myfunc2']]],
|
||||
@ -205,7 +210,7 @@ class DeprecationTest extends TestCase
|
||||
$vendorDir.'/myfakevendor/myfakepackage1/MyFakeFile2.php',
|
||||
],
|
||||
]),
|
||||
[['function' => 'myfunc1'], ['class' => SymfonyTestsListenerForV7::class, 'method' => 'mymethod']],
|
||||
$fakeTrace,
|
||||
],
|
||||
'serialized_stack_files_from_various_packages' => [
|
||||
Deprecation::TYPE_INDIRECT,
|
||||
@ -218,7 +223,7 @@ class DeprecationTest extends TestCase
|
||||
$vendorDir.'/myfakevendor/myfakepackage2/MyFakeFile.php',
|
||||
],
|
||||
]),
|
||||
[['function' => 'myfunc1'], ['class' => SymfonyTestsListenerForV7::class, 'method' => 'mymethod']],
|
||||
$fakeTrace,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
@ -30,16 +30,6 @@ EOPHP
|
||||
);
|
||||
require __DIR__.'/fake_vendor/autoload.php';
|
||||
|
||||
// We need the real DebugClassLoader FQCN but in a vendor path.
|
||||
if (!file_exists($errorHandlerRootDir = __DIR__.'/../../../../Component/ErrorHandler')) {
|
||||
if (!file_exists($errorHandlerRootDir = __DIR__.'/../../vendor/symfony/error-handler')) {
|
||||
die('Could not find the ErrorHandler component root directory.');
|
||||
}
|
||||
}
|
||||
|
||||
file_put_contents($fakeDebugClassLoadPath = __DIR__.'/fake_vendor/symfony/error-handler/DebugClassLoader.php', file_get_contents($errorHandlerRootDir.'/DebugClassLoader.php'));
|
||||
require $fakeDebugClassLoadPath;
|
||||
|
||||
\Symfony\Component\ErrorHandler\DebugClassLoader::enable();
|
||||
new \App\Services\BarService();
|
||||
|
||||
|
@ -29,13 +29,11 @@ Unsilenced deprecation notices (3)
|
||||
1x: unsilenced bar deprecation
|
||||
1x in FooTestCase::testNonLegacyBar
|
||||
|
||||
Remaining direct deprecation notices (1)
|
||||
Remaining direct deprecation notices (2)
|
||||
|
||||
1x: root deprecation
|
||||
|
||||
1x: silenced bar deprecation
|
||||
1x in FooTestCase::testNonLegacyBar
|
||||
|
||||
Legacy deprecation notices (2)
|
||||
|
||||
Other deprecation notices (1)
|
||||
|
||||
1x: root deprecation
|
||||
|
@ -10,7 +10,7 @@
|
||||
*/
|
||||
|
||||
// Please update when phpunit needs to be reinstalled with fresh deps:
|
||||
// Cache-Id: 2020-01-31 10:00 UTC
|
||||
// Cache-Id: 2021-02-04 11:00 UTC
|
||||
|
||||
error_reporting(-1);
|
||||
|
||||
|
@ -40,7 +40,7 @@ class ExpressionCacheWarmer implements CacheWarmerInterface
|
||||
public function warmUp(string $cacheDir)
|
||||
{
|
||||
foreach ($this->expressions as $expression) {
|
||||
$this->expressionLanguage->parse($expression, ['token', 'user', 'object', 'subject', 'roles', 'request', 'trust_resolver']);
|
||||
$this->expressionLanguage->parse($expression, ['token', 'user', 'object', 'subject', 'role_names', 'request', 'trust_resolver']);
|
||||
}
|
||||
|
||||
return [];
|
||||
|
@ -26,8 +26,8 @@ class ExpressionCacheWarmerTest extends TestCase
|
||||
$expressionLang->expects($this->exactly(2))
|
||||
->method('parse')
|
||||
->withConsecutive(
|
||||
[$expressions[0], ['token', 'user', 'object', 'subject', 'roles', 'request', 'trust_resolver']],
|
||||
[$expressions[1], ['token', 'user', 'object', 'subject', 'roles', 'request', 'trust_resolver']]
|
||||
[$expressions[0], ['token', 'user', 'object', 'subject', 'role_names', 'request', 'trust_resolver']],
|
||||
[$expressions[1], ['token', 'user', 'object', 'subject', 'role_names', 'request', 'trust_resolver']]
|
||||
);
|
||||
|
||||
(new ExpressionCacheWarmer($expressions, $expressionLang))->warmUp('');
|
||||
|
@ -534,7 +534,7 @@ class DebugClassLoader
|
||||
if (null !== (self::INTERNAL_TYPES[$use] ?? null)) {
|
||||
foreach (self::INTERNAL_TYPES[$use] as $method => $returnType) {
|
||||
if ('void' !== $returnType) {
|
||||
self::$returnTypes[$class] += [$method => [$returnType, $returnType, $class, '']];
|
||||
self::$returnTypes[$class] += [$method => [$returnType, $returnType, $use, '']];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -611,7 +611,7 @@ class DebugClassLoader
|
||||
$this->patchMethod($method, $returnType, $declaringFile, $normalizedType);
|
||||
}
|
||||
|
||||
if (strncmp($ns, $declaringClass, $len)) {
|
||||
if (false === strpos($doc, '@deprecated') && strncmp($ns, $declaringClass, $len)) {
|
||||
if ($canAddReturnType && 'docblock' === $this->patchTypes['force'] && false === strpos($method->getFileName(), \DIRECTORY_SEPARATOR.'vendor'.\DIRECTORY_SEPARATOR)) {
|
||||
$this->patchMethod($method, $returnType, $declaringFile, $normalizedType);
|
||||
} elseif ('' !== $declaringClass && $this->patchTypes['deprecations']) {
|
||||
|
@ -428,11 +428,7 @@ class ErrorHandler
|
||||
return false;
|
||||
}
|
||||
|
||||
if (false !== strpos($message, "@anonymous\0")) {
|
||||
$logMessage = $this->parseAnonymousClass($message);
|
||||
} else {
|
||||
$logMessage = $this->levels[$type].': '.$message;
|
||||
}
|
||||
|
||||
if (null !== self::$toStringException) {
|
||||
$errorAsException = self::$toStringException;
|
||||
@ -461,6 +457,23 @@ class ErrorHandler
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (false !== strpos($message, '@anonymous')) {
|
||||
$backtrace = debug_backtrace(false, 5);
|
||||
|
||||
for ($i = 1; isset($backtrace[$i]); ++$i) {
|
||||
if (isset($backtrace[$i]['function'], $backtrace[$i]['args'][0])
|
||||
&& ('trigger_error' === $backtrace[$i]['function'] || 'user_error' === $backtrace[$i]['function'])
|
||||
) {
|
||||
if ($backtrace[$i]['args'][0] !== $message) {
|
||||
$message = $this->parseAnonymousClass($backtrace[$i]['args'][0]);
|
||||
$logMessage = $this->levels[$type].': '.$message;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$errorAsException = new \ErrorException($logMessage, 0, $type, $file, $line);
|
||||
|
||||
if ($throw || $this->tracedErrors & $type) {
|
||||
|
@ -368,11 +368,12 @@ class ErrorHandlerTest extends TestCase
|
||||
|
||||
public function testHandleErrorWithAnonymousClass()
|
||||
{
|
||||
$anonymousObject = new class() extends \stdClass {
|
||||
};
|
||||
|
||||
$handler = ErrorHandler::register();
|
||||
$handler->throwAt(3, true);
|
||||
try {
|
||||
$handler->handleError(3, 'foo '.\get_class(new class() extends \stdClass {
|
||||
}).' bar', 'foo.php', 12);
|
||||
trigger_error('foo '.\get_class($anonymousObject).' bar', \E_USER_WARNING);
|
||||
$this->fail('Exception expected.');
|
||||
} catch (\ErrorException $e) {
|
||||
} finally {
|
||||
@ -380,10 +381,7 @@ class ErrorHandlerTest extends TestCase
|
||||
restore_exception_handler();
|
||||
}
|
||||
|
||||
$this->assertSame('foo stdClass@anonymous bar', $e->getMessage());
|
||||
$this->assertSame(3, $e->getSeverity());
|
||||
$this->assertSame('foo.php', $e->getFile());
|
||||
$this->assertSame(12, $e->getLine());
|
||||
$this->assertSame('User Warning: foo stdClass@anonymous bar', $e->getMessage());
|
||||
}
|
||||
|
||||
public function testHandleDeprecation()
|
||||
|
@ -127,7 +127,7 @@ class RetryableHttpClient implements HttpClientInterface
|
||||
|
||||
$context->getResponse()->cancel();
|
||||
|
||||
$delay = $this->getDelayFromHeader($context->getHeaders()) ?? $this->strategy->getDelay($context, $chunk->isLast() ? $content : null, $exception);
|
||||
$delay = $this->getDelayFromHeader($context->getHeaders()) ?? $this->strategy->getDelay($context, !$exception && $chunk->isLast() ? $content : null, $exception);
|
||||
++$retryCount;
|
||||
|
||||
$this->logger->info('Try #{count} after {delay}ms'.($exception ? ': '.$exception->getMessage() : ', status code: '.$context->getStatusCode()), [
|
||||
|
@ -5,6 +5,7 @@ namespace Symfony\Component\HttpClient\Tests;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpClient\Exception\ServerException;
|
||||
use Symfony\Component\HttpClient\MockHttpClient;
|
||||
use Symfony\Component\HttpClient\NativeHttpClient;
|
||||
use Symfony\Component\HttpClient\Response\AsyncContext;
|
||||
use Symfony\Component\HttpClient\Response\MockResponse;
|
||||
use Symfony\Component\HttpClient\Retry\GenericRetryStrategy;
|
||||
@ -133,4 +134,29 @@ class RetryableHttpClientTest extends TestCase
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function testRetryWithDnsIssue()
|
||||
{
|
||||
$client = new RetryableHttpClient(
|
||||
new NativeHttpClient(),
|
||||
new class(GenericRetryStrategy::DEFAULT_RETRY_STATUS_CODES, 0) extends GenericRetryStrategy {
|
||||
public function shouldRetry(AsyncContext $context, ?string $responseContent, ?TransportExceptionInterface $exception): ?bool
|
||||
{
|
||||
$this->fail('should not be called');
|
||||
}
|
||||
},
|
||||
2,
|
||||
$logger = new TestLogger()
|
||||
);
|
||||
|
||||
$response = $client->request('GET', 'http://does.not.exists/foo-bar');
|
||||
|
||||
try {
|
||||
$response->getHeaders();
|
||||
} catch (TransportExceptionInterface $e) {
|
||||
$this->assertSame('Could not resolve host "does.not.exists".', $e->getMessage());
|
||||
}
|
||||
$this->assertCount(2, $logger->logs);
|
||||
$this->assertSame('Try #{count} after {delay}ms: Could not resolve host "does.not.exists".', $logger->logs[0]);
|
||||
}
|
||||
}
|
||||
|
@ -233,12 +233,12 @@ class SerializableUser implements UserInterface, \Serializable
|
||||
return null;
|
||||
}
|
||||
|
||||
public function serialize()
|
||||
public function serialize(): string
|
||||
{
|
||||
return serialize($this->name);
|
||||
}
|
||||
|
||||
public function unserialize($serialized)
|
||||
public function unserialize($serialized): void
|
||||
{
|
||||
$this->name = unserialize($serialized);
|
||||
}
|
||||
|
Reference in New Issue
Block a user