<?php

declare(strict_types=1);

namespace Drupal\Tests\flowdrop_interrupt\Unit\Enum;

use Drupal\flowdrop_interrupt\Enum\InterruptDirection;
use Drupal\Tests\UnitTestCase;

/**
 * Tests the InterruptDirection enum.
 *
 * @coversDefaultClass \Drupal\flowdrop_interrupt\Enum\InterruptDirection
 * @group flowdrop_interrupt
 */
class InterruptDirectionTest extends UnitTestCase {

  /**
   * The enum has exactly two cases with stable string values.
   *
   * The values are persisted on the entity column; changing them is a
   * BC-breaking change requiring a migration.
   */
  public function testCasesAndValues(): void {
    $cases = InterruptDirection::cases();
    $this->assertCount(2, $cases);
    $this->assertSame('outward', InterruptDirection::Outward->value);
    $this->assertSame('inward', InterruptDirection::Inward->value);
  }

  /**
   * TryFrom returns the expected case for known values, NULL otherwise.
   */
  public function testTryFrom(): void {
    $this->assertSame(InterruptDirection::Outward, InterruptDirection::tryFrom('outward'));
    $this->assertSame(InterruptDirection::Inward, InterruptDirection::tryFrom('inward'));
    $this->assertNull(InterruptDirection::tryFrom('sideways'));
    $this->assertNull(InterruptDirection::tryFrom(''));
  }

}
