ver. 0.277: ShopProduct factory, Dashboard, Update migration, legacy cleanup, admin\App

- ShopProduct factory: full migration (~40 ProductRepository methods, ~30 controller actions)
- Dashboard: Domain+DI migration (DashboardRepository + DashboardController)
- Update: Domain+DI migration (UpdateRepository + UpdateController, template rewrite)
- Renamed admin\Site to admin\App, removed dead fallback routing
- Removed all legacy folders: admin/controls, admin/factory, admin/view
- Newsletter: switched from admin\factory\Articles to ArticleRepository
- 414 tests, 1335 assertions passing

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-16 01:06:29 +01:00
parent be93a7e330
commit 74343b0f33
51 changed files with 4960 additions and 5403 deletions

View File

@@ -0,0 +1,89 @@
<?php
namespace Tests\Unit\Domain\Dashboard;
use PHPUnit\Framework\TestCase;
use Domain\Dashboard\DashboardRepository;
class DashboardRepositoryTest extends TestCase
{
private function createMockDb(): \medoo
{
return $this->createMock(\medoo::class);
}
public function testConstructorAcceptsDb(): void
{
$db = $this->createMockDb();
$repository = new DashboardRepository($db);
$this->assertInstanceOf(DashboardRepository::class, $repository);
}
public function testHasAllPublicMethods(): void
{
$db = $this->createMockDb();
$repository = new DashboardRepository($db);
$expectedMethods = [
'summaryOrders',
'summarySales',
'salesGrid',
'mostViewedProducts',
'bestSalesProducts',
'last24MonthsSales',
'lastOrders',
];
foreach ($expectedMethods as $method) {
$this->assertTrue(
method_exists($repository, $method),
"Missing method: {$method}"
);
}
}
public function testSalesGridReturnsArray(): void
{
$db = $this->createMockDb();
$db->method('select')->willReturn([]);
$repository = new DashboardRepository($db);
$result = $repository->salesGrid();
$this->assertIsArray($result);
}
public function testLastOrdersReturnsArray(): void
{
$db = $this->createMockDb();
$stmt = $this->createMock(\PDOStatement::class);
$stmt->method('fetchAll')->willReturn([]);
$db->method('query')->willReturn($stmt);
$repository = new DashboardRepository($db);
$result = $repository->lastOrders();
$this->assertIsArray($result);
}
public function testMostViewedProductsReturnsArray(): void
{
$db = $this->createMockDb();
$stmt = $this->createMock(\PDOStatement::class);
$stmt->method('fetchAll')->willReturn([]);
$db->method('query')->willReturn($stmt);
$repository = new DashboardRepository($db);
$result = $repository->mostViewedProducts();
$this->assertIsArray($result);
}
public function testBestSalesProductsReturnsArray(): void
{
$db = $this->createMockDb();
$stmt = $this->createMock(\PDOStatement::class);
$stmt->method('fetchAll')->willReturn([]);
$db->method('query')->willReturn($stmt);
$repository = new DashboardRepository($db);
$result = $repository->bestSalesProducts();
$this->assertIsArray($result);
}
}

View File

