66 lines
2.1 KiB
PHP
66 lines
2.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
require_once dirname(__DIR__, 2) . '/feca_mailshots_plugin/src/autoload.php';
|
|
|
|
use FecaMailshots\Infrastructure\Env;
|
|
use FecaMailshots\Infrastructure\PdoDatabaseRouter;
|
|
use FecaMailshots\Repository\MailshotQueryRepository;
|
|
|
|
Env::load(dirname(__DIR__, 2) . '/credentials/.env');
|
|
|
|
$dbConfig = [
|
|
'MYSQL_HOST' => '127.0.0.1',
|
|
'MYSQL_PORT' => (string) (getenv('MYSQL_TUNNEL_LOCAL_PORT') ?: '13306'),
|
|
'MYSQL_USER' => Env::require('REMOTE_MYSQL_USER'),
|
|
'MYSQL_PASSWORD' => Env::require('REMOTE_MYSQL_PASSWORD'),
|
|
'MAILSHOTS_REMOTE_MYSQL_DB' => Env::require('MAILSHOTS_REMOTE_MYSQL_DB'),
|
|
'MEMBERS_REMOTE_MYSQL_DB' => Env::require('MEMBERS_REMOTE_MYSQL_DB'),
|
|
'FEN_REMOTE_MYSQL_DB' => Env::require('FEN_REMOTE_MYSQL_DB'),
|
|
];
|
|
|
|
$repo = new MailshotQueryRepository(new PdoDatabaseRouter($dbConfig));
|
|
$id = null;
|
|
$name = 'ds_list_lightweight_' . gmdate('Ymd_His') . '_' . bin2hex(random_bytes(3));
|
|
$dsl = 'contacts where contacts.id = 1 ' . str_repeat('x', 1800000);
|
|
|
|
try {
|
|
$id = $repo->create(['name' => $name, 'dsl_text' => $dsl]);
|
|
if ($id <= 0) {
|
|
fwrite(STDERR, "Data source create did not return an id\n");
|
|
exit(1);
|
|
}
|
|
|
|
$listedRow = null;
|
|
foreach ($repo->all() as $row) {
|
|
if ((int) ($row['ID'] ?? 0) === $id) {
|
|
$listedRow = $row;
|
|
break;
|
|
}
|
|
}
|
|
if (!is_array($listedRow)) {
|
|
fwrite(STDERR, "Data source was not returned by list query\n");
|
|
exit(1);
|
|
}
|
|
if (strlen((string) ($listedRow['dsl_text'] ?? '')) > 1000) {
|
|
fwrite(STDERR, "Data source list query should return only a bounded DSL preview\n");
|
|
exit(1);
|
|
}
|
|
|
|
$fullRow = $repo->find($id);
|
|
if (!is_array($fullRow) || (string) ($fullRow['dsl_text'] ?? '') !== $dsl) {
|
|
fwrite(STDERR, "Data source find query should fetch full DSL for editing/execution\n");
|
|
exit(1);
|
|
}
|
|
} finally {
|
|
if ($id !== null && $id > 0) {
|
|
try {
|
|
$repo->delete($id);
|
|
} catch (Throwable $e) {
|
|
}
|
|
}
|
|
}
|
|
|
|
echo "Data source list lightweight regression test passed\n";
|