<?php

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

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

class JaneNormalizerTest extends TestCase
{
    private JaneNormalizer $subject;

    private JsonSerializerFacadeInterface $serializer;

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

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

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

        $result = $this->subject->normalize(object: $object);

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

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

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

        $this->serializer->expects($this->once())
            ->method('normalize')
            ->with(
                data: $object,
                normalizers: [$normalizer],
            )
            ->willReturn($expected)
        ;

        $result = $subject->normalize(object: $object);

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