Files
shopPRO/tests/Unit/admin/Controllers/ShopTransportControllerTest.php
Jacek Pyziak 6543f8dc31 feat: Add Transport module with repository, controller, and views
- Implemented TransportRepository for managing transport data with methods for listing, finding, saving, and retrieving transport costs.
- Created ShopTransportController to handle transport-related actions, including listing, editing, and saving transports.
- Added views for transport management: transports list and transport edit forms.
- Introduced JavaScript for responsive tabs in transport edit view.
- Updated testing suite with comprehensive unit tests for TransportRepository and ShopTransportController.
- Increased test coverage with new assertions and scenarios for transport functionalities.
2026-02-14 20:16:18 +01:00

68 lines
2.5 KiB
PHP

<?php
namespace Tests\Unit\admin\Controllers;
use PHPUnit\Framework\TestCase;
use admin\Controllers\ShopTransportController;
use Domain\Transport\TransportRepository;
use Domain\PaymentMethod\PaymentMethodRepository;
class ShopTransportControllerTest extends TestCase
{
private $transportRepository;
private $paymentMethodRepository;
private $controller;
protected function setUp(): void
{
$this->transportRepository = $this->createMock(TransportRepository::class);
$this->paymentMethodRepository = $this->createMock(PaymentMethodRepository::class);
$this->controller = new ShopTransportController(
$this->transportRepository,
$this->paymentMethodRepository
);
}
public function testConstructorAcceptsRepositories(): void
{
$controller = new ShopTransportController(
$this->transportRepository,
$this->paymentMethodRepository
);
$this->assertInstanceOf(ShopTransportController::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'));
}
public function testHasNoLegacyAliasMethods(): void
{
$this->assertFalse(method_exists($this->controller, 'view_list'));
$this->assertFalse(method_exists($this->controller, 'transport_edit'));
$this->assertFalse(method_exists($this->controller, 'transport_save'));
}
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());
}
public function testConstructorRequiresBothRepositories(): void
{
$reflection = new \ReflectionClass(ShopTransportController::class);
$constructor = $reflection->getConstructor();
$params = $constructor->getParameters();
$this->assertCount(2, $params);
$this->assertEquals('Domain\Transport\TransportRepository', $params[0]->getType()->getName());
$this->assertEquals('Domain\PaymentMethod\PaymentMethodRepository', $params[1]->getType()->getName());
}
}