function EntityLegacyTest::testEntityCreate

Tests deprecation of the entity_create() function.

@expectedDeprecation entity_create() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use the create() method of the entity type class directly or \Drupal::entityTypeManager()->getStorage($entity_type)->create($values) instead. See https://www.drupal.org/node/2266845

File

core/tests/Drupal/KernelTests/Core/Entity/EntityLegacyTest.php, line 144

Class

EntityLegacyTest
Tests legacy entity functions.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testEntityCreate() {
    $values = [
        'name' => $this->getRandomGenerator()
            ->sentences(2),
    ];
    $expected = EntityTest::create($values);
    $actual = entity_create('entity_test', $values);
    $this->assertEquals($expected->label(), $actual->label());
    $this->assertEquals($expected->getEntityTypeId(), $actual->getEntityTypeId());
    $this->assertInstanceOf(EntityTest::class, $actual);
}

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