Add Orders and Order Status repositories with pagination and management features
- Implemented OrdersRepository for handling order data with pagination, filtering, and sorting capabilities. - Added methods for retrieving order status options, quick stats, and detailed order information. - Created OrderStatusRepository for managing order status groups and statuses, including CRUD operations and sorting. - Introduced a bootstrap file for test environment setup and autoloading.
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Settings;
|
||||
|
||||
use App\Modules\Settings\OrderStatusMappingRepository;
|
||||
use PDO;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[CoversClass(OrderStatusMappingRepository::class)]
|
||||
final class OrderStatusMappingRepositoryTest extends TestCase
|
||||
{
|
||||
private PDO $pdo;
|
||||
private OrderStatusMappingRepository $repository;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->pdo = new PDO('sqlite::memory:');
|
||||
$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
$this->pdo->exec(
|
||||
'CREATE TABLE order_status_mappings (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
integration_id INTEGER NOT NULL,
|
||||
shoppro_status_code VARCHAR(64) NOT NULL,
|
||||
shoppro_status_name VARCHAR(128) NULL,
|
||||
orderpro_status_code VARCHAR(64) NOT NULL,
|
||||
created_at DATETIME NOT NULL,
|
||||
updated_at DATETIME NOT NULL
|
||||
)'
|
||||
);
|
||||
|
||||
$this->repository = new OrderStatusMappingRepository($this->pdo);
|
||||
}
|
||||
|
||||
public function testReplaceAndReadMappingsForIntegration(): void
|
||||
{
|
||||
$this->repository->replaceForIntegration(10, [
|
||||
[
|
||||
'shoppro_status_code' => 'new',
|
||||
'shoppro_status_name' => 'Nowe',
|
||||
'orderpro_status_code' => 'new',
|
||||
],
|
||||
[
|
||||
'shoppro_status_code' => 'paid',
|
||||
'shoppro_status_name' => 'Oplacone',
|
||||
'orderpro_status_code' => 'completed',
|
||||
],
|
||||
]);
|
||||
|
||||
$rows = $this->repository->listByIntegration(10);
|
||||
|
||||
self::assertArrayHasKey('new', $rows);
|
||||
self::assertSame('Nowe', $rows['new']['shoppro_status_name']);
|
||||
self::assertSame('new', $rows['new']['orderpro_status_code']);
|
||||
self::assertSame('completed', $rows['paid']['orderpro_status_code']);
|
||||
}
|
||||
|
||||
public function testListOrderProToShopProMapNormalizesCodes(): void
|
||||
{
|
||||
$this->repository->replaceForIntegration(11, [
|
||||
[
|
||||
'shoppro_status_code' => 'Paid',
|
||||
'shoppro_status_name' => 'Oplacone',
|
||||
'orderpro_status_code' => 'Completed',
|
||||
],
|
||||
]);
|
||||
|
||||
$map = $this->repository->listOrderProToShopProMap(11);
|
||||
|
||||
self::assertSame('paid', $map['completed']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user