Add Event enum for trigger events

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
This commit is contained in:
Maurício Meneghini Fauth 2023-05-27 15:36:26 -03:00
parent 210521bae8
commit 7cdbfc2eaf
No known key found for this signature in database
GPG Key ID: 6A16FD38AFC89CC8
7 changed files with 28 additions and 10 deletions

View File

@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Triggers;
/**
* Indicates the kind of statement that activates the trigger.
*/
enum Event: string
{
case Insert = 'INSERT';
case Update = 'UPDATE';
case Delete = 'DELETE';
}

View File

@ -12,7 +12,7 @@ final class Trigger
public function __construct(
public readonly string $name,
public readonly string $timing,
public readonly string $event,
public readonly Event $event,
public readonly string $table,
public readonly string $statement,
public readonly string $definer,
@ -32,6 +32,8 @@ final class Trigger
Assert::string($name);
Assert::string($timing);
Assert::string($event);
$event = Event::tryFrom($event);
Assert::notNull($event);
Assert::string($table);
Assert::string($statement);
Assert::string($definer);

View File

@ -524,7 +524,7 @@ class Triggers
$oneResult['name'] = $newTrigger->name;
$oneResult['table'] = $newTrigger->table;
$oneResult['action_timing'] = $newTrigger->timing;
$oneResult['event_manipulation'] = $newTrigger->event;
$oneResult['event_manipulation'] = $newTrigger->event->value;
$oneResult['definition'] = $newTrigger->statement;
$oneResult['definer'] = $newTrigger->definer;
@ -536,7 +536,7 @@ class Triggers
"CREATE TRIGGER %s %s %s ON %s\n FOR EACH ROW %s\n%s\n",
$oneResult['full_trigger_name'],
$newTrigger->timing,
$newTrigger->event,
$newTrigger->event->value,
Util::backquote($newTrigger->table),
$newTrigger->statement,
$delimiter,

View File

@ -570,7 +570,7 @@ class ExportHtmlwordTest extends AbstractTestCase
[
'TRIGGER_SCHEMA' => 'database',
'TRIGGER_NAME' => 'tna"me',
'EVENT_MANIPULATION' => 'manip&',
'EVENT_MANIPULATION' => 'UPDATE',
'EVENT_OBJECT_TABLE' => 'table',
'ACTION_TIMING' => 'ac>t',
'ACTION_STATEMENT' => 'def',
@ -591,7 +591,7 @@ class ExportHtmlwordTest extends AbstractTestCase
$this->assertStringContainsString(
'<td class="print">tna&quot;me</td>' .
'<td class="print">ac&gt;t</td>' .
'<td class="print">manip&amp;</td>' .
'<td class="print">UPDATE</td>' .
'<td class="print">def</td>',
$result,
);

View File

@ -735,7 +735,7 @@ class ExportOdtTest extends AbstractTestCase
[
'TRIGGER_SCHEMA' => 'database',
'TRIGGER_NAME' => 'tna"me',
'EVENT_MANIPULATION' => 'manip&',
'EVENT_MANIPULATION' => 'INSERT',
'EVENT_OBJECT_TABLE' => 'ta<ble',
'ACTION_TIMING' => 'ac>t',
'ACTION_STATEMENT' => 'def',
@ -761,7 +761,7 @@ class ExportOdtTest extends AbstractTestCase
$this->assertStringContainsString('<text:p>ac&gt;t</text:p>', $result);
$this->assertStringContainsString('<text:p>manip&amp;</text:p>', $result);
$this->assertStringContainsString('<text:p>INSERT</text:p>', $result);
$this->assertStringContainsString('<text:p>def</text:p>', $result);
}

View File

@ -327,7 +327,7 @@ class ExportTexytextTest extends AbstractTestCase
[
'TRIGGER_SCHEMA' => 'database',
'TRIGGER_NAME' => 'tna"me',
'EVENT_MANIPULATION' => 'manip&',
'EVENT_MANIPULATION' => 'DELETE',
'EVENT_OBJECT_TABLE' => 'ta<ble',
'ACTION_TIMING' => 'ac>t',
'ACTION_STATEMENT' => 'def',
@ -344,7 +344,7 @@ class ExportTexytextTest extends AbstractTestCase
$result = $this->object->getTriggers('database', 'ta<ble');
$this->assertStringContainsString('|tna"me|ac>t|manip&|def', $result);
$this->assertStringContainsString('|tna"me|ac>t|DELETE|def', $result);
$this->assertStringContainsString('|Name|Time|Event|Definition', $result);
}

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace PhpMyAdmin\Tests\Triggers;
use PhpMyAdmin\Triggers\Event;
use PhpMyAdmin\Triggers\Trigger;
use PHPUnit\Framework\TestCase;
@ -26,7 +27,7 @@ class TriggerTest extends TestCase
$this->assertNotNull($actual);
$this->assertSame('trigger_name', $actual->name);
$this->assertSame('BEFORE', $actual->timing);
$this->assertSame('UPDATE', $actual->event);
$this->assertSame(Event::Update, $actual->event);
$this->assertSame('test_table', $actual->table);
$this->assertSame('BEGIN END', $actual->statement);
$this->assertSame('definer@localhost', $actual->definer);