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
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Flow\Bridge\Symfony\TelemetryBundle\Tests\Unit\Instrumentation\Doctrine\DBAL;

use Doctrine\DBAL\Driver\{Connection as ConnectionInterface, Result, Statement as DriverStatement};
use Doctrine\DBAL\{ParameterType, VersionAwarePlatformDriver};
use Doctrine\DBAL\ParameterType;
use Flow\Bridge\Symfony\TelemetryBundle\Instrumentation\Doctrine\DBAL\V4\TracingConnection;
use Flow\Telemetry\Context\MemoryContextStorage;
use Flow\Telemetry\Logger\LoggerProvider;
Expand All @@ -23,7 +23,7 @@ final class TracingConnectionTest extends TestCase
{
protected function setUp() : void
{
if (\interface_exists(VersionAwarePlatformDriver::class)) {
if (\interface_exists('Doctrine\DBAL\VersionAwarePlatformDriver')) {
self::markTestSkipped('Test requires Doctrine DBAL 4.x');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Doctrine\DBAL\Driver\API\ExceptionConverter;
use Doctrine\DBAL\Driver\{Connection, Result, Statement};
use Doctrine\DBAL\{Driver, ServerVersionProvider, VersionAwarePlatformDriver};
use Doctrine\DBAL\{Driver, ServerVersionProvider};
use Doctrine\DBAL\Platforms\{AbstractPlatform, DB2Platform, MariaDBPlatform, MySQL80Platform, OraclePlatform, PostgreSQLPlatform, SQLServerPlatform, SQLitePlatform};
use Flow\Bridge\Symfony\TelemetryBundle\Instrumentation\Doctrine\DBAL\V4\TracingDriver;
use Flow\Telemetry\Context\MemoryContextStorage;
Expand All @@ -25,7 +25,7 @@ final class TracingDriverTest extends TestCase
{
protected function setUp() : void
{
if (\interface_exists(VersionAwarePlatformDriver::class)) {
if (\interface_exists('Doctrine\DBAL\VersionAwarePlatformDriver')) {
self::markTestSkipped('Test requires Doctrine DBAL 4.x');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Flow\Bridge\Symfony\TelemetryBundle\Tests\Unit\Instrumentation\Doctrine\DBAL\V3;

use Doctrine\DBAL\Driver\{Connection as ConnectionInterface, Result, Statement as DriverStatement};
use Doctrine\DBAL\{ParameterType, VersionAwarePlatformDriver};
use Doctrine\DBAL\ParameterType;
use Flow\Bridge\Symfony\TelemetryBundle\Instrumentation\Doctrine\DBAL\V3\TracingConnection;
use Flow\Telemetry\Context\MemoryContextStorage;
use Flow\Telemetry\Logger\LoggerProvider;
Expand All @@ -23,7 +23,7 @@ final class TracingConnectionTest extends TestCase
{
protected function setUp() : void
{
if (!\interface_exists(VersionAwarePlatformDriver::class)) {
if (!\interface_exists('Doctrine\DBAL\VersionAwarePlatformDriver')) {
self::markTestSkipped('Test requires Doctrine DBAL 3.x');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

use Doctrine\DBAL\Driver\API\ExceptionConverter;
use Doctrine\DBAL\Driver\{Connection, Result, Statement};
use Doctrine\DBAL\{Driver, VersionAwarePlatformDriver};
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\{Driver, ParameterType};
use Doctrine\DBAL\Platforms\{AbstractPlatform, DB2Platform, MariaDBPlatform, MySQL80Platform, OraclePlatform, PostgreSQLPlatform, SQLServerPlatform, SqlitePlatform};
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Flow\Bridge\Symfony\TelemetryBundle\Instrumentation\Doctrine\DBAL\V3\TracingDriver;
Expand All @@ -27,7 +26,7 @@ final class TracingDriverTest extends TestCase
{
protected function setUp() : void
{
if (!\interface_exists(VersionAwarePlatformDriver::class)) {
if (!\interface_exists('Doctrine\DBAL\VersionAwarePlatformDriver')) {
self::markTestSkipped('Test requires Doctrine DBAL 3.x');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function toDatabase(mixed $value) : ?string
}

if (\is_string($value)) {
return $value;
return '\x' . \bin2hex($value);
}

throw ValueConversionException::cannotConvert($value, 'bytea');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

namespace Flow\PostgreSql\Tests\Integration\Client\Types\Converter;

use function Flow\PostgreSql\DSL\{cast, column_type_bytea, literal, param, select};
use function Flow\PostgreSql\DSL\{cast, column_type_bytea, literal, param, select, typed};
use Flow\PostgreSql\Client\Types\ValueType;
use Flow\PostgreSql\Tests\Integration\PostgreSqlTestCase;
use PHPUnit\Framework\Attributes\DataProvider;

Expand All @@ -31,6 +32,17 @@ public static function provide_hex_bytea_values() : \Generator
yield 'mixed case' => ['deadbeef', "\xde\xad\xbe\xef"];
}

/**
* @return \Generator<string, array{string}>
*/
public static function provide_typed_bytea_binary_values() : \Generator
{
yield 'leading null bytes' => ["\x00\x00\x00\x02\x11\x06value1"];
yield 'embedded null bytes' => ["hello\x00world"];
yield 'high bytes' => ["\x01\x02\x03\xff\xfe"];
yield 'serialize output' => [\serialize(['greeting' => 'world', 'count' => 7])];
}

public function test_binary_data_via_hex_literal() : void
{
$result = $this->pgsqlContext()->client()->fetchScalar(select(cast(literal('\\x00010203'), column_type_bytea())->as('val'))->toSql());
Expand Down Expand Up @@ -76,4 +88,15 @@ public function test_null_bytea() : void

self::assertNull($result);
}

#[DataProvider('provide_typed_bytea_binary_values')]
public function test_typed_bytea_round_trip_preserves_binary(string $input) : void
{
$result = $this->pgsqlContext()->client()->fetchScalar(
select(cast(param(1), column_type_bytea())->as('val'))->toSql(),
[typed($input, ValueType::BYTEA)],
);

self::assertSame($input, $result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ public static function provide_invalid_values() : \Generator

public static function provide_valid_values() : \Generator
{
yield 'simple text' => ['simple text', 'simple text'];
yield 'hello' => ['hello', 'hello'];
yield 'empty string' => ['', ''];
yield 'binary with null byte' => ["hello\x00world", "hello\x00world"];
yield 'binary with special bytes' => ["\x01\x02\x03\xff\xfe", "\x01\x02\x03\xff\xfe"];
yield 'unicode characters' => ['日本語テスト', '日本語テスト'];
yield 'emoji' => ['Hello 🎉 World', 'Hello 🎉 World'];
yield 'newlines and tabs' => ["line1\nline2\ttab", "line1\nline2\ttab"];
yield 'backslash' => ['path\\to\\file', 'path\\to\\file'];
yield 'single quote' => ["it's a test", "it's a test"];
yield 'double quote' => ['say "hello"', 'say "hello"'];
yield 'simple text' => ['simple text', '\x' . \bin2hex('simple text')];
yield 'hello' => ['hello', '\x' . \bin2hex('hello')];
yield 'empty string' => ['', '\x'];
yield 'binary with null byte' => ["hello\x00world", '\x' . \bin2hex("hello\x00world")];
yield 'binary with special bytes' => ["\x01\x02\x03\xff\xfe", '\x' . \bin2hex("\x01\x02\x03\xff\xfe")];
yield 'unicode characters' => ['日本語テスト', '\x' . \bin2hex('日本語テスト')];
yield 'emoji' => ['Hello 🎉 World', '\x' . \bin2hex('Hello 🎉 World')];
yield 'newlines and tabs' => ["line1\nline2\ttab", '\x' . \bin2hex("line1\nline2\ttab")];
yield 'backslash' => ['path\\to\\file', '\x' . \bin2hex('path\\to\\file')];
yield 'single quote' => ["it's a test", '\x' . \bin2hex("it's a test")];
yield 'double quote' => ['say "hello"', '\x' . \bin2hex('say "hello"')];
}

#[DataProvider('provide_invalid_values')]
Expand Down
Loading