<?php

namespace NoahVet\Reef\Test\A_Unit\Infrastructure\Serialization\Jane;

use NoahVet\Reef\Domain\Serialization\Json\JsonSerializerFacadeInterface;
use NoahVet\Reef\Infrastructure\Serialization\Jane\JaneDenormalizer;
use NoahVet\Reef\Jane\Normalizer\JaneObjectNormalizer;
use PHPUnit\Framework\TestCase;

class JaneDenormalizerTest extends TestCase
{
    private JaneDenormalizer $subject;

    private JsonSerializerFacadeInterface $serializer;

    protected function setUp(): void
    {
        $this->serializer = $this->createMock(JsonSerializerFacadeInterface::class);
        $this->subject = new JaneDenormalizer(serializer: $this->serializer);
    }

    public function testDenormalize(): void
    {
        $data = ['name' => 'test'];
        $expected = new \stdClass();

        $this->serializer->expects($this->once())
            ->method('denormalize')
            ->willReturn($expected)
        ;

        $result = $this->subject->denormalize(data: $data, type: \stdClass::class);

        $this->assertSame($expected, $result);
    }

    public function testDenormalizeWithJaneObjectNormalizers(): void
    {
        $normalizer = new JaneObjectNormalizer();
        $subject = new JaneDenormalizer(
            serializer: $this->serializer,
            janeObjectNormalizers: [$normalizer],
        );

        $data = ['name' => 'test'];
        $expected = new \stdClass();

        $this->serializer->expects($this->once())
            ->method('denormalize')
            ->with(
                data: $data,
                type: \stdClass::class,
                normalizers: [$normalizer],
            )
            ->willReturn($expected)
        ;

        $result = $subject->denormalize(data: $data, type: \stdClass::class);

        $this->assertSame($expected, $result);
    }
}
