Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 0 additions & 123 deletions tests/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -965,124 +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<string, array{input: mixed, expected: mixed, htmlSpecialChars?: bool, addSlashes?: bool}>
*/
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' => '<a>',
'expected' => '&lt;a&gt;',
],
'string with quote is escaped' => [
'input' => "O'Brien",
'expected' => "O\\'Brien",
],
'htmlSpecialChars=false skips html escape' => [
'input' => '<a>',
'expected' => '<a>',
'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' => '&lt;a&gt;',
],
'BackedEnum (string with quote is escaped)' => [
'input' => StringBackedEnum::WithQuote,
'expected' => "O\\'Brien",
],
'BackedEnum (htmlSpecialChars=false skips html escape)' => [
'input' => StringBackedEnum::WithHtml,
'expected' => '<a>',
'htmlSpecialChars' => false,
],
'BackedEnum (addSlashes=false skips slash escape)' => [
'input' => StringBackedEnum::WithQuote,
'expected' => "O'Brien",
'addSlashes' => false,
],
'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('<a>'),
'expected' => '&lt;a&gt;',
],
'EscapeableParameterInterface (string with quote is escaped)' => [
'input' => new EscapeableValue("O'Brien"),
'expected' => "O\\'Brien",
],
'EscapeableParameterInterface (htmlSpecialChars=false skips html escape)' => [
'input' => new EscapeableValue('<a>'),
'expected' => '<a>',
'htmlSpecialChars' => false,
],
'EscapeableParameterInterface (addSlashes=false skips slash escape)' => [
'input' => new EscapeableValue("O'Brien"),
'expected' => "O'Brien",
'addSlashes' => false,
],
];
}
}
37 changes: 0 additions & 37 deletions tests/Fixtures/EscapeableValue.php

This file was deleted.

19 changes: 0 additions & 19 deletions tests/Fixtures/IntBackedEnum.php

This file was deleted.

21 changes: 0 additions & 21 deletions tests/Fixtures/StringBackedEnum.php

This file was deleted.

Loading