Files
ECShopX/tests/ShuyunOpenPlatform/CompanyShuyunOpenPlatformConfigUniqueConstraintTest.php
wanghai 058673559c 4.7.0
2026-06-26 19:20:24 +08:00

33 lines
1.1 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
namespace Tests\ShuyunOpenPlatform;
use PHPUnit\Framework\TestCase;
/**
* TC-DB-COMPANY-01同一 company_id 第二条插入触发唯一冲突(与迁移 uk_shuyun_op_company_id 语义一致,使用 SQLite 最小复现)。
*/
class CompanyShuyunOpenPlatformConfigUniqueConstraintTest extends TestCase
{
public function testSecondRowWithSameCompanyIdViolatesUniqueConstraint(): void
{
$pdo = new \PDO('sqlite::memory:');
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$pdo->exec(
'CREATE TABLE company_shuyun_open_platform_config (
id INTEGER PRIMARY KEY AUTOINCREMENT,
company_id INTEGER NOT NULL,
auth_value TEXT NOT NULL,
UNIQUE (company_id),
UNIQUE (auth_value)
)'
);
$pdo->exec("INSERT INTO company_shuyun_open_platform_config (company_id, auth_value) VALUES (42, 'auth-a')");
$this->expectException(\PDOException::class);
$pdo->exec("INSERT INTO company_shuyun_open_platform_config (company_id, auth_value) VALUES (42, 'auth-b')");
}
}