From 93af384d966c5499f4acdac909ded42c1ab4092d Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sat, 27 May 2023 12:03:09 +0200 Subject: [PATCH] Test igbinary serialization --- src/Db/DbPropertiesFactory.php | 6 +++++- src/Settings/Database/DriverDatabaseAbstract.php | 3 ++- tests/db.php | 5 ++++- tests/makephar.sh | 16 +++++++++------- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/Db/DbPropertiesFactory.php b/src/Db/DbPropertiesFactory.php index d3cff138a..a5cb65712 100644 --- a/src/Db/DbPropertiesFactory.php +++ b/src/Db/DbPropertiesFactory.php @@ -49,7 +49,11 @@ final class DbPropertiesFactory 'enableCache' => true, 'cacheTtl' => $dbSettingsCopy->getCacheTtl(), ], $config); - if ($config['innerMadelineProto']) { + + if ($config['innerMadelineProto'] + && $config['serializer'] !== SerializerType::IGBINARY + && $config['serializer'] !== SerializerType::SERIALIZE + ) { $config['serializer'] = Magic::$can_use_igbinary ? SerializerType::IGBINARY : SerializerType::SERIALIZE; diff --git a/src/Settings/Database/DriverDatabaseAbstract.php b/src/Settings/Database/DriverDatabaseAbstract.php index 90944651b..06f4bb080 100644 --- a/src/Settings/Database/DriverDatabaseAbstract.php +++ b/src/Settings/Database/DriverDatabaseAbstract.php @@ -122,8 +122,9 @@ abstract class DriverDatabaseAbstract extends DatabaseAbstract * * If null, the best serializer is chosen. */ - public function setSerializer(?SerializerType $serializer): void + public function setSerializer(?SerializerType $serializer): static { $this->serializer = $serializer; + return $this; } } diff --git a/tests/db.php b/tests/db.php index 11ba07711..0ef54752e 100644 --- a/tests/db.php +++ b/tests/db.php @@ -21,6 +21,7 @@ use danog\MadelineProto\Settings\Database\Memory; use danog\MadelineProto\Settings\Database\Mysql; use danog\MadelineProto\Settings\Database\Postgres; use danog\MadelineProto\Settings\Database\Redis; +use danog\MadelineProto\Settings\Database\SerializerType; $MadelineProto = new API(__DIR__.'/../testing.madeline'); @@ -31,6 +32,8 @@ $map = [ 'redis' => (new Redis)->setUri('redis://redis'), ]; -$MadelineProto->updateSettings($map[$argv[1]]); +$MadelineProto->updateSettings( + $map[$argv[1]]->setSerializer($argv[2] === 'igbinary' ? SerializerType::IGBINARY : SerializerType::SERIALIZE) +); var_dump($MadelineProto->getFullInfo('danogentili')); diff --git a/tests/makephar.sh b/tests/makephar.sh index d2aed5e76..afdc10827 100755 --- a/tests/makephar.sh +++ b/tests/makephar.sh @@ -96,15 +96,17 @@ cd $madelinePath db() { - php tests/db.php $1 + php tests/db.php $1 $2 } cycledb() { - db memory - db mysql - db postgres - db redis - db memory + for f in serialize igbinary; do + db memory $f + db mysql $f + db postgres $f + db redis $f + db memory $f + done } runTestSimple() @@ -135,7 +137,7 @@ echo "Testing with previous version..." export ACTIONS_FORCE_PREVIOUS=1 cp tools/phar.php madeline.php runTest -db mysql +db mysql serialize k echo "Testing with new version (upgrade)..."