From 9dc3673bed55a29bbc431163b72e4d7fc5ae2fbd Mon Sep 17 00:00:00 2001 From: Roman Konz Date: Mon, 8 Jun 2026 07:29:26 +0200 Subject: [PATCH 1/2] Revert "test: assert dbsafeString flag toggles after enum/escapeable unwrap" This reverts commit 587fa694aa9d2110bdb4d032030f18d68b83e397. --- tests/ConnectionTest.php | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/tests/ConnectionTest.php b/tests/ConnectionTest.php index cacb938b..bd328ea5 100644 --- a/tests/ConnectionTest.php +++ b/tests/ConnectionTest.php @@ -1043,16 +1043,6 @@ public static function dbsafeStringProvider(): array 'input' => StringBackedEnum::WithQuote, 'expected' => "O\\'Brien", ], - 'BackedEnum (htmlSpecialChars=false skips html escape)' => [ - 'input' => StringBackedEnum::WithHtml, - 'expected' => '', - 'htmlSpecialChars' => false, - ], - 'BackedEnum (addSlashes=false skips slash escape)' => [ - 'input' => StringBackedEnum::WithQuote, - 'expected' => "O'Brien", - 'addSlashes' => false, - ], 'EscapeableParameterInterface (string)' => [ 'input' => new EscapeableValue('hello'), 'expected' => 'hello', @@ -1073,16 +1063,6 @@ public static function dbsafeStringProvider(): array 'input' => new EscapeableValue("O'Brien"), 'expected' => "O\\'Brien", ], - 'EscapeableParameterInterface (htmlSpecialChars=false skips html escape)' => [ - 'input' => new EscapeableValue(''), - 'expected' => '', - 'htmlSpecialChars' => false, - ], - 'EscapeableParameterInterface (addSlashes=false skips slash escape)' => [ - 'input' => new EscapeableValue("O'Brien"), - 'expected' => "O'Brien", - 'addSlashes' => false, - ], ]; } } From 0ee529d11551595cca0b5c1c65b37dbbc9ed21ef Mon Sep 17 00:00:00 2001 From: Roman Konz Date: Mon, 8 Jun 2026 07:29:47 +0200 Subject: [PATCH 2/2] Revert "test: add dbsafeString coverage" This reverts commit 5e00cf15db227b0eb8c54111fce47caa255e669b. --- tests/ConnectionTest.php | 103 ---------------------------- tests/Fixtures/EscapeableValue.php | 37 ---------- tests/Fixtures/IntBackedEnum.php | 19 ----- tests/Fixtures/StringBackedEnum.php | 21 ------ 4 files changed, 180 deletions(-) delete mode 100644 tests/Fixtures/EscapeableValue.php delete mode 100644 tests/Fixtures/IntBackedEnum.php delete mode 100644 tests/Fixtures/StringBackedEnum.php diff --git a/tests/ConnectionTest.php b/tests/ConnectionTest.php index bd328ea5..e4e93493 100644 --- a/tests/ConnectionTest.php +++ b/tests/ConnectionTest.php @@ -20,9 +20,6 @@ use Artemeon\Database\Exception\QueryException; use Artemeon\Database\Exception\RemoveColumnException; use Artemeon\Database\Schema\DataType; -use Artemeon\Database\Tests\Fixtures\EscapeableValue; -use Artemeon\Database\Tests\Fixtures\IntBackedEnum; -use Artemeon\Database\Tests\Fixtures\StringBackedEnum; use DateInterval; use DateTime; use PHPUnit\Framework\Attributes\CoversClass; @@ -965,104 +962,4 @@ public function testHasTable(): void $this->assertTrue($connection->hasTable($tableName)); $this->assertFalse($connection->hasTable('table_does_not_exist')); } - - #[DataProvider('dbsafeStringProvider')] - public function testDbsafeString( - mixed $input, - mixed $expected, - bool $htmlSpecialChars = true, - bool $addSlashes = true, - ): void { - $this->assertSame( - $expected, - $this->getConnection()->dbsafeString($input, $htmlSpecialChars, $addSlashes), - ); - } - - /** - * @return array - */ - public static function dbsafeStringProvider(): array - { - return [ - 'null' => [ - 'input' => null, - 'expected' => null, - ], - 'int' => [ - 'input' => 42, - 'expected' => 42, - ], - 'float' => [ - 'input' => 1.5, - 'expected' => 1.5, - ], - 'bool true is cast to 1' => [ - 'input' => true, - 'expected' => 1, - ], - 'bool false is cast to 0' => [ - 'input' => false, - 'expected' => 0, - ], - 'plain string passthrough' => [ - 'input' => 'plain', - 'expected' => 'plain', - ], - 'string with html chars is escaped' => [ - 'input' => '', - 'expected' => '<a>', - ], - 'string with quote is escaped' => [ - 'input' => "O'Brien", - 'expected' => "O\\'Brien", - ], - 'htmlSpecialChars=false skips html escape' => [ - 'input' => '', - 'expected' => '', - 'htmlSpecialChars' => false, - ], - 'addSlashes=false skips slash escape' => [ - 'input' => "O'Brien", - 'expected' => "O'Brien", - 'addSlashes' => false, - ], - 'BackedEnum (string)' => [ - 'input' => StringBackedEnum::Foo, - 'expected' => 'foo', - ], - 'BackedEnum (int)' => [ - 'input' => IntBackedEnum::Forty, - 'expected' => 40, - ], - 'BackedEnum (string with html chars is escaped)' => [ - 'input' => StringBackedEnum::WithHtml, - 'expected' => '<a>', - ], - 'BackedEnum (string with quote is escaped)' => [ - 'input' => StringBackedEnum::WithQuote, - 'expected' => "O\\'Brien", - ], - 'EscapeableParameterInterface (string)' => [ - 'input' => new EscapeableValue('hello'), - 'expected' => 'hello', - ], - 'EscapeableParameterInterface (int)' => [ - 'input' => new EscapeableValue(123), - 'expected' => 123, - ], - 'EscapeableParameterInterface (null)' => [ - 'input' => new EscapeableValue(null), - 'expected' => null, - ], - 'EscapeableParameterInterface (string with html chars is escaped)' => [ - 'input' => new EscapeableValue(''), - 'expected' => '<a>', - ], - 'EscapeableParameterInterface (string with quote is escaped)' => [ - 'input' => new EscapeableValue("O'Brien"), - 'expected' => "O\\'Brien", - ], - ]; - } } diff --git a/tests/Fixtures/EscapeableValue.php b/tests/Fixtures/EscapeableValue.php deleted file mode 100644 index bd00ae47..00000000 --- a/tests/Fixtures/EscapeableValue.php +++ /dev/null @@ -1,37 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -declare(strict_types=1); - -namespace Artemeon\Database\Tests\Fixtures; - -use Artemeon\Database\EscapeableParameterInterface; -use Stringable; - -final class EscapeableValue implements EscapeableParameterInterface -{ - /** - * @param scalar|Stringable|null $value - */ - public function __construct(private readonly mixed $value) - { - } - - public function isEscape(): bool - { - return true; - } - - public function getValue(): mixed - { - return $this->value; - } -} diff --git a/tests/Fixtures/IntBackedEnum.php b/tests/Fixtures/IntBackedEnum.php deleted file mode 100644 index 4debf61b..00000000 --- a/tests/Fixtures/IntBackedEnum.php +++ /dev/null @@ -1,19 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -declare(strict_types=1); - -namespace Artemeon\Database\Tests\Fixtures; - -enum IntBackedEnum: int -{ - case Forty = 40; -} diff --git a/tests/Fixtures/StringBackedEnum.php b/tests/Fixtures/StringBackedEnum.php deleted file mode 100644 index ec09c158..00000000 --- a/tests/Fixtures/StringBackedEnum.php +++ /dev/null @@ -1,21 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -declare(strict_types=1); - -namespace Artemeon\Database\Tests\Fixtures; - -enum StringBackedEnum: string -{ - case Foo = 'foo'; - case WithHtml = ''; - case WithQuote = "O'Brien"; -}