<?php

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

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

class TestableDeleteOperation extends DeleteOperation {
    public function getExpectedResult(): ?array { return parent::getExpectedResult(); }
}

class DeleteOperationTest extends TestCase
{
    /**
     * @see DeleteOperation::__construct()
     * @see DeleteOperation::getMethod()
     * @see DeleteOperation::getEntityName()
     * @see DeleteOperation::getPath()
     * @see DeleteOperation::__toString()
     */
    public function testGetters(): void
    {
        $operation = new DeleteOperation(
            'Delete a dinosaur',
            'dinosaur',
            1
        );

        $this->assertEquals('DELETE', $operation->getMethod());
        $this->assertEquals('dinosaur', $operation->getEntityName());
        $this->assertEquals('dinosaur/1', $operation->getPath());

        $this->assertEquals('DELETE dinosaur/1', (string)$operation);
    }

    /**
     * @see DeleteOperation::getExpectedResult()
     */
    public function testGetExpectedResult(): void {
        $operation = new TestableDeleteOperation(
            'Delete a dinosaur',
            'dinosaur',
            1
        );

        $this->assertEquals(null, $operation->getExpectedResult());
    }

    /**
     * @see DeleteOperation::getChangeLog()
     */
    public function testGetChangeLog(): void
    {
        $operation = new DeleteOperation(
            'Delete a dinosaur',
            'dinosaur',
            1
        );

        $this->assertEquals(
            ['[DELETE dinosaur/1]'],
            $operation->getChangeLog()
        );
    }

}
