function ResourceTypeRepositoryTest::testMappingNameConflictCheck

Same name and namespace in other branches
  1. 11.x core/modules/jsonapi/tests/src/Kernel/ResourceType/ResourceTypeRepositoryTest.php \Drupal\Tests\jsonapi\Kernel\ResourceType\ResourceTypeRepositoryTest::testMappingNameConflictCheck()
  2. 9 core/modules/jsonapi/tests/src/Kernel/ResourceType/ResourceTypeRepositoryTest.php \Drupal\Tests\jsonapi\Kernel\ResourceType\ResourceTypeRepositoryTest::testMappingNameConflictCheck()
  3. 8.9.x core/modules/jsonapi/tests/src/Kernel/ResourceType/ResourceTypeRepositoryTest.php \Drupal\Tests\jsonapi\Kernel\ResourceType\ResourceTypeRepositoryTest::testMappingNameConflictCheck()

Ensures that a naming conflict in mapping causes an exception to be thrown.

@covers ::getFields
@dataProvider getFieldsProvider

File

core/modules/jsonapi/tests/src/Kernel/ResourceType/ResourceTypeRepositoryTest.php, line 131

Class

ResourceTypeRepositoryTest
@coversDefaultClass \Drupal\jsonapi\ResourceType\ResourceTypeRepository[[api-linebreak]] @group jsonapi @group #slow

Namespace

Drupal\Tests\jsonapi\Kernel\ResourceType

Code

public function testMappingNameConflictCheck($field_name_list) : void {
  $entity_type = \Drupal::entityTypeManager()->getDefinition('node');
  $bundle = 'article';
  $reflection_class = new \ReflectionClass($this->resourceTypeRepository);
  $reflection_method = $reflection_class->getMethod('getFields');
  $this->expectException(\LogicException::class);
  $this->expectExceptionMessage("The generated alias '{$field_name_list[1]}' for field name '{$field_name_list[0]}' conflicts with an existing field. Report this in the JSON:API issue queue!");
  $reflection_method->invokeArgs($this->resourceTypeRepository, [
    $field_name_list,
    $entity_type,
    $bundle,
  ]);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.