SerializerDataCollector example

->method('encode')
            ->with('data', 'format', $this->isType('array'))
            ->willReturn('encoded');

        $decoder = $this->createMock(DecoderInterface::class);
        $decoder
            ->expects($this->once())
            ->method('decode')
            ->with('data', 'format', $this->isType('array'))
            ->willReturn('decoded');

        $this->assertSame('encoded', (new TraceableEncoder($encodernew SerializerDataCollector()))->encode('data', 'format'));
        $this->assertSame('decoded', (new TraceableEncoder($decodernew SerializerDataCollector()))->decode('data', 'format'));
    }

    public function testCollectEncodingData()
    {
        $encoder = $this->createMock(EncoderInterface::class);
        $decoder = $this->createMock(DecoderInterface::class);

        $dataCollector = $this->createMock(SerializerDataCollector::class);
        $dataCollector
            ->expects($this->once())
            
use PHPUnit\Framework\TestCase;
use Symfony\Component\Serializer\DataCollector\SerializerDataCollector;
use Symfony\Component\Serializer\Encoder\CsvEncoder;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;

class SerializerDataCollectorTest extends TestCase
{
    public function testCollectSerialize()
    {
        $dataCollector = new SerializerDataCollector();

        $caller = ['name' => 'Foo.php', 'file' => 'src/Foo.php', 'line' => 123];
        $dataCollector->collectSerialize('traceIdOne', 'data', 'format', ['foo' => 'bar'], 1.0, $caller);
        $dataCollector->collectDeserialize('traceIdTwo', 'data', 'type', 'format', ['foo' => 'bar'], 1.0, $caller);

        $dataCollector->lateCollect();
        $collectedData = $this->castCollectedData($dataCollector->getData());

        $this->assertSame([[
            'data' => 'data',
            'dataType' => 'string',
            
->with('data', 'format', $this->isType('array'))
            ->willReturn('normalized');

        $denormalizer = $this->createMock(DenormalizerInterface::class);
        $denormalizer->method('getSupportedTypes')->willReturn(['*' => false]);
        $denormalizer
            ->expects($this->once())
            ->method('denormalize')
            ->with('data', 'type', 'format', $this->isType('array'))
            ->willReturn('denormalized');

        $this->assertSame('normalized', (new TraceableNormalizer($normalizernew SerializerDataCollector()))->normalize('data', 'format'));
        $this->assertSame('denormalized', (new TraceableNormalizer($denormalizernew SerializerDataCollector()))->denormalize('data', 'type', 'format'));
    }

    public function testCollectNormalizationData()
    {
        $normalizer = $this->createMock(NormalizerInterface::class);
        $normalizer->method('getSupportedTypes')->willReturn(['*' => false]);
        $denormalizer = $this->createMock(DenormalizerInterface::class);
        $denormalizer->method('getSupportedTypes')->willReturn(['*' => false]);

        $dataCollector = $this->createMock(SerializerDataCollector::class);
        
$serializer
            ->expects($this->once())
            ->method('encode')
            ->with('data', 'format', $this->isType('array'))
            ->willReturn('encoded');
        $serializer
            ->expects($this->once())
            ->method('decode')
            ->with('data', 'format', $this->isType('array'))
            ->willReturn('decoded');

        $traceableSerializer = new TraceableSerializer($serializernew SerializerDataCollector());

        $this->assertSame('serialized', $traceableSerializer->serialize('data', 'format'));
        $this->assertSame('deserialized', $traceableSerializer->deserialize('data', 'type', 'format'));
        $this->assertSame('normalized', $traceableSerializer->normalize('data', 'format'));
        $this->assertSame('denormalized', $traceableSerializer->denormalize('data', 'type', 'format'));
        $this->assertSame('encoded', $traceableSerializer->encode('data', 'format'));
        $this->assertSame('decoded', $traceableSerializer->decode('data', 'format'));
    }

    public function testCollectData()
    {
        
Home | Imprint | This part of the site doesn't use cookies.