reviewer-1.2.x-dev/tests/src/Kernel/Review/ReviewTest.php

tests/src/Kernel/Review/ReviewTest.php
<?php

declare(strict_types=1);

namespace Drupal\Tests\reviewer\Kernel\Review;

use Drupal\KernelTests\KernelTestBase;
use Drupal\reviewer\Reviewer\Action;
use Drupal\reviewer\Reviewer\Result\CollectionResultInterface;
use Drupal\reviewer\Reviewer\Result\IndividualResultInterface;
use Drupal\reviewer\Reviewer\Review\Review;
use Drupal\reviewer\Reviewer\Task\TaskInterface;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Group;

/**
 * Test review methods.
 */
#[Group('reviewer')]
#[CoversClass(Review::class)]
final class ReviewTest extends KernelTestBase {

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'reviewer',
  ];

  /**
   * Test running the review.
   *
   * @throws \PHPUnit\Framework\MockObject\Exception
   * @throws \Exception
   */
  public function testRun(): void {
    $result_one = $this->createMock(IndividualResultInterface::class);
    $result_one->method('getId')->willReturn('result_one');
    $collection_one = $this->createMock(CollectionResultInterface::class);
    $collection_one->method('getId')->willReturn('collection_one');
    $collection_one->method('getIndividualResults')->willReturn([$result_one]);
    $checklist_one = $this->createMock(TaskInterface::class);
    $checklist_one->method('getId')->willReturn('checklist_one');
    $checklist_one->method('getResults')->willReturn($collection_one);

    $result_two = $this->createMock(IndividualResultInterface::class);
    $result_two->method('getId')->willReturn('result_two');
    $collection_two = $this->createMock(CollectionResultInterface::class);
    $collection_two->method('getId')->willReturn('collection_two');
    $collection_two->method('getIndividualResults')->willReturn([$result_two]);
    $checklist_two = $this->createMock(TaskInterface::class);
    $checklist_two->method('getId')->willReturn('checklist_two');
    $checklist_two->method('getResults')->willReturn($collection_two);

    /**
     * @var array{
     *   string,
     *   string,
     *   array<string, \Drupal\reviewer\Reviewer\Checklist\ChecklistInterface>,
     *   array{id: string, reason: string}[],
     *   \Drupal\reviewer\Reviewer\Result\ResultFactoryInterface,
     * } $constructor_arguments
     */
    $constructor_arguments = [
      'checklist',
      'checklist',
      [
        $checklist_one->getId() => $checklist_one,
        $checklist_two->getId() => $checklist_two,
      ],
      [],
      $this->container->get('reviewer.factory.result'),
    ];

    $check = new Review(...$constructor_arguments);
    $check->run(Action::Check);
    self::assertCount(2, $check->getResults()->getAll());
    self::assertSame(['collection_one', 'collection_two'], array_keys($check->getResults()->getAll()));

    $fix = new Review(...$constructor_arguments);
    $fix->run(Action::Fix);
    self::assertCount(2, $fix->getResults()->getAll());
    self::assertSame(['collection_one', 'collection_two'], array_keys($fix->getResults()->getAll()));
  }

}

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

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