<?php

declare(strict_types=1);

namespace Drupal\Tests\flowdrop_trigger\Unit\Event;

use Drupal\Tests\UnitTestCase;
use Drupal\flowdrop_trigger\Event\TriggerPostExecuteEvent;
use Symfony\Contracts\EventDispatcher\Event;

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

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

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

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

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

    $this->assertTrue($ref->getProperty('config')->isReadOnly());
    $this->assertTrue($ref->getProperty('eventType')->isReadOnly());
    $this->assertTrue($ref->getProperty('response')->isReadOnly());
  }

}
