Repository navigation
Use VarString for string parameter encoding in binary protocol #142
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
Merged
trowski
merged 10 commits into
amphp:3.x
from
webpatser:fix/string-parameter-type-for-mariadb-uuid
May 10, 2026
Merged
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
95f5e6f
Use VarString instead of LongBlob for string parameter encoding
webpatser 693d0b7
Suppress Psalm InvalidAttribute for #[\Override]
webpatser bd4e36b
Revert psalm.xml changes — CI issue is pre-existing
webpatser b603de7
Pick string parameter type from target column
webpatser 4339143
Refactor a bit
trowski 619b2de
Add test for blob data
trowski 1e8ecd2
Wrap in transaction
trowski d48e123
Update test
trowski efea7d3
Refactor JSON column tests
trowski cc59597
Style fix
trowski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| <?php declare(strict_types=1); | ||
|
|
||
| namespace Amp\Mysql\Test; | ||
|
|
||
| use Amp\Mysql\Internal\MysqlEncodedValue; | ||
| use Amp\Mysql\MysqlDataType; | ||
| use PHPUnit\Framework\TestCase; | ||
|
|
||
| class MysqlEncodedValueTest extends TestCase | ||
| { | ||
| /** | ||
| * @return iterable<string, array{MysqlDataType|null, MysqlDataType}> | ||
| */ | ||
| public function provideStringTargets(): iterable | ||
| { | ||
| yield 'no target (legacy default)' => [null, MysqlDataType::VarString]; | ||
| yield 'varchar' => [MysqlDataType::Varchar, MysqlDataType::VarString]; | ||
| yield 'string' => [MysqlDataType::String, MysqlDataType::VarString]; | ||
| yield 'var_string' => [MysqlDataType::VarString, MysqlDataType::VarString]; | ||
| yield 'tiny_blob' => [MysqlDataType::TinyBlob, MysqlDataType::LongBlob]; | ||
| yield 'blob' => [MysqlDataType::Blob, MysqlDataType::LongBlob]; | ||
| yield 'medium_blob' => [MysqlDataType::MediumBlob, MysqlDataType::LongBlob]; | ||
| yield 'long_blob' => [MysqlDataType::LongBlob, MysqlDataType::LongBlob]; | ||
| yield 'bit' => [MysqlDataType::Bit, MysqlDataType::VarString]; | ||
| yield 'enum' => [MysqlDataType::Enum, MysqlDataType::VarString]; | ||
| yield 'set' => [MysqlDataType::Set, MysqlDataType::VarString]; | ||
| yield 'geometry' => [MysqlDataType::Geometry, MysqlDataType::VarString]; | ||
| } | ||
|
|
||
| /** | ||
| * @dataProvider provideStringTargets | ||
| */ | ||
| public function testStringPicksTypeBasedOnTarget(?MysqlDataType $target, MysqlDataType $expected): void | ||
| { | ||
| $encoded = MysqlEncodedValue::fromValue('hello', $target); | ||
|
|
||
| self::assertSame($expected, $encoded->getType()); | ||
| } | ||
|
|
||
| public function testBinaryPayloadIntoBlobStaysLongBlob(): void | ||
| { | ||
| $encoded = MysqlEncodedValue::fromValue(\random_bytes(64), MysqlDataType::Blob); | ||
|
|
||
| self::assertSame(MysqlDataType::LongBlob, $encoded->getType()); | ||
| } | ||
|
|
||
| public function testStringableIntoBlobStaysLongBlob(): void | ||
| { | ||
| $stringable = new class implements \Stringable { | ||
| public function __toString(): string | ||
| { | ||
| return 'cast me'; | ||
| } | ||
| }; | ||
|
|
||
| $encoded = MysqlEncodedValue::fromValue($stringable, MysqlDataType::LongBlob); | ||
|
|
||
| self::assertSame(MysqlDataType::LongBlob, $encoded->getType()); | ||
| } | ||
|
|
||
| public function testBackedEnumIntoStringTargetUsesVarString(): void | ||
| { | ||
| $enum = StringTargetEnum::Foo; | ||
|
|
||
| $encoded = MysqlEncodedValue::fromValue($enum, MysqlDataType::Varchar); | ||
|
|
||
| self::assertSame(MysqlDataType::VarString, $encoded->getType()); | ||
| } | ||
|
|
||
| public function testIntegerEncodingIgnoresTarget(): void | ||
| { | ||
| $encoded = MysqlEncodedValue::fromValue(1, MysqlDataType::LongBlob); | ||
|
|
||
| self::assertSame(MysqlDataType::Tiny, $encoded->getType()); | ||
| } | ||
|
|
||
| public function testNullEncodingIgnoresTarget(): void | ||
| { | ||
| $encoded = MysqlEncodedValue::fromValue(null, MysqlDataType::LongBlob); | ||
|
|
||
| self::assertSame(MysqlDataType::Null, $encoded->getType()); | ||
| } | ||
| } | ||
|
|
||
| enum StringTargetEnum: string | ||
| { | ||
| case Foo = 'foo'; | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.