Files
shopPRO/tests/Unit/admin/Controllers/IntegrationsControllerTest.php
Jacek Pyziak 4f66dbe42c ver. 0.319: usunięcie shopPRO eksportu produktów + rozszerzenie API o custom_fields i security_information
- Usunięto shopproExportProduct() z IntegrationsRepository
- Usunięto shoppro_product_export() z IntegrationsController
- Usunięto przycisk "Eksportuj do shopPRO" z ShopProductController
- ProductRepository: dodano custom_fields i security_information do odpowiedzi API
- Zaktualizowano docs/API.md i testy

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-24 12:29:13 +01:00

199 lines
5.9 KiB
PHP

<?php
namespace Tests\Unit\admin\Controllers;
use PHPUnit\Framework\TestCase;
use admin\Controllers\IntegrationsController;
use Domain\Integrations\IntegrationsRepository;
class IntegrationsControllerTest extends TestCase
{
private $repository;
private IntegrationsController $controller;
protected function setUp(): void
{
$this->repository = $this->createMock(IntegrationsRepository::class);
$this->controller = new IntegrationsController($this->repository);
}
public function testConstructorAcceptsDependencies(): void
{
$controller = new IntegrationsController($this->repository);
$this->assertInstanceOf(IntegrationsController::class, $controller);
}
public function testConstructorRequiresRepository(): void
{
$reflection = new \ReflectionClass(IntegrationsController::class);
$constructor = $reflection->getConstructor();
$params = $constructor->getParameters();
$this->assertCount(1, $params);
$this->assertEquals(
'Domain\Integrations\IntegrationsRepository',
$params[0]->getType()->getName()
);
}
public function testHasLogsMethods(): void
{
$methods = [
'logs',
'logs_clear',
];
foreach ($methods as $method) {
$this->assertTrue(
method_exists($this->controller, $method),
"Method $method does not exist"
);
}
}
public function testLogsReturnsString(): void
{
$reflection = new \ReflectionClass($this->controller);
$this->assertEquals('string', (string) $reflection->getMethod('logs')->getReturnType());
}
public function testLogsClearReturnsVoid(): void
{
$reflection = new \ReflectionClass($this->controller);
$this->assertEquals('void', (string) $reflection->getMethod('logs_clear')->getReturnType());
}
public function testHasAllApiloSettingsMethods(): void
{
$methods = [
'apilo_settings',
'apilo_settings_save',
'apilo_authorization',
];
foreach ($methods as $method) {
$this->assertTrue(
method_exists($this->controller, $method),
"Method $method does not exist"
);
}
}
public function testHasAllApiloDataFetchMethods(): void
{
$methods = [
'get_platform_list',
'get_status_types_list',
'get_carrier_account_list',
'get_payment_types_list',
];
foreach ($methods as $method) {
$this->assertTrue(
method_exists($this->controller, $method),
"Method $method does not exist"
);
}
}
public function testHasAllApiloProductMethods(): void
{
$methods = [
'apilo_create_product',
'apilo_product_search',
'apilo_product_select_save',
'apilo_product_select_delete',
];
foreach ($methods as $method) {
$this->assertTrue(
method_exists($this->controller, $method),
"Method $method does not exist"
);
}
}
public function testHasAllShopproMethods(): void
{
$methods = [
'shoppro_settings',
'shoppro_settings_save',
'shoppro_product_import',
];
foreach ($methods as $method) {
$this->assertTrue(
method_exists($this->controller, $method),
"Method $method does not exist"
);
}
}
public function testApiloSettingsReturnsString(): void
{
$reflection = new \ReflectionClass($this->controller);
$this->assertEquals('string', (string) $reflection->getMethod('apilo_settings')->getReturnType());
}
public function testShopproSettingsReturnsString(): void
{
$reflection = new \ReflectionClass($this->controller);
$this->assertEquals('string', (string) $reflection->getMethod('shoppro_settings')->getReturnType());
}
public function testVoidReturnTypes(): void
{
$reflection = new \ReflectionClass($this->controller);
$voidMethods = [
'apilo_settings_save',
'apilo_authorization',
'get_platform_list',
'get_status_types_list',
'get_carrier_account_list',
'get_payment_types_list',
'apilo_create_product',
'apilo_product_search',
'apilo_product_select_save',
'apilo_product_select_delete',
'shoppro_settings_save',
'shoppro_product_import',
];
foreach ($voidMethods as $method) {
$this->assertEquals(
'void',
(string) $reflection->getMethod($method)->getReturnType(),
"Method $method should return void"
);
}
}
public function testDoesNotHaveSellasistMethods(): void
{
$reflection = new \ReflectionClass($this->controller);
$methods = array_map(fn($m) => $m->getName(), $reflection->getMethods());
foreach ($methods as $method) {
$this->assertStringNotContainsString(
'sellasist',
strtolower($method),
"Controller should not have sellasist method: $method"
);
}
}
public function testDoesNotHaveBaselinkerMethods(): void
{
$reflection = new \ReflectionClass($this->controller);
$methods = array_map(fn($m) => $m->getName(), $reflection->getMethods());
foreach ($methods as $method) {
$this->assertStringNotContainsString(
'baselinker',
strtolower($method),
"Controller should not have baselinker method: $method"
);
}
}
}