$end = date('Y-m-d', strtotime($start . ' +1 month'));
$suffix = str_replace('-', '_', $yearMonth);
+ // DDL не поддерживает bind params — используем интерполяцию (формат валидирован regex)
$this->db->createCommand()
- ->setSql("CREATE TABLE IF NOT EXISTS stock_history_{$suffix} PARTITION OF stock_history FOR VALUES FROM (:start) TO (:end)")
- ->bindValues([':start' => $start, ':end' => $end])
+ ->setSql("CREATE TABLE IF NOT EXISTS stock_history_{$suffix} PARTITION OF stock_history FOR VALUES FROM ('{$start}') TO ('{$end}')")
->execute();
}
$db->method('createCommand')->willReturn($command);
$executedSql = [];
- $boundParams = [];
$command->method('setSql')->willReturnCallback(
function ($sql) use ($command, &$executedSql) {
$executedSql[] = $sql;
return $command;
}
);
- $command->method('bindValues')->willReturnCallback(
- function ($values) use ($command, &$boundParams) {
- $boundParams = array_merge($boundParams, $values);
- return $command;
- }
- );
$command->method('execute')->willReturn(0);
$service = new StockHistoryService($db);
$sql = implode(' ', $executedSql);
$this->assertStringContainsString('PARTITION OF', $sql);
$this->assertStringContainsString('stock_history_2026_04', $sql);
- $this->assertEquals('2026-04-01', $boundParams[':start']);
- $this->assertEquals('2026-05-01', $boundParams[':end']);
+ $this->assertStringContainsString('2026-04-01', $sql);
+ $this->assertStringContainsString('2026-05-01', $sql);
}
public function testCreatePartition_InvalidFormat_ThrowsException(): void
return $command;
}
);
- $command->method('bindValues')->willReturnSelf();
$command->method('execute')->willReturn(0);
$service = new StockHistoryService($db);