function FieldStorageConfigEntityUnitTest::testStoredCardinality

Same name in other branches
  1. 8.9.x core/modules/field/tests/src/Unit/FieldStorageConfigEntityUnitTest.php \Drupal\Tests\field\Unit\FieldStorageConfigEntityUnitTest::testStoredCardinality()
  2. 10 core/modules/field/tests/src/Unit/FieldStorageConfigEntityUnitTest.php \Drupal\Tests\field\Unit\FieldStorageConfigEntityUnitTest::testStoredCardinality()
  3. 11.x 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

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());
}

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