123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- namespace Test\DB;
- use Test\TestCase;
- class AdapterTest extends TestCase {
- private string $appId;
- private $connection;
- public function setUp(): void {
- $this->connection = \OC::$server->getDatabaseConnection();
- $this->appId = uniqid('test_db_adapter', true);
- }
- public function tearDown(): void {
- $qb = $this->connection->getQueryBuilder();
- $qb->delete('appconfig')
- ->from('appconfig')
- ->where($qb->expr()->eq('appid', $qb->createNamedParameter($this->appId)))
- ->execute();
- }
- public function testInsertIgnoreOnConflictDuplicate(): void {
- $configKey = uniqid('key', true);
- $expected = [
- [
- 'configkey' => $configKey,
- 'configvalue' => '1',
- ]
- ];
- $result = $this->connection->insertIgnoreConflict('appconfig', [
- 'appid' => $this->appId,
- 'configkey' => $configKey,
- 'configvalue' => '1',
- ]);
- $this->assertEquals(1, $result);
- $rows = $this->getRows($configKey);
- $this->assertSame($expected, $rows);
- $result = $this->connection->insertIgnoreConflict('appconfig', [
- 'appid' => $this->appId,
- 'configkey' => $configKey,
- 'configvalue' => '2',
- ]);
- $this->assertEquals(0, $result);
- $rows = $this->getRows($configKey);
- $this->assertSame($expected, $rows);
- }
- private function getRows(string $configKey): array {
- $qb = $this->connection->getQueryBuilder();
- return $qb->select(['configkey', 'configvalue'])
- ->from('appconfig')
- ->where($qb->expr()->eq('appid', $qb->createNamedParameter($this->appId)))
- ->andWhere($qb->expr()->eq('configkey', $qb->createNamedParameter($configKey)))
- ->execute()
- ->fetchAll();
- }
- }
|