-
Notifications
You must be signed in to change notification settings - Fork 9
refactor(clickhouse): make retention a readonly constructor property #129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -377,71 +377,78 @@ public function testSetSecure(): void | |
| } | ||
|
|
||
| /** | ||
| * Test setRetention stores the value and getRetention returns it | ||
| * Test retention defaults to null and is stored when passed to the constructor | ||
| */ | ||
| public function testSetRetention(): void | ||
| public function testRetention(): void | ||
| { | ||
| $adapter = new ClickHouse( | ||
| host: 'clickhouse', | ||
| username: 'default', | ||
| password: 'clickhouse' | ||
| ); | ||
| $this->assertNull($adapter->retention); | ||
|
|
||
| $this->assertNull($adapter->getRetention()); | ||
|
|
||
| $result = $adapter->setRetention(30); | ||
| $this->assertInstanceOf(ClickHouse::class, $result); | ||
| $this->assertEquals(30, $adapter->getRetention()); | ||
| $adapter = new ClickHouse( | ||
| host: 'clickhouse', | ||
| username: 'default', | ||
| password: 'clickhouse', | ||
| retention: 30 | ||
| ); | ||
| $this->assertEquals(30, $adapter->retention); | ||
| } | ||
|
|
||
| /** | ||
| * Test setRetention accepts null to disable retention | ||
| * Test retention can be set and cleared per table via the fluent setter | ||
| */ | ||
| public function testSetRetentionAcceptsNull(): void | ||
| public function testSetRetention(): void | ||
| { | ||
| $adapter = new ClickHouse( | ||
| host: 'clickhouse', | ||
| username: 'default', | ||
| password: 'clickhouse' | ||
| ); | ||
|
|
||
| $adapter->setRetention(30); | ||
| $this->assertSame($adapter, $adapter->setRetention(30)); | ||
| $this->assertEquals(30, $adapter->retention); | ||
|
|
||
| $adapter->setRetention(null); | ||
| $this->assertNull($adapter->getRetention()); | ||
| $this->assertNull($adapter->retention); | ||
|
|
||
| $this->expectException(Exception::class); | ||
| $this->expectExceptionMessage('Retention must be a positive number of days'); | ||
| $adapter->setRetention(0); | ||
| } | ||
|
Comment on lines
407
to
420
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Prompt To Fix With AIThis is a comment left during a code review.
Path: tests/Audit/Adapter/ClickHouseTest.php
Line: 407-420
Comment:
**Test calls the broken setter — will always error before any assertion**
`testSetRetention` invokes `$adapter->setRetention(30)` on an already-constructed object whose `$retention` is `readonly`. This immediately throws `\Error: Cannot modify readonly property ClickHouse::$retention`, so none of the assertions below that line are ever reached. If `setRetention()` is removed (the PR's stated intent), this entire test block should be removed. If the setter is kept (and `readonly` dropped), the test is correct as-is.
How can I resolve this? If you propose a fix, please make it concise. |
||
|
|
||
| /** | ||
| * Test setRetention rejects zero days | ||
| * Test retention rejects zero days | ||
| */ | ||
| public function testSetRetentionRejectsZero(): void | ||
| public function testRetentionRejectsZero(): void | ||
| { | ||
| $this->expectException(Exception::class); | ||
| $this->expectExceptionMessage('Retention must be a positive number of days'); | ||
|
|
||
| $adapter = new ClickHouse( | ||
| new ClickHouse( | ||
| host: 'clickhouse', | ||
| username: 'default', | ||
| password: 'clickhouse' | ||
| password: 'clickhouse', | ||
| retention: 0 | ||
| ); | ||
|
|
||
| $adapter->setRetention(0); | ||
| } | ||
|
|
||
| /** | ||
| * Test setRetention rejects negative days | ||
| * Test retention rejects negative days | ||
| */ | ||
| public function testSetRetentionRejectsNegative(): void | ||
| public function testRetentionRejectsNegative(): void | ||
| { | ||
| $this->expectException(Exception::class); | ||
| $this->expectExceptionMessage('Retention must be a positive number of days'); | ||
|
|
||
| $adapter = new ClickHouse( | ||
| new ClickHouse( | ||
| host: 'clickhouse', | ||
| username: 'default', | ||
| password: 'clickhouse' | ||
| password: 'clickhouse', | ||
| retention: -1 | ||
| ); | ||
|
|
||
| $adapter->setRetention(-1); | ||
| } | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setRetention()writes to areadonlyproperty — PHP Fatal Error$retentionis declaredpublic readonly ?int $retentionat line 102. PHP does not permit re-assignment of areadonlyproperty after object construction; any call tosetRetention()will throw\Error: Cannot modify readonly property ClickHouse::$retention. The PR description states "the fluent setter is dropped", but the method was left in. It needs to be removed (or thereadonlymodifier removed from the property if the setter is intentional).Prompt To Fix With AI