diff --git a/src/Symfony/Component/Cache/Traits/PdoTrait.php b/src/Symfony/Component/Cache/Traits/PdoTrait.php index 3ee1f8cf60..73f8c6465e 100644 --- a/src/Symfony/Component/Cache/Traits/PdoTrait.php +++ b/src/Symfony/Component/Cache/Traits/PdoTrait.php @@ -403,6 +403,7 @@ trait PdoTrait } else { switch ($this->driver = $this->conn->getDriver()->getName()) { case 'mysqli': + throw new \LogicException(sprintf('The adapter "%s" does not support the mysqli driver, use pdo_mysql instead.', \get_class($this))); case 'pdo_mysql': case 'drizzle_pdo_mysql': $this->driver = 'mysql'; diff --git a/src/Symfony/Component/Lock/Store/PdoStore.php b/src/Symfony/Component/Lock/Store/PdoStore.php index c2dbd622ff..bd9df9e56c 100644 --- a/src/Symfony/Component/Lock/Store/PdoStore.php +++ b/src/Symfony/Component/Lock/Store/PdoStore.php @@ -317,6 +317,7 @@ class PdoStore implements StoreInterface } else { switch ($this->driver = $con->getDriver()->getName()) { case 'mysqli': + throw new NotSupportedException(sprintf('The store "%s" does not support the mysqli driver, use pdo_mysql instead.', \get_class($this))); case 'pdo_mysql': case 'drizzle_pdo_mysql': $this->driver = 'mysql'; diff --git a/src/Symfony/Component/Messenger/Tests/Transport/Serialization/SerializerTest.php b/src/Symfony/Component/Messenger/Tests/Transport/Serialization/SerializerTest.php index ae9a76fe22..b73a3a196b 100644 --- a/src/Symfony/Component/Messenger/Tests/Transport/Serialization/SerializerTest.php +++ b/src/Symfony/Component/Messenger/Tests/Transport/Serialization/SerializerTest.php @@ -207,7 +207,40 @@ class SerializerTest extends TestCase $encoded = $serializer->encode($envelope); $this->assertStringNotContainsString('DummySymfonySerializerNonSendableStamp', print_r($encoded['headers'], true)); } + + public function testDecodingFailedConstructorDeserialization() + { + $serializer = new Serializer(); + + $this->expectException(MessageDecodingFailedException::class); + + $serializer->decode([ + 'body' => '{}', + 'headers' => ['type' => DummySymfonySerializerInvalidConstructor::class], + ]); + } + + public function testDecodingStampFailedDeserialization() + { + $serializer = new Serializer(); + + $this->expectException(MessageDecodingFailedException::class); + + $serializer->decode([ + 'body' => '{"message":"hello"}', + 'headers' => [ + 'type' => DummyMessage::class, + 'X-Message-Stamp-'.SerializerStamp::class => '[{}]', + ], + ]); + } } class DummySymfonySerializerNonSendableStamp implements NonSendableStampInterface { } +class DummySymfonySerializerInvalidConstructor +{ + public function __construct(string $missingArgument) + { + } +} diff --git a/src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php b/src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php index d5d4d74031..2b4017e946 100644 --- a/src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php +++ b/src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php @@ -85,13 +85,13 @@ class Connection // check for extra keys in options $optionsExtraKeys = array_diff(array_keys($options), array_keys(self::DEFAULT_OPTIONS)); if (0 < \count($optionsExtraKeys)) { - throw new InvalidArgumentException(sprintf('Unknown option found : [%s]. Allowed options are [%s]', implode(', ', $optionsExtraKeys), implode(', ', self::DEFAULT_OPTIONS))); + throw new InvalidArgumentException(sprintf('Unknown option found : [%s]. Allowed options are [%s]', implode(', ', $optionsExtraKeys), implode(', ', array_keys(self::DEFAULT_OPTIONS)))); } // check for extra keys in options $queryExtraKeys = array_diff(array_keys($query), array_keys(self::DEFAULT_OPTIONS)); if (0 < \count($queryExtraKeys)) { - throw new InvalidArgumentException(sprintf('Unknown option found in DSN: [%s]. Allowed options are [%s]', implode(', ', $queryExtraKeys), implode(', ', self::DEFAULT_OPTIONS))); + throw new InvalidArgumentException(sprintf('Unknown option found in DSN: [%s]. Allowed options are [%s]', implode(', ', $queryExtraKeys), implode(', ', array_keys(self::DEFAULT_OPTIONS)))); } return $configuration; diff --git a/src/Symfony/Component/Messenger/Transport/Serialization/Serializer.php b/src/Symfony/Component/Messenger/Transport/Serialization/Serializer.php index 2dfcb1bb83..8d466500fd 100644 --- a/src/Symfony/Component/Messenger/Transport/Serialization/Serializer.php +++ b/src/Symfony/Component/Messenger/Transport/Serialization/Serializer.php @@ -19,7 +19,7 @@ use Symfony\Component\Messenger\Stamp\SerializerStamp; use Symfony\Component\Messenger\Stamp\StampInterface; use Symfony\Component\Serializer\Encoder\JsonEncoder; use Symfony\Component\Serializer\Encoder\XmlEncoder; -use Symfony\Component\Serializer\Exception\UnexpectedValueException; +use Symfony\Component\Serializer\Exception\ExceptionInterface; use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer; use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; use Symfony\Component\Serializer\Serializer as SymfonySerializer; @@ -79,7 +79,7 @@ class Serializer implements SerializerInterface try { $message = $this->serializer->deserialize($encodedEnvelope['body'], $encodedEnvelope['headers']['type'], $this->format, $context); - } catch (UnexpectedValueException $e) { + } catch (ExceptionInterface $e) { throw new MessageDecodingFailedException(sprintf('Could not decode message: %s.', $e->getMessage()), $e->getCode(), $e); } @@ -117,7 +117,7 @@ class Serializer implements SerializerInterface try { $stamps[] = $this->serializer->deserialize($value, substr($name, \strlen(self::STAMP_HEADER_PREFIX)).'[]', $this->format, $this->context); - } catch (UnexpectedValueException $e) { + } catch (ExceptionInterface $e) { throw new MessageDecodingFailedException(sprintf('Could not decode stamp: %s.', $e->getMessage()), $e->getCode(), $e); } }