@@ -0,0 +1,80 @@
<?php
namespace Tests\Unit\Domain\Update;
use PHPUnit\Framework\TestCase;
use Domain\Update\UpdateRepository;
class UpdateRepositoryTest extends TestCase
{
private function createMockDb(): \medoo
{
return $this->createMock(\medoo::class);
}
public function testConstructorAcceptsDb(): void
{
$db = $this->createMockDb();
$repository = new UpdateRepository($db);
$this->assertInstanceOf(UpdateRepository::class, $repository);
}
public function testHasUpdateMethod(): void
{
$db = $this->createMockDb();
$repository = new UpdateRepository($db);
$this->assertTrue(method_exists($repository, 'update'));
}
public function testUpdateReturnsArray(): void
{
$db = $this->createMockDb();
$repository = new UpdateRepository($db);
$reflection = new \ReflectionClass($repository);
$method = $reflection->getMethod('update');
$this->assertEquals('array', (string)$method->getReturnType());
}
public function testHasRunPendingMigrationsMethod(): void
{
$db = $this->createMockDb();
$repository = new UpdateRepository($db);
$this->assertTrue(method_exists($repository, 'runPendingMigrations'));
}
public function testRunPendingMigrationsWithNoResults(): void
{
$db = $this->createMockDb();
$db->method('select')->willReturn(false);
$repository = new UpdateRepository($db);
$repository->runPendingMigrations();
$this->assertTrue(true); // No exception thrown
}
public function testHasPrivateHelperMethods(): void
{
$reflection = new \ReflectionClass(UpdateRepository::class);
$privateMethods = [
'downloadAndApply',
'executeSql',
'deleteFiles',
'extractZip',
'saveLog',
];
foreach ($privateMethods as $methodName) {
$this->assertTrue(
$reflection->hasMethod($methodName),
"Missing private method: {$methodName}"
);
$method = $reflection->getMethod($methodName);
$this->assertTrue(
$method->isPrivate(),
"Method {$methodName} should be private"
);
}
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace Tests\Unit\admin\Controllers;
use PHPUnit\Framework\TestCase;
use admin\Controllers\DashboardController;
use Domain\Dashboard\DashboardRepository;
use Domain\ShopStatus\ShopStatusRepository;
class DashboardControllerTest extends TestCase
{
private $repository;
private $statusesRepository;
private $controller;
protected function setUp(): void
{
$this->repository = $this->createMock(DashboardRepository::class);
$this->statusesRepository = $this->createMock(ShopStatusRepository::class);
$this->controller = new DashboardController($this->repository, $this->statusesRepository);
}
public function testConstructorAcceptsRepositories(): void
{
$controller = new DashboardController($this->repository, $this->statusesRepository);
$this->assertInstanceOf(DashboardController::class, $controller);
}
public function testHasMainViewMethod(): void
{
$this->assertTrue(method_exists($this->controller, 'main_view'));
}
public function testMainViewReturnsString(): void
{
$reflection = new \ReflectionClass($this->controller);
$this->assertEquals('string', (string)$reflection->getMethod('main_view')->getReturnType());
}
public function testConstructorRequiresRepositories(): void
{
$reflection = new \ReflectionClass(DashboardController::class);
$constructor = $reflection->getConstructor();
$params = $constructor->getParameters();
$this->assertCount(2, $params);
$this->assertEquals('Domain\Dashboard\DashboardRepository', $params[0]->getType()->getName());
$this->assertEquals('Domain\ShopStatus\ShopStatusRepository', $params[1]->getType()->getName());
}
}

View File

@@ -4,21 +4,24 @@ namespace Tests\Unit\admin\Controllers;
use PHPUnit\Framework\TestCase;
use admin\Controllers\ShopProductController;
use Domain\Product\ProductRepository;
use Domain\Integrations\IntegrationsRepository;
class ShopProductControllerTest extends TestCase
{
private $repository;
private $integrationsRepository;
private $controller;
protected function setUp(): void
{
$this->repository = $this->createMock(ProductRepository::class);
$this->controller = new ShopProductController($this->repository);
$this->integrationsRepository = $this->createMock(IntegrationsRepository::class);
$this->controller = new ShopProductController($this->repository, $this->integrationsRepository);
}
public function testConstructorAcceptsRepository(): void
public function testConstructorAcceptsRepositories(): void
{
$controller = new ShopProductController($this->repository);
$controller = new ShopProductController($this->repository, $this->integrationsRepository);
$this->assertInstanceOf(ShopProductController::class, $controller);
}
@@ -29,6 +32,55 @@ class ShopProductControllerTest extends TestCase
$this->assertTrue(method_exists($this->controller, 'get_products_by_category'));
}
public function testHasViewListMethods(): void
{
$this->assertTrue(method_exists($this->controller, 'view_list'));
}
public function testHasEditAndSaveMethods(): void
{
$this->assertTrue(method_exists($this->controller, 'product_edit'));
$this->assertTrue(method_exists($this->controller, 'save'));
}
public function testHasOperationMethods(): void
{
$this->assertTrue(method_exists($this->controller, 'duplicate_product'));
$this->assertTrue(method_exists($this->controller, 'product_archive'));
$this->assertTrue(method_exists($this->controller, 'product_unarchive'));
$this->assertTrue(method_exists($this->controller, 'product_delete'));
$this->assertTrue(method_exists($this->controller, 'change_product_status'));
$this->assertTrue(method_exists($this->controller, 'product_change_price_brutto'));
$this->assertTrue(method_exists($this->controller, 'product_change_price_brutto_promo'));
$this->assertTrue(method_exists($this->controller, 'product_change_custom_label'));
$this->assertTrue(method_exists($this->controller, 'product_custom_label_suggestions'));
$this->assertTrue(method_exists($this->controller, 'product_custom_label_save'));
$this->assertTrue(method_exists($this->controller, 'ajax_product_url'));
$this->assertTrue(method_exists($this->controller, 'generate_sku_code'));
}
public function testHasCombinationMethods(): void
{
$this->assertTrue(method_exists($this->controller, 'product_combination'));
$this->assertTrue(method_exists($this->controller, 'generate_combination'));
$this->assertTrue(method_exists($this->controller, 'delete_combination'));
$this->assertTrue(method_exists($this->controller, 'delete_combination_ajax'));
$this->assertTrue(method_exists($this->controller, 'product_combination_stock_0_buy_save'));
$this->assertTrue(method_exists($this->controller, 'product_combination_sku_save'));
$this->assertTrue(method_exists($this->controller, 'product_combination_quantity_save'));
$this->assertTrue(method_exists($this->controller, 'product_combination_price_save'));
}
public function testHasImageAndFileMethods(): void
{
$this->assertTrue(method_exists($this->controller, 'image_delete'));
$this->assertTrue(method_exists($this->controller, 'images_order_save'));
$this->assertTrue(method_exists($this->controller, 'image_alt_change'));
$this->assertTrue(method_exists($this->controller, 'product_file_delete'));
$this->assertTrue(method_exists($this->controller, 'product_file_name_change'));
$this->assertTrue(method_exists($this->controller, 'product_image_delete'));
}
public function testMassEditReturnsString(): void
{
$reflection = new \ReflectionClass($this->controller);
@@ -47,13 +99,48 @@ class ShopProductControllerTest extends TestCase
$this->assertEquals('void', (string)$reflection->getMethod('get_products_by_category')->getReturnType());
}
public function testConstructorRequiresProductRepository(): void
public function testConstructorRequiresRepositories(): void
{
$reflection = new \ReflectionClass(ShopProductController::class);
$constructor = $reflection->getConstructor();
$params = $constructor->getParameters();
$this->assertCount(1, $params);
$this->assertCount(2, $params);
$this->assertEquals('Domain\Product\ProductRepository', $params[0]->getType()->getName());
$this->assertEquals('Domain\Integrations\IntegrationsRepository', $params[1]->getType()->getName());
}
public function testHasFormBuildingHelpers(): void
{
$reflection = new \ReflectionClass(ShopProductController::class);
$expectedPrivate = [
'buildProductFormViewModel',
'renderSkuField',
'renderCategoriesTree',
'renderGalleryBox',
'renderFilesBox',
'renderRelatedProducts',
'renderCustomFieldsBox',
'escapeHtml',
'resolveSavePayload',
];
foreach ($expectedPrivate as $method) {
$this->assertTrue(
$reflection->hasMethod($method),
"Missing private method: {$method}"
);
$this->assertTrue(
$reflection->getMethod($method)->isPrivate(),
"Method {$method} should be private"
);
}
}
public function testSaveMethodReturnsVoid(): void
{
$reflection = new \ReflectionClass($this->controller);
$this->assertEquals('void', (string)$reflection->getMethod('save')->getReturnType());
}
}

View File

@@ -0,0 +1,55 @@
<?php
namespace Tests\Unit\admin\Controllers;
use PHPUnit\Framework\TestCase;
use admin\Controllers\UpdateController;
use Domain\Update\UpdateRepository;
class UpdateControllerTest extends TestCase
{
private $repository;
private $controller;
protected function setUp(): void
{
$this->repository = $this->createMock(UpdateRepository::class);
$this->controller = new UpdateController($this->repository);
}
public function testConstructorAcceptsRepository(): void
{
$controller = new UpdateController($this->repository);
$this->assertInstanceOf(UpdateController::class, $controller);
}
public function testHasMainViewMethod(): void
{
$this->assertTrue(method_exists($this->controller, 'main_view'));
}
public function testMainViewReturnsString(): void
{
$reflection = new \ReflectionClass($this->controller);
$this->assertEquals('string', (string)$reflection->getMethod('main_view')->getReturnType());
}
public function testHasUpdateMethod(): void
{
$this->assertTrue(method_exists($this->controller, 'update'));
}
public function testHasUpdateAllMethod(): void
{
$this->assertTrue(method_exists($this->controller, 'updateAll'));
}
public function testConstructorRequiresRepository(): void
{
$reflection = new \ReflectionClass(UpdateController::class);
$constructor = $reflection->getConstructor();
$params = $constructor->getParameters();
$this->assertCount(1, $params);
$this->assertEquals('Domain\Update\UpdateRepository', $params[0]->getType()->getName());
}
}