ver. 0.290: ShopCoupon + ShopOrder frontend migration to Domain + Controllers
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -91,4 +91,141 @@ class OrderRepositoryTest extends TestCase
|
||||
$this->assertSame(2, $result['items'][0]['total_orders']);
|
||||
$this->assertSame(1, $result['items'][0]['paid']);
|
||||
}
|
||||
|
||||
// --- Frontend method tests ---
|
||||
|
||||
public function testFindIdByHashReturnsIdWhenFound(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->method('get')
|
||||
->with('pp_shop_orders', 'id', ['hash' => 'abc123'])
|
||||
->willReturn('42');
|
||||
|
||||
$repository = new OrderRepository($mockDb);
|
||||
$this->assertSame(42, $repository->findIdByHash('abc123'));
|
||||
}
|
||||
|
||||
public function testFindIdByHashReturnsNullWhenNotFound(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->method('get')->willReturn(null);
|
||||
|
||||
$repository = new OrderRepository($mockDb);
|
||||
$this->assertNull($repository->findIdByHash('nonexistent'));
|
||||
}
|
||||
|
||||
public function testFindIdByHashReturnsNullForEmptyHash(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->never())->method('get');
|
||||
|
||||
$repository = new OrderRepository($mockDb);
|
||||
$this->assertNull($repository->findIdByHash(''));
|
||||
$this->assertNull($repository->findIdByHash(' '));
|
||||
}
|
||||
|
||||
public function testFindHashByIdReturnsHashWhenFound(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->method('get')
|
||||
->with('pp_shop_orders', 'hash', ['id' => 42])
|
||||
->willReturn('abc123hash');
|
||||
|
||||
$repository = new OrderRepository($mockDb);
|
||||
$this->assertSame('abc123hash', $repository->findHashById(42));
|
||||
}
|
||||
|
||||
public function testFindHashByIdReturnsNullForInvalidId(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->expects($this->never())->method('get');
|
||||
|
||||
$repository = new OrderRepository($mockDb);
|
||||
$this->assertNull($repository->findHashById(0));
|
||||
$this->assertNull($repository->findHashById(-1));
|
||||
}
|
||||
|
||||
public function testOrderDetailsFrontendByIdReturnsArrayWithProducts(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->method('get')
|
||||
->willReturn(['id' => 1, 'number' => '2026/02/001', 'coupon_id' => null]);
|
||||
$mockDb->method('select')
|
||||
->willReturn([['product_id' => 10, 'name' => 'Test Product']]);
|
||||
|
||||
$repository = new OrderRepository($mockDb);
|
||||
$result = $repository->orderDetailsFrontend(1);
|
||||
|
||||
$this->assertIsArray($result);
|
||||
$this->assertSame(1, $result['id']);
|
||||
$this->assertIsArray($result['products']);
|
||||
$this->assertCount(1, $result['products']);
|
||||
}
|
||||
|
||||
public function testOrderDetailsFrontendByHashReturnsArrayWithProducts(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->method('get')
|
||||
->willReturn(['id' => 5, 'number' => '2026/02/005', 'hash' => 'testhash']);
|
||||
$mockDb->method('select')
|
||||
->willReturn([]);
|
||||
|
||||
$repository = new OrderRepository($mockDb);
|
||||
$result = $repository->orderDetailsFrontend(null, 'testhash');
|
||||
|
||||
$this->assertIsArray($result);
|
||||
$this->assertSame(5, $result['id']);
|
||||
$this->assertIsArray($result['products']);
|
||||
}
|
||||
|
||||
public function testOrderDetailsFrontendReturnsNullWhenNotFound(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
$mockDb->method('get')->willReturn(null);
|
||||
|
||||
$repository = new OrderRepository($mockDb);
|
||||
$this->assertNull($repository->orderDetailsFrontend(999));
|
||||
$this->assertNull($repository->orderDetailsFrontend(null, 'nonexistent'));
|
||||
}
|
||||
|
||||
public function testGenerateOrderNumberFormatsCorrectly(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
|
||||
$resultSet = new class {
|
||||
public function fetchAll(): array
|
||||
{
|
||||
return [[5]];
|
||||
}
|
||||
};
|
||||
|
||||
$mockDb->method('query')->willReturn($resultSet);
|
||||
|
||||
$repository = new OrderRepository($mockDb);
|
||||
$number = $repository->generateOrderNumber();
|
||||
|
||||
$expectedPrefix = date('Y/m') . '/';
|
||||
$this->assertStringStartsWith($expectedPrefix, $number);
|
||||
$this->assertSame($expectedPrefix . '006', $number);
|
||||
}
|
||||
|
||||
public function testGenerateOrderNumberStartsAt001(): void
|
||||
{
|
||||
$mockDb = $this->createMock(\medoo::class);
|
||||
|
||||
$resultSet = new class {
|
||||
public function fetchAll(): array
|
||||
{
|
||||
return [[null]];
|
||||
}
|
||||
};
|
||||
|
||||
$mockDb->method('query')->willReturn($resultSet);
|
||||
|
||||
$repository = new OrderRepository($mockDb);
|
||||
$number = $repository->generateOrderNumber();
|
||||
|
||||
$expectedPrefix = date('Y/m') . '/';
|
||||
$this->assertSame($expectedPrefix . '001', $number);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user