private function triggerEndingTest($triggerAction) { $audit_columns = new TableColumnsMetadata(); $table_columns = new TableColumnsMetadata([['column_name' => 'x', 'column_type' => 'int(11)', 'is_nullable' => 'YES', 'character_set_name' => null, 'collation_name' => null]]); $helper = new CreateAuditTrigger('test_data', 'test_audit', 'MY_TABLE', 'my_trigger', $triggerAction, $audit_columns, $table_columns, null, []); $sql = $helper->buildStatement(); // Code must have one EOL at the end. $this->assertRegExp('/\\r?\\n$/', $sql, sprintf('Single EOL: %s', $triggerAction)); // Code must have one and only EOL at the end. $this->assertNotRegExp('/\\r?\\n\\r?\\n$/', $sql, sprintf('Double EOL: %s', $triggerAction)); // Code must not have a semicolon at the end. $this->assertNotRegExp('/;$/', trim($sql), sprintf('Semicolon: %s', $triggerAction)); }
/** * Creates a trigger on a table. * * @param string $dataSchemaName The name of the data schema. * @param string $auditSchemaName The name of the audit schema. * @param string $tableName The name of the table. * @param string $triggerAction The trigger action (i.e. INSERT, UPDATE, or DELETE). * @param string $triggerName The name of the trigger. * @param TableColumnsMetadata $auditColumns The audit table columns. * @param TableColumnsMetadata $tableColumns The data table columns. * @param string $skipVariable The skip variable. * @param string[] $additionSql Additional SQL statements. */ public static function createAuditTrigger($dataSchemaName, $auditSchemaName, $tableName, $triggerAction, $triggerName, $auditColumns, $tableColumns, $skipVariable, $additionSql) { $helper = new CreateAuditTrigger($dataSchemaName, $auditSchemaName, $tableName, $triggerAction, $triggerName, $auditColumns, $tableColumns, $skipVariable, $additionSql); $sql = $helper->buildStatement(); self::executeNone($sql); }