ver. 0.291: ShopProducer frontend migration to Domain + Controllers

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-17 20:32:07 +01:00
parent 46ff934d42
commit 827b903e1e
19 changed files with 267 additions and 119 deletions

View File

@@ -237,4 +237,79 @@ class ProducerRepositoryTest extends TestCase
$this->assertArrayHasKey('ls', $result);
$this->assertSame(3, $result['ls']);
}
public function testAllActiveProducersReturnsFullData(): void
{
$mockDb = $this->createMock(\medoo::class);
$mockDb->expects($this->once())
->method('select')
->with('pp_shop_producer', ['id', 'name', 'img'], [
'status' => 1,
'ORDER' => ['name' => 'ASC'],
])
->willReturn([
['id' => '3', 'name' => 'Apple', 'img' => '/apple.png'],
['id' => '7', 'name' => 'Samsung', 'img' => null],
]);
$repository = new ProducerRepository($mockDb);
$result = $repository->allActiveProducers();
$this->assertCount(2, $result);
$this->assertSame(3, $result[0]['id']);
$this->assertSame('Apple', $result[0]['name']);
$this->assertSame('/apple.png', $result[0]['img']);
$this->assertSame(7, $result[1]['id']);
$this->assertSame('Samsung', $result[1]['name']);
$this->assertNull($result[1]['img']);
}
public function testAllActiveProducersReturnsEmptyOnNull(): void
{
$mockDb = $this->createMock(\medoo::class);
$mockDb->method('select')->willReturn(null);
$repository = new ProducerRepository($mockDb);
$result = $repository->allActiveProducers();
$this->assertSame([], $result);
}
public function testFindForFrontendReturnsNullForInvalidId(): void
{
$mockDb = $this->createMock(\medoo::class);
$mockDb->expects($this->never())->method('get');
$repository = new ProducerRepository($mockDb);
$this->assertNull($repository->findForFrontend(0, 'pl'));
}
public function testFindForFrontendReturnsNullWhenNotFound(): void
{
$mockDb = $this->createMock(\medoo::class);
$mockDb->method('get')->willReturn(null);
$repository = new ProducerRepository($mockDb);
$this->assertNull($repository->findForFrontend(99, 'pl'));
}
public function testFindForFrontendReturnsProducerWithLanguage(): void
{
$mockDb = $this->createMock(\medoo::class);
$mockDb->expects($this->exactly(2))
->method('get')
->willReturnOnConsecutiveCalls(
['id' => '5', 'name' => 'Sony', 'status' => '1', 'img' => '/sony.png'],
['lang_id' => 'pl', 'description' => 'Opis', 'data' => null, 'meta_title' => 'Sony PL']
);
$repository = new ProducerRepository($mockDb);
$result = $repository->findForFrontend(5, 'pl');
$this->assertSame(5, $result['id']);
$this->assertSame('Sony', $result['name']);
$this->assertArrayHasKey('pl', $result['languages']);
$this->assertSame('Sony PL', $result['languages']['pl']['meta_title']);
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace Tests\Unit\front\Controllers;
use PHPUnit\Framework\TestCase;
use front\Controllers\ShopProducerController;
use Domain\Producer\ProducerRepository;
class ShopProducerControllerTest extends TestCase
{
private $repository;
private $controller;
protected function setUp(): void
{
$this->repository = $this->createMock(ProducerRepository::class);
$this->controller = new ShopProducerController($this->repository);
}
public function testConstructorAcceptsRepository(): void
{
$controller = new ShopProducerController($this->repository);
$this->assertInstanceOf(ShopProducerController::class, $controller);
}
public function testHasMainActionMethods(): void
{
$this->assertTrue(method_exists($this->controller, 'products'));
$this->assertTrue(method_exists($this->controller, 'list'));
}
public function testConstructorRequiresProducerRepository(): void
{
$reflection = new \ReflectionClass(ShopProducerController::class);
$constructor = $reflection->getConstructor();
$params = $constructor->getParameters();
$this->assertCount(1, $params);
$this->assertEquals('Domain\Producer\ProducerRepository', $params[0]->getType()->getName());
}
}