1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-11-26 23:14:38 +01:00
MadelineProto/tests/db.php

44 lines
1.4 KiB
PHP
Raw Normal View History

2022-12-30 19:21:36 +01:00
<?php
declare(strict_types=1);
2022-06-23 14:37:54 +02:00
// Switch to another database driver, for testing
2022-12-08 20:16:40 +01:00
if (getenv('ACTIONS_PHAR')) {
2022-06-23 17:42:04 +02:00
include 'madeline.php';
2022-12-08 20:16:40 +01:00
} elseif (!file_exists(__DIR__.'/../vendor/autoload.php') || getenv('ACTIONS_FORCE_PREVIOUS')) {
2022-06-23 17:42:04 +02:00
echo 'You did not run composer update, using madeline.php'.PHP_EOL;
2022-12-08 20:16:40 +01:00
if (!file_exists('madeline.php')) {
copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
2022-06-23 17:42:04 +02:00
}
include 'madeline.php';
} else {
require_once 'vendor/autoload.php';
}
2022-12-30 19:21:36 +01:00
use danog\MadelineProto\API;
2022-06-23 14:37:54 +02:00
use danog\MadelineProto\Settings\Database\Memory;
use danog\MadelineProto\Settings\Database\Mysql;
use danog\MadelineProto\Settings\Database\Postgres;
use danog\MadelineProto\Settings\Database\Redis;
2023-05-27 12:03:09 +02:00
use danog\MadelineProto\Settings\Database\SerializerType;
2022-06-23 14:37:54 +02:00
2022-12-30 19:21:36 +01:00
$MadelineProto = new API(__DIR__.'/../testing.madeline');
2022-06-23 14:37:54 +02:00
2022-06-25 19:15:30 +02:00
$map = [
2022-06-23 14:37:54 +02:00
'memory' => new Memory,
'mysql' => (new Mysql)->setUri('tcp://mariadb')->setUsername('MadelineProto')->setPassword('test'),
'postgres' => (new Postgres)->setUri('tcp://postgres')->setUsername('MadelineProto')->setPassword('test'),
2022-06-25 19:15:30 +02:00
'redis' => (new Redis)->setUri('redis://redis'),
];
2022-06-23 14:37:54 +02:00
2023-05-27 12:05:56 +02:00
$settings = $map[$argv[1]];
2023-05-27 12:11:24 +02:00
if (!$settings instanceof Memory) {
$settings->setSerializer($argv[2] === 'igbinary' ? SerializerType::IGBINARY : SerializerType::SERIALIZE);
}
2023-05-27 12:05:56 +02:00
$MadelineProto->updateSettings($settings);
2022-06-25 19:15:30 +02:00
2022-12-08 20:16:40 +01:00
var_dump($MadelineProto->getFullInfo('danogentili'));