reviewer-1.2.x-dev/modules/reviewer_test_kit/tests/src/Kernel/ReviewerTestKitKernelTestBase.php
modules/reviewer_test_kit/tests/src/Kernel/ReviewerTestKitKernelTestBase.php
<?php
declare(strict_types=1);
namespace Drupal\Tests\reviewer_test_kit\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Drupal\reviewer\Reviewer\Action;
use Drupal\reviewer\Reviewer\Result\IndividualResultInterface;
use Drupal\reviewer\Reviewer\Review\ReviewInterface;
use Drupal\reviewer\Reviewer\Review\ReviewRunner;
/**
* Base class for reviewer test kit kernel tests.
*/
abstract class ReviewerTestKitKernelTestBase extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'system',
'reviewer',
'reviewer_test',
'reviewer_test_kit',
'reviewer_test_kit_test',
];
protected ReviewRunner $runner;
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->runner = $this->container->get('reviewer.review_runner');
}
/**
* Run a review which has one task and return it.
*
* @throws \Exception
* @throws \PHPUnit\Framework\ExpectationFailedException
* @throws \PHPUnit\Framework\UnknownClassOrInterfaceException
*/
protected function runOneTaskReview(Action $action, string $id): ReviewInterface {
$reviews = $this->runner->runIds($action, [$id]);
$review = array_shift($reviews);
self::assertInstanceOf(ReviewInterface::class, $review);
return $review;
}
/**
* Get the result from a review which has one task.
*
* @throws \Exception
* @throws \PHPUnit\Framework\ExpectationFailedException
* @throws \PHPUnit\Framework\UnknownClassOrInterfaceException
*/
protected function firstResultFromReview(ReviewInterface $review): IndividualResultInterface {
$results = $review->getResults()->getIndividualResults();
$result = array_shift($results);
self::assertInstanceOf(IndividualResultInterface::class, $result);
return $result;
}
/**
* Run a review which has one task and return the result.
*
* @throws \Exception
* @throws \PHPUnit\Framework\ExpectationFailedException
* @throws \PHPUnit\Framework\UnknownClassOrInterfaceException
*/
protected function runOneTaskReviewAndGetResult(Action $action, string $review): IndividualResultInterface {
return $this->firstResultFromReview($this->runOneTaskReview($action, $review));
}
}
