<?php
namespace Tests\Unit\admin\Controllers;

use PHPUnit\Framework\TestCase;
use admin\Controllers\ShopProductSetsController;
use Domain\ProductSet\ProductSetRepository;

class ShopProductSetsControllerTest extends TestCase
{
    private $repository;
    private $controller;

    protected function setUp(): void
    {
        $this->repository = $this->createMock(ProductSetRepository::class);
        $this->controller = new ShopProductSetsController($this->repository);
    }

    public function testConstructorAcceptsRepository(): void
    {
        $controller = new ShopProductSetsController($this->repository);
        $this->assertInstanceOf(ShopProductSetsController::class, $controller);
    }

    public function testHasMainActionMethods(): void
    {
        $this->assertTrue(method_exists($this->controller, 'list'));
        $this->assertTrue(method_exists($this->controller, 'edit'));
        $this->assertTrue(method_exists($this->controller, 'save'));
        $this->assertTrue(method_exists($this->controller, 'delete'));
    }

    public function testHasLegacyAliasMethods(): void
    {
        $this->assertTrue(method_exists($this->controller, 'view_list'));
        $this->assertTrue(method_exists($this->controller, 'set_edit'));
        $this->assertTrue(method_exists($this->controller, 'set_delete'));
    }

    public function testActionMethodReturnTypes(): void
    {
        $reflection = new \ReflectionClass($this->controller);

        $this->assertEquals('string', (string)$reflection->getMethod('list')->getReturnType());
        $this->assertEquals('string', (string)$reflection->getMethod('view_list')->getReturnType());
        $this->assertEquals('string', (string)$reflection->getMethod('edit')->getReturnType());
        $this->assertEquals('string', (string)$reflection->getMethod('set_edit')->getReturnType());
        $this->assertEquals('void', (string)$reflection->getMethod('save')->getReturnType());
        $this->assertEquals('void', (string)$reflection->getMethod('delete')->getReturnType());
        $this->assertEquals('void', (string)$reflection->getMethod('set_delete')->getReturnType());
    }

    public function testConstructorRequiresProductSetRepository(): void
    {
        $reflection = new \ReflectionClass(ShopProductSetsController::class);
        $constructor = $reflection->getConstructor();
        $params = $constructor->getParameters();

        $this->assertCount(1, $params);
        $this->assertEquals('Domain\ProductSet\ProductSetRepository', $params[0]->getType()->getName());
    }
}
