From bff30f1e064d49e83f429b8558683f866f64d7cf Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 4 May 2026 01:33:06 +0000 Subject: [PATCH 1/2] feat: add setTableName setter and getTableNameRaw getter to ClickHouse adapter Agent-Logs-Url: https://github.com/utopia-php/audit/sessions/fa48fed4-eea0-4071-b099-2a51045d1e52 Co-authored-by: lohanidamodar <6360216+lohanidamodar@users.noreply.github.com> --- src/Audit/Adapter/ClickHouse.php | 24 ++++++++ tests/Audit/Adapter/ClickHouseTest.php | 84 ++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) diff --git a/src/Audit/Adapter/ClickHouse.php b/src/Audit/Adapter/ClickHouse.php index 0d598d5..9bfc6bf 100644 --- a/src/Audit/Adapter/ClickHouse.php +++ b/src/Audit/Adapter/ClickHouse.php @@ -185,6 +185,30 @@ public function setDatabase(string $database): self return $this; } + /** + * Set the table name for subsequent operations. + * + * @param string $table + * @return self + * @throws Exception + */ + public function setTableName(string $table): self + { + $this->validateIdentifier($table, 'Table'); + $this->table = $table; + return $this; + } + + /** + * Get the table name (without namespace prefix). + * + * @return string + */ + public function getTableNameRaw(): string + { + return $this->table; + } + /** * Enable or disable HTTPS for ClickHouse HTTP interface. */ diff --git a/tests/Audit/Adapter/ClickHouseTest.php b/tests/Audit/Adapter/ClickHouseTest.php index 1374c71..9fedf39 100644 --- a/tests/Audit/Adapter/ClickHouseTest.php +++ b/tests/Audit/Adapter/ClickHouseTest.php @@ -213,6 +213,90 @@ public function testSetDatabaseWithValidIdentifier(): void $this->assertInstanceOf(ClickHouse::class, $result); } + /** + * Test setTableName validates empty identifier + */ + public function testSetTableNameValidatesEmpty(): void + { + $this->expectException(Exception::class); + $this->expectExceptionMessage('Table cannot be empty'); + + $adapter = new ClickHouse( + host: 'clickhouse', + username: 'default', + password: 'clickhouse' + ); + + $adapter->setTableName(''); + } + + /** + * Test setTableName validates identifier length + */ + public function testSetTableNameValidatesLength(): void + { + $this->expectException(Exception::class); + $this->expectExceptionMessage('Table cannot exceed 255 characters'); + + $adapter = new ClickHouse( + host: 'clickhouse', + username: 'default', + password: 'clickhouse' + ); + + $adapter->setTableName(str_repeat('a', 256)); + } + + /** + * Test setTableName validates identifier format + */ + public function testSetTableNameValidatesFormat(): void + { + $this->expectException(Exception::class); + $this->expectExceptionMessage('Table must start with a letter or underscore'); + + $adapter = new ClickHouse( + host: 'clickhouse', + username: 'default', + password: 'clickhouse' + ); + + $adapter->setTableName('123invalid'); + } + + /** + * Test setTableName rejects SQL keywords + */ + public function testSetTableNameRejectsKeywords(): void + { + $this->expectException(Exception::class); + $this->expectExceptionMessage('Table cannot be a reserved SQL keyword'); + + $adapter = new ClickHouse( + host: 'clickhouse', + username: 'default', + password: 'clickhouse' + ); + + $adapter->setTableName('SELECT'); + } + + /** + * Test setTableName with valid identifier + */ + public function testSetTableNameWithValidIdentifier(): void + { + $adapter = new ClickHouse( + host: 'clickhouse', + username: 'default', + password: 'clickhouse' + ); + + $result = $adapter->setTableName('my_audit_logs'); + $this->assertInstanceOf(ClickHouse::class, $result); + $this->assertEquals('my_audit_logs', $adapter->getTableNameRaw()); + } + /** * Test setNamespace allows empty string */ From b5b4dd4a102bcc9d333359de4edf360d1fe1bda7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 4 May 2026 01:51:47 +0000 Subject: [PATCH 2/2] =?UTF-8?q?refactor:=20rename=20setTableName=E2=86=92s?= =?UTF-8?q?etTable=20and=20getTableNameRaw=E2=86=92getTable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Agent-Logs-Url: https://github.com/utopia-php/audit/sessions/24eb2765-07b1-4636-8c3f-90373bb31eaf Co-authored-by: lohanidamodar <6360216+lohanidamodar@users.noreply.github.com> --- src/Audit/Adapter/ClickHouse.php | 4 ++-- tests/Audit/Adapter/ClickHouseTest.php | 32 +++++++++++++------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Audit/Adapter/ClickHouse.php b/src/Audit/Adapter/ClickHouse.php index 9bfc6bf..2f07fe3 100644 --- a/src/Audit/Adapter/ClickHouse.php +++ b/src/Audit/Adapter/ClickHouse.php @@ -192,7 +192,7 @@ public function setDatabase(string $database): self * @return self * @throws Exception */ - public function setTableName(string $table): self + public function setTable(string $table): self { $this->validateIdentifier($table, 'Table'); $this->table = $table; @@ -204,7 +204,7 @@ public function setTableName(string $table): self * * @return string */ - public function getTableNameRaw(): string + public function getTable(): string { return $this->table; } diff --git a/tests/Audit/Adapter/ClickHouseTest.php b/tests/Audit/Adapter/ClickHouseTest.php index 9fedf39..17bff4d 100644 --- a/tests/Audit/Adapter/ClickHouseTest.php +++ b/tests/Audit/Adapter/ClickHouseTest.php @@ -214,9 +214,9 @@ public function testSetDatabaseWithValidIdentifier(): void } /** - * Test setTableName validates empty identifier + * Test setTable validates empty identifier */ - public function testSetTableNameValidatesEmpty(): void + public function testSetTableValidatesEmpty(): void { $this->expectException(Exception::class); $this->expectExceptionMessage('Table cannot be empty'); @@ -227,13 +227,13 @@ public function testSetTableNameValidatesEmpty(): void password: 'clickhouse' ); - $adapter->setTableName(''); + $adapter->setTable(''); } /** - * Test setTableName validates identifier length + * Test setTable validates identifier length */ - public function testSetTableNameValidatesLength(): void + public function testSetTableValidatesLength(): void { $this->expectException(Exception::class); $this->expectExceptionMessage('Table cannot exceed 255 characters'); @@ -244,13 +244,13 @@ public function testSetTableNameValidatesLength(): void password: 'clickhouse' ); - $adapter->setTableName(str_repeat('a', 256)); + $adapter->setTable(str_repeat('a', 256)); } /** - * Test setTableName validates identifier format + * Test setTable validates identifier format */ - public function testSetTableNameValidatesFormat(): void + public function testSetTableValidatesFormat(): void { $this->expectException(Exception::class); $this->expectExceptionMessage('Table must start with a letter or underscore'); @@ -261,13 +261,13 @@ public function testSetTableNameValidatesFormat(): void password: 'clickhouse' ); - $adapter->setTableName('123invalid'); + $adapter->setTable('123invalid'); } /** - * Test setTableName rejects SQL keywords + * Test setTable rejects SQL keywords */ - public function testSetTableNameRejectsKeywords(): void + public function testSetTableRejectsKeywords(): void { $this->expectException(Exception::class); $this->expectExceptionMessage('Table cannot be a reserved SQL keyword'); @@ -278,13 +278,13 @@ public function testSetTableNameRejectsKeywords(): void password: 'clickhouse' ); - $adapter->setTableName('SELECT'); + $adapter->setTable('SELECT'); } /** - * Test setTableName with valid identifier + * Test setTable with valid identifier */ - public function testSetTableNameWithValidIdentifier(): void + public function testSetTableWithValidIdentifier(): void { $adapter = new ClickHouse( host: 'clickhouse', @@ -292,9 +292,9 @@ public function testSetTableNameWithValidIdentifier(): void password: 'clickhouse' ); - $result = $adapter->setTableName('my_audit_logs'); + $result = $adapter->setTable('my_audit_logs'); $this->assertInstanceOf(ClickHouse::class, $result); - $this->assertEquals('my_audit_logs', $adapter->getTableNameRaw()); + $this->assertEquals('my_audit_logs', $adapter->getTable()); } /**