<?php

declare(strict_types=1);

namespace Drupal\Tests\flowdrop_trigger\Unit\Event;

use Drupal\Tests\UnitTestCase;
use Drupal\flowdrop_trigger\Event\TriggerPreExecuteEvent;
use Drupal\Tests\flowdrop\Unit\Traits\InterfaceContractTestTrait;
use Symfony\Contracts\EventDispatcher\Event;

/**
 * Tests the TriggerPreExecuteEvent.
 *
 * @coversDefaultClass \Drupal\flowdrop_trigger\Event\TriggerPreExecuteEvent
 * @group flowdrop_trigger
 */
class TriggerPreExecuteEventTest extends UnitTestCase {

  use InterfaceContractTestTrait;

  /**
   * Tests the event extends Symfony Event.
   */
  public function testExtendsEvent(): void {
    $ref = new \ReflectionClass(TriggerPreExecuteEvent::class);
    $this->assertTrue($ref->isSubclassOf(Event::class));
  }

  /**
   * Tests the event name constant.
   */
  public function testEventName(): void {
    $this->assertEquals('flowdrop_trigger.pre_execute', TriggerPreExecuteEvent::NAME);
  }

  /**
   * Tests constructor has expected readonly properties.
   */
  public function testConstructorProperties(): void {
    $ref = new \ReflectionClass(TriggerPreExecuteEvent::class);
    $constructor = $ref->getConstructor();
    $this->assertNotNull($constructor);

    $params = array_map(fn(\ReflectionParameter $p) => $p->getName(), $constructor->getParameters());
    $this->assertEquals(['config', 'eventType', 'workflow', 'entity', 'formId'], $params);

    // Verify readonly public properties.
    $this->assertTrue($ref->getProperty('config')->isReadOnly());
    $this->assertTrue($ref->getProperty('eventType')->isReadOnly());
    $this->assertTrue($ref->getProperty('workflow')->isReadOnly());
  }

}
