Files
shopPRO/tests/Unit/admin/Controllers/LayoutsControllerTest.php

57 lines
2.2 KiB
PHP

<?php
namespace Tests\Unit\admin\Controllers;
use PHPUnit\Framework\TestCase;
use admin\Controllers\LayoutsController;
use Domain\Layouts\LayoutsRepository;
use Domain\Languages\LanguagesRepository;
class LayoutsControllerTest extends TestCase
{
private $mockRepository;
private $mockLanguagesRepository;
private $controller;
protected function setUp(): void
{
$this->mockRepository = $this->createMock(LayoutsRepository::class);
$this->mockLanguagesRepository = $this->createMock(LanguagesRepository::class);
$this->controller = new LayoutsController($this->mockRepository, $this->mockLanguagesRepository);
}
public function testConstructorAcceptsRepository(): void
{
$controller = new LayoutsController($this->mockRepository, $this->mockLanguagesRepository);
$this->assertInstanceOf(LayoutsController::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 testActionMethodReturnTypes(): void
{
$reflection = new \ReflectionClass($this->controller);
$this->assertEquals('string', (string)$reflection->getMethod('list')->getReturnType());
$this->assertEquals('string', (string)$reflection->getMethod('edit')->getReturnType());
$this->assertEquals('void', (string)$reflection->getMethod('save')->getReturnType());
$this->assertEquals('void', (string)$reflection->getMethod('delete')->getReturnType());
}
public function testConstructorRequiresLayoutsRepository(): void
{
$reflection = new \ReflectionClass(LayoutsController::class);
$constructor = $reflection->getConstructor();
$params = $constructor->getParameters();
$this->assertCount(2, $params);
$this->assertEquals('Domain\Layouts\LayoutsRepository', $params[0]->getType()->getName());
$this->assertEquals('Domain\Languages\LanguagesRepository', $params[1]->getType()->getName());
}
}