You are here

public function ResourceResponseValidatorTest::setUp in JSON:API 8.2

Same name and namespace in other branches
  1. 8 tests/src/Unit/EventSubscriber/ResourceResponseValidatorTest.php \Drupal\Tests\jsonapi\Unit\EventSubscriber\ResourceResponseValidatorTest::setUp()

Overrides UnitTestCase::setUp

File

tests/src/Unit/EventSubscriber/ResourceResponseValidatorTest.php, line 40

Class

ResourceResponseValidatorTest
@coversDefaultClass \Drupal\jsonapi\EventSubscriber\ResourceResponseValidator @group jsonapi

Namespace

Drupal\Tests\jsonapi\Unit\EventSubscriber

Code

public function setUp() {
  parent::setUp();

  // Check that the validation class is available.
  if (!class_exists("\\JsonSchema\\Validator")) {
    $this
      ->fail('The JSON Schema validator is missing. You can install it with `composer require justinrainbow/json-schema`.');
  }
  $module_handler = $this
    ->prophesize(ModuleHandlerInterface::class);
  $module = $this
    ->prophesize(Extension::class);
  $module_path = dirname(dirname(dirname(dirname(__DIR__))));
  $module
    ->getPath()
    ->willReturn($module_path);
  $module_handler
    ->getModule('jsonapi')
    ->willReturn($module
    ->reveal());
  $encoders = [
    new JsonEncoder(),
  ];
  if (class_exists(JsonSchemaEncoder::class)) {
    $encoders[] = new JsonSchemaEncoder();
  }
  $subscriber = new ResourceResponseValidator(new Serializer([], $encoders), $this
    ->prophesize(LoggerInterface::class)
    ->reveal(), $module_handler
    ->reveal(), '');
  $subscriber
    ->setValidator();
  $this->subscriber = $subscriber;
}