<?php

namespace App\Tests\Unit\Service\Rest\Operation;

use App\Service\Rest\Operation\CreateOperation;
use PHPUnit\Framework\TestCase;

class CreateOperationTest extends TestCase
{
    /**
     * @see CreateOperation::__construct()
     * @see CreateOperation::getMethod()
     * @see CreateOperation::getEntityName()
     * @see CreateOperation::getPath()
     * @see CreateOperation::getData()
     * @see CreateOperation::__toString()
     */
    public function testGetters(): void
    {
        $operation = new CreateOperation(
            'Create a dinosaur',
            'dinosaur',
            ['name' => 'denver']
        );

        $this->assertEquals('POST', $operation->getMethod());
        $this->assertEquals('dinosaur', $operation->getEntityName());
        $this->assertEquals('dinosaur', $operation->getPath());
        $this->assertEquals(['name' => 'denver'], $operation->getData());

        $this->assertEquals('POST dinosaur', (string)$operation);
    }

    /**
     * @see CreateOperation::getChangeLog()
     */
    public function testGetChangeLog(): void
    {
        $operation = new CreateOperation(
            'Create a dinosaur',
            'dinosaur',
            ['name' => 'denver', 'color' => 'green', 'objects' => ['glasses' => 'pink', 'guitar' => 'electric']]
        );

        $this->assertEquals(
            [
                '[POST dinosaur]',
                'name : (new) => `denver`',
                'color : (new) => `green`',
                'objects.glasses : (new) => `pink`',
                'objects.guitar : (new) => `electric`',
            ],
            $operation->getChangeLog()
        );
    }

}
