reviewer-1.2.x-dev/tests/src/Unit/StatusFactoryTest.php

tests/src/Unit/StatusFactoryTest.php
<?php

declare(strict_types=1);

namespace Drupal\Tests\reviewer\Unit;

use Drupal\reviewer\Reviewer\Result\ResultInterface;
use Drupal\reviewer\Reviewer\Status\Status;
use Drupal\reviewer\Reviewer\Status\StatusFactory;
use Drupal\reviewer\Reviewer\Status\StatusFactoryInterface;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Group;

/**
 * Tests the status factory.
 */
#[Group('reviewer')]
#[CoversClass(StatusFactory::class)]
final class StatusFactoryTest extends UnitTestCase {

  private readonly StatusFactoryInterface $statusFactory;

  private readonly ResultInterface $notRun;

  private readonly ResultInterface $pass;

  private readonly ResultInterface $fixed;

  private readonly ResultInterface $ignoredFailure;

  private readonly ResultInterface $ignoredError;

  private readonly ResultInterface $fail;

  private readonly ResultInterface $error;

  /**
   * {@inheritdoc}
   *
   * @throws \PHPUnit\Framework\MockObject\Exception
   */
  protected function setUp(): void {
    parent::setUp();
    $this->statusFactory = new StatusFactory();
    $this->notRun = $this->createMock(ResultInterface::class);
    $this->notRun->method('getStatus')->willReturn(Status::NotRun);
    $this->pass = $this->createMock(ResultInterface::class);
    $this->pass->method('getStatus')->willReturn(Status::Pass);
    $this->fixed = $this->createMock(ResultInterface::class);
    $this->fixed->method('getStatus')->willReturn(Status::Fixed);
    $this->ignoredFailure = $this->createMock(ResultInterface::class);
    $this->ignoredFailure->method('getStatus')->willReturn(Status::IgnoredFailure);
    $this->ignoredError = $this->createMock(ResultInterface::class);
    $this->ignoredError->method('getStatus')->willReturn(Status::IgnoredError);
    $this->fail = $this->createMock(ResultInterface::class);
    $this->fail->method('getStatus')->willReturn(Status::Fail);
    $this->error = $this->createMock(ResultInterface::class);
    $this->error->method('getStatus')->willReturn(Status::Error);
  }

  /**
   * Test ignoring statuses.
   */
  public function testCreateIgnored(): void {
    self::assertSame(
      Status::IgnoredFailure,
      $this->statusFactory->createIgnored(Status::Fail),
    );
    self::assertSame(
      Status::IgnoredError,
      $this->statusFactory->createIgnored(Status::Error),
    );

    self::assertSame(
      Status::IgnoredFailure,
      $this->statusFactory->createIgnored(Status::IgnoredFailure),
    );
    self::assertSame(
      Status::IgnoredError,
      $this->statusFactory->createIgnored(Status::IgnoredError),
    );
    self::assertSame(
      Status::NotRun,
      $this->statusFactory->createIgnored(Status::NotRun),
    );
    self::assertSame(
      Status::Pass,
      $this->statusFactory->createIgnored(Status::Pass),
    );
    self::assertSame(
      Status::Fixed,
      $this->statusFactory->createIgnored(Status::Fixed),
    );
  }

  /**
   * Test unignoring statuses.
   */
  public function testCreateUnignored(): void {
    self::assertSame(
      Status::Fail,
      $this->statusFactory->createUnignored(Status::IgnoredFailure),
    );
    self::assertSame(
      Status::Error,
      $this->statusFactory->createUnignored(Status::IgnoredError),
    );

    self::assertSame(
      Status::Fail,
      $this->statusFactory->createUnignored(Status::Fail),
    );
    self::assertSame(
      Status::Error,
      $this->statusFactory->createUnignored(Status::Error),
    );
    self::assertSame(
      Status::NotRun,
      $this->statusFactory->createUnignored(Status::NotRun),
    );
    self::assertSame(
      Status::Pass,
      $this->statusFactory->createUnignored(Status::Pass),
    );
    self::assertSame(
      Status::Fixed,
      $this->statusFactory->createUnignored(Status::Fixed),
    );
  }

  /**
   * Test creating a status from a boolean.
   */
  public function testCreateFromBool(): void {
    self::assertSame(Status::Fail, $this->statusFactory->createFromBool(FALSE));
    self::assertSame(Status::Pass, $this->statusFactory->createFromBool(TRUE));
  }

  /**
   * Test creating the most severe status from an array of results.
   */
  public function testCreateMostSevere(): void {
    self::assertSame(
      Status::NotRun,
      $this->statusFactory->createMostSevere([
        $this->notRun,
      ]),
    );

    self::assertSame(
      Status::Pass,
      $this->statusFactory->createMostSevere([
        $this->pass,
        $this->pass,
      ]),
    );

    self::assertSame(
      Status::Fixed,
      $this->statusFactory->createMostSevere([
        $this->pass,
        $this->fixed,
        $this->notRun,
      ]),
    );

    self::assertSame(
      Status::IgnoredFailure,
      $this->statusFactory->createMostSevere([
        $this->pass,
        $this->pass,
        $this->ignoredFailure,
        $this->ignoredFailure,
        $this->notRun,
        $this->pass,
        $this->pass,
        $this->fixed,
      ]),
    );

    self::assertSame(
      Status::IgnoredError,
      $this->statusFactory->createMostSevere([
        $this->pass,
        $this->ignoredError,
        $this->ignoredFailure,
        $this->ignoredFailure,
        $this->notRun,
        $this->pass,
        $this->pass,
        $this->fixed,
      ]),
    );

    self::assertSame(
      Status::Fail,
      $this->statusFactory->createMostSevere([
        $this->fail,
        $this->ignoredError,
        $this->ignoredFailure,
        $this->ignoredFailure,
        $this->notRun,
        $this->pass,
        $this->pass,
        $this->fixed,
      ]),
    );

    self::assertSame(
      Status::Error,
      $this->statusFactory->createMostSevere([
        $this->error,
        $this->fail,
        $this->ignoredError,
        $this->ignoredFailure,
        $this->notRun,
        $this->pass,
        $this->pass,
        $this->fixed,
      ]),
    );
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc