function FieldStorageConfigEntityUnitTest::testStoredCardinality

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

Class

FieldStorageConfigEntityUnitTest
@coversDefaultClass \Drupal\field\Entity\FieldStorageConfig

Namespace

Drupal\Tests\field\Unit

Code

public function testStoredCardinality() : void {
    $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.