You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virt/web/tests/CloudSetupReferralMigration...

38 lines
1.7 KiB
PHTML

<?php
// Static contract test: online updates must apply the referral migration
// before the new registration and promotion code paths are used.
$root = dirname(__DIR__);
$read = static function (string $relative) use ($root): string {
$contents = file_get_contents($root . '/' . $relative);
if ($contents === false) {
throw new RuntimeException('Cannot read ' . $relative);
}
return $contents;
};
$assert = static function ($condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$setup = $read('app/Command/CloudSetup.php');
$migration = $read('sql/referral_affiliate_code.sql');
$assert(str_contains($setup, 'self::upgradeReferralSchema($connection);'),
'cloudInit does not invoke the referral schema migration.');
$assert(str_contains($setup, "self::schema('referral_affiliate_code.sql')"),
'cloudInit does not load the versioned referral migration.');
$assert(str_contains($setup, "hasTable('ss_invite_code')"),
'cloudInit does not guard the legacy invite-code table prerequisite.');
$assert(str_contains($setup, 'ReferralConfig::clearCache();'),
'cloudInit does not clear the referral configuration cache after migration.');
$assert(str_contains($migration, 'CREATE TABLE IF NOT EXISTS `referral_code_generation_locks`'),
'Referral migration is not idempotent for the generation lock table.');
$assert(str_contains($migration, 'INSERT IGNORE INTO `referral_code_generation_locks`'),
'Referral migration does not seed the generation lock row.');
$assert(str_contains($migration, 'COLLATE utf8mb4_bin'),
'Referral migration does not enforce case-sensitive code collation.');
echo "Cloud setup referral migration contract checks passed.\n";