function SqlContentEntityStorageSchemaTest::providerSchemaCastValue

Same name in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageSchemaTest::providerSchemaCastValue()
  2. 10 core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageSchemaTest::providerSchemaCastValue()
  3. 11.x core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php \Drupal\Tests\Core\Entity\Sql\SqlContentEntityStorageSchemaTest::providerSchemaCastValue()

Provides data for testCastValue().

File

core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php, line 1584

Class

SqlContentEntityStorageSchemaTest
@coversDefaultClass \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema @group Entity

Namespace

Drupal\Tests\Core\Entity\Sql

Code

public function providerSchemaCastValue() {
    $cases = [];
    // Tests NULL values.
    $cases[] = [
        NULL,
        NULL,
        [
            'not null' => FALSE,
        ],
    ];
    $cases[] = [
        0,
        NULL,
        [
            'not null' => TRUE,
            'type' => 'int',
        ],
    ];
    $cases[] = [
        0,
        NULL,
        [
            'not null' => TRUE,
            'type' => 'serial',
        ],
    ];
    $cases[] = [
        0.0,
        NULL,
        [
            'not null' => TRUE,
            'type' => 'float',
        ],
    ];
    $cases[] = [
        '',
        NULL,
        [
            'not null' => TRUE,
            'type' => 'varchar',
        ],
    ];
    // Tests cast to int and serial.
    $cases[] = [
        1,
        '1.001',
        [
            'type' => 'int',
        ],
    ];
    $cases[] = [
        2,
        2.6,
        [
            'type' => 'int',
        ],
    ];
    $cases[] = [
        3,
        '3.6',
        [
            'type' => 'serial',
        ],
    ];
    // Tests float.
    $cases[] = [
        1.001,
        '1.001',
        [
            'type' => 'float',
        ],
    ];
    $cases[] = [
        2.6,
        2.6,
        [
            'type' => 'float',
        ],
    ];
    // Tests other column types casts to string.
    $cases[] = [
        '1',
        1,
        [
            'type' => 'varchar',
        ],
    ];
    $cases[] = [
        '2',
        '2',
        [
            'type' => 'varchar',
        ],
    ];
    return $cases;
}

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