You are here

public function FieldStorageConfigEntityUnitTest::testStoredCardinality in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/field/tests/src/Unit/FieldStorageConfigEntityUnitTest.php \Drupal\Tests\field\Unit\FieldStorageConfigEntityUnitTest::testStoredCardinality()

Tests stored cardinality.

@covers ::getCardinality

File

core/modules/field/tests/src/Unit/FieldStorageConfigEntityUnitTest.php, line 120
Contains \Drupal\Tests\field\Unit\FieldStorageConfigEntityUnitTest.

Class

FieldStorageConfigEntityUnitTest
@coversDefaultClass \Drupal\field\Entity\FieldStorageConfig

Namespace

Drupal\Tests\field\Unit

Code

public function testStoredCardinality() {
  $this->fieldTypeManager
    ->expects($this
    ->any())
    ->method('getDefinition')
    ->with('test_field_type')
    ->willReturn([
    'class' => TestFieldType::class,
    // The field type definition has no enforced cardinality.
    'cardinality' => NULL,
  ]);
  $field_storage = new FieldStorageConfig([
    'entity_type' => 'entity_test',
    'field_name' => 'test_field',
    'type' => 'test_field_type',
    'module' => 'test_module',
  ]);
  $field_storage
    ->setCardinality(8);

  // Check that the stored cardinality is returned.
  $this
    ->assertEquals(8, $field_storage
    ->getCardinality());
}