Merge branch '4.2'
* 4.2: Restore previous state for libxml option fix tests Uses the SerializerStamp when deserializing the envelope
This commit is contained in:
commit
ea5ff18014
@ -62,16 +62,16 @@ class SimpleFormTest extends AbstractFormTest
|
||||
$config = new FormConfigBuilder($name, null, $this->dispatcher);
|
||||
$form = new Form($config);
|
||||
|
||||
$this->assertEquals(new PropertyPath($propertyPath), $form->getPropertyPath());
|
||||
$this->assertEquals($propertyPath, $form->getPropertyPath());
|
||||
}
|
||||
|
||||
public function provideFormNames()
|
||||
{
|
||||
yield [null, null];
|
||||
yield ['', null];
|
||||
yield ['0', '0'];
|
||||
yield [0, '0'];
|
||||
yield ['name', 'name'];
|
||||
yield ['0', new PropertyPath('0')];
|
||||
yield [0, new PropertyPath('0')];
|
||||
yield ['name', new PropertyPath('name')];
|
||||
}
|
||||
|
||||
public function testDataIsInitializedToConfiguredValue()
|
||||
|
@ -20,6 +20,7 @@ use Symfony\Component\Messenger\Tests\Fixtures\DummyMessage;
|
||||
use Symfony\Component\Messenger\Transport\Serialization\Serializer;
|
||||
use Symfony\Component\Serializer as SerializerComponent;
|
||||
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
|
||||
use Symfony\Component\Serializer\SerializerInterface as SerializerComponentInterface;
|
||||
|
||||
class SerializerTest extends TestCase
|
||||
{
|
||||
@ -75,11 +76,23 @@ class SerializerTest extends TestCase
|
||||
|
||||
public function testEncodedWithSymfonySerializerForStamps()
|
||||
{
|
||||
$serializer = new Serializer();
|
||||
$serializer = new Serializer(
|
||||
$symfonySerializer = $this->createMock(SerializerComponentInterface::class)
|
||||
);
|
||||
|
||||
$envelope = (new Envelope(new DummyMessage('Hello')))
|
||||
$envelope = (new Envelope($message = new DummyMessage('test')))
|
||||
->with($serializerStamp = new SerializerStamp([ObjectNormalizer::GROUPS => ['foo']]))
|
||||
->with($validationStamp = new ValidationStamp(['foo', 'bar']))
|
||||
->with($validationStamp = new ValidationStamp(['foo', 'bar']));
|
||||
|
||||
$symfonySerializer
|
||||
->expects($this->at(2))
|
||||
->method('serialize')->with(
|
||||
$message,
|
||||
'json',
|
||||
[
|
||||
ObjectNormalizer::GROUPS => ['foo'],
|
||||
]
|
||||
)
|
||||
;
|
||||
|
||||
$encoded = $serializer->encode($envelope);
|
||||
@ -89,11 +102,41 @@ class SerializerTest extends TestCase
|
||||
$this->assertArrayHasKey('type', $encoded['headers']);
|
||||
$this->assertArrayHasKey('X-Message-Stamp-'.SerializerStamp::class, $encoded['headers']);
|
||||
$this->assertArrayHasKey('X-Message-Stamp-'.ValidationStamp::class, $encoded['headers']);
|
||||
}
|
||||
|
||||
$decoded = $serializer->decode($encoded);
|
||||
public function testDecodeWithSymfonySerializerStamp()
|
||||
{
|
||||
$serializer = new Serializer(
|
||||
$symfonySerializer = $this->createMock(SerializerComponentInterface::class)
|
||||
);
|
||||
|
||||
$this->assertEquals($serializerStamp, $decoded->last(SerializerStamp::class));
|
||||
$this->assertEquals($validationStamp, $decoded->last(ValidationStamp::class));
|
||||
$symfonySerializer
|
||||
->expects($this->at(0))
|
||||
->method('deserialize')
|
||||
->with('[{"context":{"groups":["foo"]}}]', SerializerStamp::class.'[]', 'json', [])
|
||||
->willReturn([new SerializerStamp(['groups' => ['foo']])])
|
||||
;
|
||||
|
||||
$symfonySerializer
|
||||
->expects($this->at(1))
|
||||
->method('deserialize')->with(
|
||||
'{}',
|
||||
DummyMessage::class,
|
||||
'json',
|
||||
[
|
||||
ObjectNormalizer::GROUPS => ['foo'],
|
||||
]
|
||||
)
|
||||
->willReturn(new DummyMessage('test'))
|
||||
;
|
||||
|
||||
$serializer->decode([
|
||||
'body' => '{}',
|
||||
'headers' => [
|
||||
'type' => DummyMessage::class,
|
||||
'X-Message-Stamp-'.SerializerStamp::class => '[{"context":{"groups":["foo"]}}]',
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function testDecodingFailsWithBadFormat()
|
||||
|
@ -15,6 +15,7 @@ use Symfony\Component\Messenger\Envelope;
|
||||
use Symfony\Component\Messenger\Exception\LogicException;
|
||||
use Symfony\Component\Messenger\Exception\MessageDecodingFailedException;
|
||||
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;
|
||||
@ -70,10 +71,11 @@ class Serializer implements SerializerInterface
|
||||
}
|
||||
|
||||
$stamps = $this->decodeStamps($encodedEnvelope);
|
||||
$serializerStamp = $this->findFirstSerializerStamp($stamps);
|
||||
|
||||
$context = $this->context;
|
||||
if (isset($stamps[SerializerStamp::class])) {
|
||||
$context = end($stamps[SerializerStamp::class])->getContext() + $context;
|
||||
if (null !== $serializerStamp) {
|
||||
$context = $serializerStamp->getContext() + $context;
|
||||
}
|
||||
|
||||
try {
|
||||
@ -138,4 +140,18 @@ class Serializer implements SerializerInterface
|
||||
|
||||
return $headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param StampInterface[] $stamps
|
||||
*/
|
||||
private function findFirstSerializerStamp(array $stamps): ?SerializerStamp
|
||||
{
|
||||
foreach ($stamps as $stamp) {
|
||||
if ($stamp instanceof SerializerStamp) {
|
||||
return $stamp;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ EOF
|
||||
return ['file' => $file, 'valid' => true];
|
||||
}
|
||||
|
||||
libxml_use_internal_errors(true);
|
||||
$internal = libxml_use_internal_errors(true);
|
||||
|
||||
$document = new \DOMDocument();
|
||||
$document->loadXML($content);
|
||||
@ -143,6 +143,9 @@ EOF
|
||||
];
|
||||
}
|
||||
|
||||
libxml_clear_errors();
|
||||
libxml_use_internal_errors($internal);
|
||||
|
||||
return ['file' => $file, 'valid' => 0 === \count($errors), 'messages' => $errors];
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user