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

use PHPUnit\Framework\TestCase;
use admin\Controllers\SettingsController;
use Domain\Languages\LanguagesRepository;
use Domain\Settings\SettingsRepository;

/**
 * Testy dla SettingsController
 *
 * Kontroler używa SettingsRepository (DI).
 * Cache czyszczony bezpośrednio przez \Shared\Helpers\Helpers::delete_dir() i \Shared\Cache\RedisConnection.
 */
class SettingsControllerTest extends TestCase
{
    private $mockSettingsRepository;
    private $mockLanguagesRepository;
    private $controller;

    protected function setUp(): void
    {
        $this->mockSettingsRepository = $this->createMock(SettingsRepository::class);
        $this->mockLanguagesRepository = $this->createMock(LanguagesRepository::class);
        $this->controller = new SettingsController($this->mockSettingsRepository, $this->mockLanguagesRepository);
    }

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

    public function testHasClearCacheMethod(): void
    {
        $this->assertTrue(method_exists($this->controller, 'clearCache'));
    }

    public function testHasClearCacheAjaxMethod(): void
    {
        $this->assertTrue(method_exists($this->controller, 'clearCacheAjax'));
    }

    public function testHasSaveMethod(): void
    {
        $this->assertTrue(method_exists($this->controller, 'save'));
    }

    public function testHasViewMethod(): void
    {
        $this->assertTrue(method_exists($this->controller, 'view'));
    }

    public function testIsNotAbstract(): void
    {
        $reflection = new \ReflectionClass($this->controller);
        $this->assertFalse($reflection->isAbstract());
    }

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

        $this->assertEquals('void', (string)$reflection->getMethod('clearCache')->getReturnType());
        $this->assertEquals('void', (string)$reflection->getMethod('clearCacheAjax')->getReturnType());
        $this->assertEquals('void', (string)$reflection->getMethod('save')->getReturnType());
        $this->assertEquals('string', (string)$reflection->getMethod('view')->getReturnType());
    }
}
