You are here

public function SwaggerUiLibraryDiscoveryTest::testWithMalformedPackageJson in Swagger UI Field Formatter 8.3

Tests with malformed package.json.

File

tests/src/Unit/SwaggerUiLibraryDiscoveryTest.php, line 202

Class

SwaggerUiLibraryDiscoveryTest
Tests the Swagger UI library discovery service.

Namespace

Drupal\Tests\swagger_ui_formatter\Unit

Code

public function testWithMalformedPackageJson() : void {
  $this
    ->setUpLibraryVersionTest();

  // Imitate an invalid package.json with a specific library directory.
  $this->cache
    ->method('get')
    ->willReturn((object) [
    'data' => SWAGGER_UI_FORMATTER_TEST_INVALID_PACKAGE_JSON_DIR,
  ]);
  $this
    ->expectException(SwaggerUiLibraryDiscoveryException::class);
  $this
    ->expectExceptionCode(SwaggerUiLibraryDiscoveryException::CODE_CANNOT_DECODE_PACKAGE_JSON);
  $this->swaggerUiLibraryDiscovery
    ->libraryVersion();
}