68 lines
2.3 KiB
PHP
68 lines
2.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
require_once dirname(__DIR__, 2) . '/feca_mailshots_plugin/src/autoload.php';
|
|
|
|
use FecaMailshots\Application\DataSourceService;
|
|
use FecaMailshots\Application\DslCompiler;
|
|
use FecaMailshots\Application\DslValidator;
|
|
use FecaMailshots\Domain\DslParser;
|
|
use FecaMailshots\Infrastructure\DatabaseSourceMetadataProvider;
|
|
use FecaMailshots\Infrastructure\Env;
|
|
use FecaMailshots\Infrastructure\PdoDatabaseRouter;
|
|
use FecaMailshots\Repository\MailshotQueryRepository;
|
|
use FecaMailshots\Repository\MailshotRepository;
|
|
|
|
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'),
|
|
];
|
|
|
|
$router = new PdoDatabaseRouter($dbConfig);
|
|
$queries = new MailshotQueryRepository($router);
|
|
$mailshots = new MailshotRepository($router);
|
|
$metadata = new DatabaseSourceMetadataProvider($router);
|
|
$service = new DataSourceService(
|
|
$queries,
|
|
$router,
|
|
new DslParser(),
|
|
new DslValidator($metadata),
|
|
new DslCompiler($metadata),
|
|
$metadata,
|
|
$mailshots
|
|
);
|
|
|
|
$first = $service->review('contacts', 3, 0);
|
|
$second = $service->review('contacts', 3, 3);
|
|
|
|
foreach ([$first, $second] as $result) {
|
|
if (($result['errors'] ?? []) !== []) {
|
|
fwrite(STDERR, 'Review recipients paging returned errors: ' . implode('; ', (array) $result['errors']) . "\n");
|
|
exit(1);
|
|
}
|
|
if ((int) ($result['returned_count'] ?? 0) > 3 || count((array) ($result['rows'] ?? [])) > 3) {
|
|
fwrite(STDERR, "Review recipients paging exceeded the requested limit\n");
|
|
exit(1);
|
|
}
|
|
}
|
|
|
|
if ((int) ($first['count'] ?? 0) !== (int) ($second['count'] ?? -1)) {
|
|
fwrite(STDERR, "Review recipients paging should preserve the total count across pages\n");
|
|
exit(1);
|
|
}
|
|
|
|
if ((int) ($second['offset'] ?? -1) !== 3) {
|
|
fwrite(STDERR, "Review recipients second page should report the requested offset\n");
|
|
exit(1);
|
|
}
|
|
|
|
echo "Review recipients paging regression test passed\n";
|