diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php
index ab2fb10..ddf4e99 100644
--- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php
+++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php
@@ -197,7 +197,9 @@ public function disable() {
    * {@inheritdoc}
    */
   public function setStatus($status) {
-    $this->status = (bool) $status;
+    if ($status_key = $this->getEntityType()->getKey('status')) {
+      $this->{$status_key} = (bool) $status;
+    }
     return $this;
   }
 
@@ -205,7 +207,8 @@ public function setStatus($status) {
    * {@inheritdoc}
    */
   public function status() {
-    return !empty($this->status);
+    $status_key = $this->getEntityType()->getKey('status');
+    return $status_key && !empty($this->{$status_key});
   }
 
   /**
@@ -253,13 +256,20 @@ public function createDuplicate() {
    * Helper callback for uasort() to sort configuration entities by weight and label.
    */
   public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b) {
-    $a_weight = isset($a->weight) ? $a->weight : 0;
-    $b_weight = isset($b->weight) ? $b->weight : 0;
-    if ($a_weight == $b_weight) {
-      $a_label = $a->label();
-      $b_label = $b->label();
-      return strnatcasecmp($a_label, $b_label);
+    $entity_type = $a->getEntityType();
+    if ($entity_type->hasKey('weight')) {
+      $weight_key = $entity_type->getKey('weight');
+      $a_weight = isset($a->{$weight_key}) ? $a->{$weight_key} : 0;
+      $b_weight = isset($b->{$weight_key}) ? $b->{$weight_key} : 0;
     }
+    else {
+      $a_weight = $b_weight = 0;
+    }
+
+    if ($a_weight == $b_weight) {
+      return strnatcasecmp($a->label(), $b->label());
+    }
+
     return ($a_weight < $b_weight) ? -1 : 1;
   }
 
diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php
index 2a4b199..2fe6a9c 100644
--- a/core/lib/Drupal/Core/Entity/Entity.php
+++ b/core/lib/Drupal/Core/Entity/Entity.php
@@ -99,7 +99,8 @@ protected function uuidGenerator() {
    * {@inheritdoc}
    */
   public function id() {
-    return isset($this->id) ? $this->id : NULL;
+    $id_key = $this->getEntityType()->getKey('id');
+    return $id_key && isset($this->{$id_key}) ? $this->{$id_key} : NULL;
   }
 
   /**
diff --git a/core/lib/Drupal/Core/Entity/Entity/EntityFormMode.php b/core/lib/Drupal/Core/Entity/Entity/EntityFormMode.php
index 1fed80c..0153b13 100644
--- a/core/lib/Drupal/Core/Entity/Entity/EntityFormMode.php
+++ b/core/lib/Drupal/Core/Entity/Entity/EntityFormMode.php
@@ -32,7 +32,8 @@
  *   label = @Translation("Form mode"),
  *   entity_keys = {
  *     "id" = "id",
- *     "label" = "label"
+ *     "label" = "label",
+ *     "status" = "status",
  *   },
  *   config_export = {
  *     "id",
diff --git a/core/lib/Drupal/Core/Entity/Entity/EntityViewMode.php b/core/lib/Drupal/Core/Entity/Entity/EntityViewMode.php
index 08eb661..bcea607 100644
--- a/core/lib/Drupal/Core/Entity/Entity/EntityViewMode.php
+++ b/core/lib/Drupal/Core/Entity/Entity/EntityViewMode.php
@@ -34,7 +34,8 @@
  *   label = @Translation("View mode"),
  *   entity_keys = {
  *     "id" = "id",
- *     "label" = "label"
+ *     "label" = "label",
+ *     "status" = "status",
  *   },
  *   config_export = {
  *     "id",
diff --git a/core/modules/block/src/Entity/Block.php b/core/modules/block/src/Entity/Block.php
index 8a65843..ee70a56 100644
--- a/core/modules/block/src/Entity/Block.php
+++ b/core/modules/block/src/Entity/Block.php
@@ -33,7 +33,8 @@
  *   },
  *   admin_permission = "administer blocks",
  *   entity_keys = {
- *     "id" = "id"
+ *     "id" = "id",
+ *     "status" = "status",
  *   },
  *   links = {
  *     "delete-form" = "/admin/structure/block/manage/{block}/delete",
diff --git a/core/modules/config/src/Tests/ConfigEntityListTest.php b/core/modules/config/src/Tests/ConfigEntityListTest.php
index 9b74a5f..28a4eb7 100644
--- a/core/modules/config/src/Tests/ConfigEntityListTest.php
+++ b/core/modules/config/src/Tests/ConfigEntityListTest.php
@@ -119,7 +119,7 @@ function testList() {
     ));
     $entity->save();
     $list = $controller->load();
-    $this->assertIdentical(array_keys($list), array('beta', 'dotted.default', 'alpha', 'omega'));
+    $this->assertIdentical(array_keys($list), array('alpha', 'beta', 'dotted.default', 'omega'));
 
     // Test that config entities that do not support status, do not have
     // enable/disable operations.
@@ -209,7 +209,7 @@ function testListUI() {
 
     // Edit the entity using the operations link.
     $this->assertLinkByHref('admin/structure/config_test/manage/antelope');
-    $this->clickLink('Edit', 1);
+    $this->clickLink('Edit', 0);
     $this->assertResponse(200);
     $this->assertTitle('Edit Antelope | Drupal');
     $edit = array('label' => 'Albatross', 'id' => 'albatross');
@@ -223,7 +223,7 @@ function testListUI() {
 
     // Delete the added entity using the operations link.
     $this->assertLinkByHref('admin/structure/config_test/manage/albatross/delete');
-    $this->clickLink('Delete', 1);
+    $this->clickLink('Delete', 0);
     $this->assertResponse(200);
     $this->assertTitle('Are you sure you want to delete the test configuration Albatross? | Drupal');
     $this->drupalPostForm(NULL, array(), t('Delete'));
diff --git a/core/modules/editor/src/Entity/Editor.php b/core/modules/editor/src/Entity/Editor.php
index 0100671..d8c1c9b 100644
--- a/core/modules/editor/src/Entity/Editor.php
+++ b/core/modules/editor/src/Entity/Editor.php
@@ -17,7 +17,8 @@
  *   id = "editor",
  *   label = @Translation("Text Editor"),
  *   entity_keys = {
- *     "id" = "format"
+ *     "id" = "format",
+ *     "status" = "status",
  *   },
  *   config_export = {
  *     "format",
diff --git a/core/modules/language/tests/src/Unit/ConfigurableLanguageUnitTest.php b/core/modules/language/tests/src/Unit/ConfigurableLanguageUnitTest.php
index 02e7457..d853764 100644
--- a/core/modules/language/tests/src/Unit/ConfigurableLanguageUnitTest.php
+++ b/core/modules/language/tests/src/Unit/ConfigurableLanguageUnitTest.php
@@ -6,6 +6,9 @@
 
 namespace Drupal\Tests\language\Unit;
 
+use Drupal\Core\DependencyInjection\ContainerBuilder;
+use Drupal\Core\Entity\EntityManagerInterface;
+use Drupal\Core\Entity\EntityTypeInterface;
 use Drupal\language\Entity\ConfigurableLanguage;
 use Drupal\Tests\UnitTestCase;
 
@@ -19,6 +22,23 @@
 class ConfigurableLanguageUnitTest extends UnitTestCase {
 
   /**
+   * {@inheritdoc}
+   */
+  protected function setUp() {
+    parent::setUp();
+
+    $entity_type = $this->prophesize(EntityTypeInterface::class);
+    $entity_type->getKey('id')->willReturn('id');
+
+    $entity_manager = $this->prophesize(EntityManagerInterface::class);
+    $entity_manager->getDefinition('configurable_language')->willReturn($entity_type->reveal());
+
+    $container = new ContainerBuilder();
+    $container->set('entity.manager', $entity_manager->reveal());
+    \Drupal::setContainer($container);
+  }
+
+  /**
    * @covers ::getDirection
    */
   public function testDirection() {
diff --git a/core/modules/migrate/tests/src/Unit/Entity/MigrationTest.php b/core/modules/migrate/tests/src/Unit/Entity/MigrationTest.php
index 73ab716..b08385a 100644
--- a/core/modules/migrate/tests/src/Unit/Entity/MigrationTest.php
+++ b/core/modules/migrate/tests/src/Unit/Entity/MigrationTest.php
@@ -7,6 +7,9 @@
 
 namespace Drupal\Tests\migrate\Unit\Entity;
 
+use Drupal\Core\DependencyInjection\ContainerBuilder;
+use Drupal\Core\Entity\EntityManagerInterface;
+use Drupal\Core\Entity\EntityTypeInterface;
 use Drupal\migrate\Entity\Migration;
 use Drupal\Tests\UnitTestCase;
 
@@ -24,6 +27,16 @@ class MigrationTest extends UnitTestCase {
    * @covers ::getProcessPlugins
    */
   public function testGetProcessPlugins() {
+    $entity_type = $this->prophesize(EntityTypeInterface::class);
+    $entity_type->getKey('id')->willReturn('id');
+
+    $entity_manager = $this->prophesize(EntityManagerInterface::class);
+    $entity_manager->getDefinition('migration')->willReturn($entity_type->reveal());
+
+    $container = new ContainerBuilder();
+    $container->set('entity.manager', $entity_manager->reveal());
+    \Drupal::setContainer($container);
+
     $migration = new Migration([], 'migration');
     $this->assertEquals([], $migration->getProcessPlugins([]));
   }
diff --git a/core/modules/rest/tests/src/Unit/CollectRoutesTest.php b/core/modules/rest/tests/src/Unit/CollectRoutesTest.php
index 8b5d215..c3519a7 100644
--- a/core/modules/rest/tests/src/Unit/CollectRoutesTest.php
+++ b/core/modules/rest/tests/src/Unit/CollectRoutesTest.php
@@ -7,6 +7,8 @@
 
 namespace Drupal\Tests\rest\Unit;
 
+use Drupal\Core\Entity\EntityManagerInterface;
+use Drupal\Core\Entity\EntityTypeInterface;
 use Drupal\Tests\UnitTestCase;
 use Drupal\Core\DependencyInjection\ContainerBuilder;
 use Drupal\rest\Plugin\views\display\RestExport;
@@ -38,7 +40,15 @@ class CollectRoutesTest extends UnitTestCase {
   protected function setUp() {
     parent::setUp();
 
+    $entity_type = $this->prophesize(EntityTypeInterface::class);
+    $entity_type->getKey('id')->willReturn('id');
+
+    $entity_manager = $this->prophesize(EntityManagerInterface::class);
+    $entity_manager->getDefinition('view')->willReturn($entity_type->reveal());
+
     $container = new ContainerBuilder();
+    $container->set('entity.manager', $entity_manager->reveal());
+    \Drupal::setContainer($container);
 
     $request = $this->getMockBuilder('\Symfony\Component\HttpFoundation\Request')
       ->disableOriginalConstructor()
diff --git a/core/modules/search/src/SearchPageRepository.php b/core/modules/search/src/SearchPageRepository.php
index 66f7bda..17dd363 100644
--- a/core/modules/search/src/SearchPageRepository.php
+++ b/core/modules/search/src/SearchPageRepository.php
@@ -110,7 +110,9 @@ public function setDefaultSearchPage(SearchPageInterface $search_page) {
    */
   public function sortSearchPages($search_pages) {
     $entity_type = $this->storage->getEntityType();
-    uasort($search_pages, array($entity_type->getClass(), 'sort'));
+    // Suppress errors because PHPUnit will indirectly modify the contents,
+    // triggering https://bugs.php.net/bug.php?id=50688.
+    @uasort($search_pages, array($entity_type->getClass(), 'sort'));
     return $search_pages;
   }
 
diff --git a/core/modules/search/tests/src/Unit/SearchPageRepositoryTest.php b/core/modules/search/tests/src/Unit/SearchPageRepositoryTest.php
index 767a81b..8cac4fd 100644
--- a/core/modules/search/tests/src/Unit/SearchPageRepositoryTest.php
+++ b/core/modules/search/tests/src/Unit/SearchPageRepositoryTest.php
@@ -7,6 +7,8 @@
 
 namespace Drupal\Tests\search\Unit;
 
+use Drupal\Core\DependencyInjection\ContainerBuilder;
+use Drupal\Core\Entity\EntityManagerInterface;
 use Drupal\search\Entity\SearchPage;
 use Drupal\search\SearchPageRepository;
 use Drupal\Tests\UnitTestCase;
@@ -256,6 +258,13 @@ public function testSortSearchPages() {
       ->method('getEntityType')
       ->will($this->returnValue($entity_type));
 
+    $entity_manager = $this->prophesize(EntityManagerInterface::class);
+    $entity_manager->getDefinition('search_page')->willReturn($entity_type);
+
+    $container = new ContainerBuilder();
+    $container->set('entity.manager', $entity_manager->reveal());
+    \Drupal::setContainer($container);
+
     // Declare entities out of their expected order so we can be sure they were
     // sorted. We cannot mock these because of uasort(), see
     // https://bugs.php.net/bug.php?id=50688.
@@ -274,9 +283,7 @@ public function testSortSearchPages() {
 
 class TestSearchPage extends SearchPage {
   public function __construct(array $values) {
-    foreach ($values as $key => $value) {
-      $this->$key = $value;
-    }
+    parent::__construct($values, 'search_page');
   }
   public function label($langcode = NULL) {
     return $this->label;
diff --git a/core/modules/user/tests/src/Unit/Views/Argument/RolesRidTest.php b/core/modules/user/tests/src/Unit/Views/Argument/RolesRidTest.php
index 66d5e8a..bb249ed 100644
--- a/core/modules/user/tests/src/Unit/Views/Argument/RolesRidTest.php
+++ b/core/modules/user/tests/src/Unit/Views/Argument/RolesRidTest.php
@@ -8,6 +8,7 @@
 namespace Drupal\Tests\user\Unit\Views\Argument;
 
 use Drupal\Core\DependencyInjection\ContainerBuilder;
+use Drupal\Core\Entity\EntityTypeInterface;
 use Drupal\Tests\UnitTestCase;
 use Drupal\user\Entity\Role;
 use Drupal\user\Plugin\views\argument\RolesRid;
@@ -24,6 +25,21 @@ class RolesRidTest extends UnitTestCase {
    * @covers ::titleQuery
    */
   public function testTitleQuery() {
+    $entity_type = $this->prophesize(EntityTypeInterface::class);
+    $entity_type->getKey('id')->willReturn('id');
+    $entity_type->getKey('label')->willReturn('label');
+    $entity_type->getLabelCallback()->willReturn(NULL);
+
+    $entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
+    $entity_manager->expects($this->any())
+      ->method('getDefinition')
+      ->with($this->equalTo('user_role'))
+      ->willReturn($entity_type->reveal());
+
+    $container = new ContainerBuilder();
+    $container->set('entity.manager', $entity_manager);
+    \Drupal::setContainer($container);
+
     $role1 = new Role(array(
       'id' => 'test_rid_1',
       'label' => 'test rid 1'
@@ -43,31 +59,12 @@ public function testTitleQuery() {
         array(array('test_rid_1', 'test_rid_2'), array('test_rid_1' => $role1, 'test_rid_2' => $role2)),
       )));
 
-    $entity_type = $this->getMock('Drupal\Core\Entity\EntityTypeInterface');
-    $entity_type->expects($this->any())
-      ->method('getKey')
-      ->with('label')
-      ->will($this->returnValue('label'));
-
-    $entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
-    $entity_manager->expects($this->any())
-      ->method('getDefinition')
-      ->with($this->equalTo('user_role'))
-      ->will($this->returnValue($entity_type));
-
     $entity_manager
       ->expects($this->once())
       ->method('getStorage')
       ->with($this->equalTo('user_role'))
       ->will($this->returnValue($role_storage));
 
-    // @todo \Drupal\Core\Entity\Entity::entityType() uses a global call to
-    //   entity_get_info(), which in turn wraps \Drupal::entityManager(). Set
-    //   the entity manager until this is fixed.
-    $container = new ContainerBuilder();
-    $container->set('entity.manager', $entity_manager);
-    \Drupal::setContainer($container);
-
     $roles_rid_argument = new RolesRid(array(), 'user__roles_rid', array(), $entity_manager);
 
     $roles_rid_argument->value = array();
diff --git a/core/modules/views/tests/src/Unit/Plugin/field/CounterTest.php b/core/modules/views/tests/src/Unit/Plugin/field/CounterTest.php
index 5280370..139e74a 100644
--- a/core/modules/views/tests/src/Unit/Plugin/field/CounterTest.php
+++ b/core/modules/views/tests/src/Unit/Plugin/field/CounterTest.php
@@ -7,6 +7,9 @@
 
 namespace Drupal\Tests\views\Unit\Plugin\field;
 
+use Drupal\Core\DependencyInjection\ContainerBuilder;
+use Drupal\Core\Entity\EntityManagerInterface;
+use Drupal\Core\Entity\EntityTypeInterface;
 use Drupal\Tests\UnitTestCase;
 use Drupal\views\Entity\View;
 use Drupal\views\Plugin\views\field\Counter;
@@ -61,6 +64,16 @@ class CounterTest extends UnitTestCase {
   protected function setUp() {
     parent::setUp();
 
+    $entity_type = $this->prophesize(EntityTypeInterface::class);
+    $entity_type->getKey('id')->willReturn('id');
+
+    $entity_manager = $this->prophesize(EntityManagerInterface::class);
+    $entity_manager->getDefinition('view')->willReturn($entity_type->reveal());
+
+    $container = new ContainerBuilder();
+    $container->set('entity.manager', $entity_manager->reveal());
+    \Drupal::setContainer($container);
+
     // Setup basic stuff like the view and the display.
     $config = array();
     $config['display']['default'] = array(
diff --git a/core/modules/views/tests/src/Unit/ViewExecutableTest.php b/core/modules/views/tests/src/Unit/ViewExecutableTest.php
index fea412b..10b2323 100644
--- a/core/modules/views/tests/src/Unit/ViewExecutableTest.php
+++ b/core/modules/views/tests/src/Unit/ViewExecutableTest.php
@@ -8,6 +8,8 @@
 namespace Drupal\Tests\views\Unit;
 
 use Drupal\Core\DependencyInjection\ContainerBuilder;
+use Drupal\Core\Entity\EntityManagerInterface;
+use Drupal\Core\Entity\EntityTypeInterface;
 use Drupal\Core\Url;
 use Drupal\Tests\UnitTestCase;
 use Drupal\views\Entity\View;
@@ -103,10 +105,17 @@ protected function setUp() {
       ->disableOriginalConstructor()
       ->getMock();
 
+    $entity_type = $this->prophesize(EntityTypeInterface::class);
+    $entity_type->getKey('id')->willReturn('id');
+
+    $entity_manager = $this->prophesize(EntityManagerInterface::class);
+    $entity_manager->getDefinition('view')->willReturn($entity_type->reveal());
+
     $translation = $this->getStringTranslationStub();
     $container = new ContainerBuilder();
     $container->set('string_translation', $translation);
     $container->set('views.executable', $this->viewExecutableFactory);
+    $container->set('entity.manager', $entity_manager->reveal());
     \Drupal::setContainer($container);
   }
 
diff --git a/core/modules/views/tests/src/Unit/ViewsTest.php b/core/modules/views/tests/src/Unit/ViewsTest.php
index 8bf4770..bcd8683 100644
--- a/core/modules/views/tests/src/Unit/ViewsTest.php
+++ b/core/modules/views/tests/src/Unit/ViewsTest.php
@@ -7,6 +7,8 @@
 
 namespace Drupal\Tests\views\Unit;
 
+use Drupal\Core\Entity\EntityManagerInterface;
+use Drupal\Core\Entity\EntityTypeInterface;
 use Drupal\Core\Entity\Query\QueryFactory;
 use Drupal\Tests\UnitTestCase;
 use Drupal\views\Views;
@@ -30,6 +32,11 @@ class ViewsTest extends UnitTestCase {
   protected $container;
 
   /**
+   * @var \Drupal\Core\Entity\EntityManagerInterface|\Prophecy\Prophecy\ObjectProphecy
+   */
+  protected $entityManager;
+
+  /**
    * {@inheritdoc}
    */
   protected function setUp() {
@@ -45,6 +52,12 @@ protected function setUp() {
     $route_provider = $this->getMock('Drupal\Core\Routing\RouteProviderInterface');
     $this->container->set('views.executable', new ViewExecutableFactory($user, $request_stack, $views_data, $route_provider));
 
+    $entity_type = $this->prophesize(EntityTypeInterface::class);
+    $entity_type->getKey('id')->willReturn('id');
+
+    $this->entityManager = $this->prophesize(EntityManagerInterface::class);
+    $this->entityManager->getDefinition('view')->willReturn($entity_type->reveal());
+    $this->container->set('entity.manager', $this->entityManager->reveal());
     \Drupal::setContainer($this->container);
   }
 
@@ -64,12 +77,7 @@ public function testGetView() {
       ->with('test_view')
       ->will($this->returnValue($view));
 
-    $entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
-    $entity_manager->expects($this->once())
-      ->method('getStorage')
-      ->with('view')
-      ->will($this->returnValue($view_storage));
-    $this->container->set('entity.manager', $entity_manager);
+    $this->entityManager->getStorage('view')->willReturn($view_storage);
 
     $executable = Views::getView('test_view');
     $this->assertInstanceOf('Drupal\views\ViewExecutable', $executable);
@@ -159,12 +167,7 @@ public function testGetApplicableViews($applicable_type, $expected) {
       ->with(['test_view_1', 'test_view_2', 'test_view_3'])
       ->will($this->returnValue(['test_view_1' => $view_1, 'test_view_2' => $view_2, 'test_view_3' => $view_3]));
 
-    $entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
-    $entity_manager->expects($this->exactly(2))
-      ->method('getStorage')
-      ->with('view')
-      ->will($this->returnValue($view_storage));
-    $this->container->set('entity.manager', $entity_manager);
+    $this->entityManager->getStorage('view')->willReturn($view_storage)->shouldBeCalledTimes(2);
 
     $definitions = [
       'type_a' => [
@@ -183,7 +186,7 @@ public function testGetApplicableViews($applicable_type, $expected) {
       ->willReturn($definitions);
     $this->container->set('plugin.manager.views.display', $display_manager);
 
-    $entity_query = new QueryFactory($entity_manager);
+    $entity_query = new QueryFactory($this->entityManager->reveal());
     $this->container->set('entity.query', $entity_query);
 
     $result = Views::getApplicableViews($applicable_type);
diff --git a/core/modules/views_ui/tests/src/Unit/ViewListBuilderTest.php b/core/modules/views_ui/tests/src/Unit/ViewListBuilderTest.php
index 4089d3a..a3ff5f6 100644
--- a/core/modules/views_ui/tests/src/Unit/ViewListBuilderTest.php
+++ b/core/modules/views_ui/tests/src/Unit/ViewListBuilderTest.php
@@ -10,6 +10,7 @@
 use Drupal\Component\Utility\SafeMarkup;
 use Drupal\Core\DependencyInjection\ContainerBuilder;
 use Drupal\Core\Entity\EntityInterface;
+use Drupal\Core\Entity\EntityManagerInterface;
 use Drupal\Tests\UnitTestCase;
 use Drupal\views\Entity\View;
 use Drupal\views\ViewExecutableFactory;
@@ -145,11 +146,20 @@ public function testBuildRowEntityList() {
     $executable_factory = new ViewExecutableFactory($user, $request_stack, $views_data, $route_provider);
     $container->set('views.executable', $executable_factory);
     $container->set('plugin.manager.views.display', $display_manager);
+    $entity_manager = $this->prophesize(EntityManagerInterface::class);
+    $container->set('entity.manager', $entity_manager->reveal());
     \Drupal::setContainer($container);
 
     // Setup a view list builder with a mocked buildOperations method,
     // because t() is called on there.
     $entity_type = $this->getMock('Drupal\Core\Entity\EntityTypeInterface');
+    $entity_type->method('getKey')
+      ->willReturnMap([
+        ['id', 'id'],
+        ['status', 'status'],
+      ]);
+    $entity_manager->getDefinition('view')->willReturn($entity_type);
+
     $view_list_builder = new TestViewListBuilder($entity_type, $storage, $display_manager);
     $view_list_builder->setStringTranslation($this->getStringTranslationStub());
 
diff --git a/core/modules/views_ui/tests/src/Unit/ViewUIObjectTest.php b/core/modules/views_ui/tests/src/Unit/ViewUIObjectTest.php
index c6d7726..d6b7502 100644
--- a/core/modules/views_ui/tests/src/Unit/ViewUIObjectTest.php
+++ b/core/modules/views_ui/tests/src/Unit/ViewUIObjectTest.php
@@ -7,6 +7,8 @@
 
 namespace Drupal\Tests\views_ui\Unit;
 
+use Drupal\Core\Entity\EntityManagerInterface;
+use Drupal\Core\Entity\EntityTypeInterface;
 use Drupal\Core\Language\LanguageInterface;
 use Drupal\Tests\UnitTestCase;
 use Drupal\views\Entity\View;
@@ -118,8 +120,15 @@ public function testIsLocked() {
    * Tests serialization of the ViewUI object.
    */
   public function testSerialization() {
+    $entity_type = $this->prophesize(EntityTypeInterface::class);
+    $entity_type->getKey('id')->willReturn('id');
+
+    $entity_manager = $this->prophesize(EntityManagerInterface::class);
+    $entity_manager->getDefinition('view')->willReturn($entity_type->reveal());
+
     // Set a container so the DependencySerializationTrait has it.
     $container = new ContainerBuilder();
+    $container->set('entity.manager', $entity_manager->reveal());
     \Drupal::setContainer($container);
 
     $storage = new View([], 'view');
diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php
index feca9e9..9c59788 100644
--- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php
+++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php
@@ -7,6 +7,8 @@
 
 namespace Drupal\Tests\Core\Config\Entity;
 
+use Drupal\Core\Config\Entity\ConfigEntityBase;
+use Drupal\Core\Config\Entity\ConfigEntityTypeInterface;
 use Drupal\Core\DependencyInjection\ContainerBuilder;
 use Drupal\Core\Language\Language;
 use Drupal\Tests\Core\Plugin\Fixtures\TestConfigurablePlugin;
@@ -28,7 +30,7 @@ class ConfigEntityBaseUnitTest extends UnitTestCase {
   /**
    * The entity type used for testing.
    *
-   * @var \Drupal\Core\Config\Entity\ConfigEntityTypeInterface|\PHPUnit_Framework_MockObject_MockObject
+   * @var \Drupal\Core\Config\Entity\ConfigEntityTypeInterface|\Prophecy\Prophecy\ObjectProphecy
    */
   protected $entityType;
 
@@ -93,26 +95,18 @@ class ConfigEntityBaseUnitTest extends UnitTestCase {
    */
   protected function setUp() {
     $this->id = $this->randomMachineName();
-    $values = array(
-      'id' => $this->id,
-      'langcode' => 'en',
-      'uuid' => '3bb9ee60-bea5-4622-b89b-a63319d10b3a',
-    );
     $this->entityTypeId = $this->randomMachineName();
     $this->provider = $this->randomMachineName();
-    $this->entityType = $this->getMock('\Drupal\Core\Config\Entity\ConfigEntityTypeInterface');
-    $this->entityType->expects($this->any())
-      ->method('getProvider')
-      ->will($this->returnValue($this->provider));
-    $this->entityType->expects($this->any())
-      ->method('getConfigPrefix')
-      ->willReturn('test_provider.' . $this->entityTypeId);
+    $this->entityType = $this->prophesize(ConfigEntityTypeInterface::class);
+    $this->entityType->getKey('id')->willReturn('id');
+    $this->entityType->getProvider()->willReturn($this->provider);
+    $this->entityType->getConfigPrefix()->willReturn('test_provider.' . $this->entityTypeId);
 
     $this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface');
     $this->entityManager->expects($this->any())
       ->method('getDefinition')
       ->with($this->entityTypeId)
-      ->will($this->returnValue($this->entityType));
+      ->will($this->returnValue($this->entityType->reveal()));
 
     $this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface');
 
@@ -134,7 +128,7 @@ protected function setUp() {
     $container->set('config.typed', $this->typedConfigManager);
     \Drupal::setContainer($container);
 
-    $this->entity = $this->getMockForAbstractClass('\Drupal\Core\Config\Entity\ConfigEntityBase', array($values, $this->entityTypeId));
+    $this->entity = $this->getMockForAbstractClass(ConfigEntityBase::class, [['id' => $this->id], $this->entityTypeId]);
   }
 
   /**
@@ -158,6 +152,8 @@ public function testCalculateDependencies() {
    * @covers ::preSave
    */
   public function testPreSaveDuringSync() {
+    $this->entityType->getBundleOf()->willReturn(NULL);
+
     $query = $this->getMock('\Drupal\Core\Entity\Query\QueryInterface');
     $storage = $this->getMock('\Drupal\Core\Config\Entity\ConfigEntityStorageInterface');
 
@@ -356,6 +352,8 @@ public function testGet() {
    * @covers ::status
    */
   public function testSetStatus() {
+    $this->entityType->getKey('status')->willReturn('status');
+
     $this->assertTrue($this->entity->status());
     $this->assertSame($this->entity, $this->entity->setStatus(FALSE));
     $this->assertFalse($this->entity->status());
@@ -368,6 +366,8 @@ public function testSetStatus() {
    * @depends testSetStatus
    */
   public function testEnable() {
+    $this->entityType->getKey('status')->willReturn('status');
+
     $this->entity->setStatus(FALSE);
     $this->assertSame($this->entity, $this->entity->enable());
     $this->assertTrue($this->entity->status());
@@ -378,6 +378,8 @@ public function testEnable() {
    * @depends testSetStatus
    */
   public function testDisable() {
+    $this->entityType->getKey('status')->willReturn('status');
+
     $this->entity->setStatus(TRUE);
     $this->assertSame($this->entity, $this->entity->disable());
     $this->assertFalse($this->entity->status());
@@ -399,20 +401,8 @@ public function testIsSyncing() {
    * @covers ::createDuplicate
    */
   public function testCreateDuplicate() {
-    $this->entityType->expects($this->at(0))
-      ->method('getKey')
-      ->with('id')
-      ->will($this->returnValue('id'));
-
-    $this->entityType->expects($this->at(1))
-      ->method('hasKey')
-      ->with('uuid')
-      ->will($this->returnValue(TRUE));
-
-    $this->entityType->expects($this->at(2))
-      ->method('getKey')
-      ->with('uuid')
-      ->will($this->returnValue('uuid'));
+    $this->entityType->hasKey('uuid')->willReturn(TRUE);
+    $this->entityType->getKey('uuid')->willReturn('uuid');
 
     $new_uuid = '8607ef21-42bc-4913-978f-8c06207b0395';
     $this->uuid->expects($this->once())
@@ -434,20 +424,21 @@ public function testCreateDuplicate() {
    * @covers ::sort
    */
   public function testSort() {
-    $this->entityManager->expects($this->any())
-      ->method('getDefinition')
-      ->with($this->entityTypeId)
-      ->will($this->returnValue(array(
-        'entity_keys' => array(
-          'label' => 'label',
-        ),
-      )));
+    $this->entityType->hasKey('weight')->willReturn(TRUE);
+    $this->entityType->getKey('weight')->willReturn('weight');
 
     $entity_a = $this->getMock('\Drupal\Core\Config\Entity\ConfigEntityInterface');
+    $entity_a->expects($this->any())
+      ->method('getEntityType')
+      ->willReturn($this->entityType->reveal());
+
     $entity_a->expects($this->atLeastOnce())
       ->method('label')
       ->willReturn('foo');
     $entity_b = $this->getMock('\Drupal\Core\Config\Entity\ConfigEntityInterface');
+    $entity_b->expects($this->any())
+      ->method('getEntityType')
+      ->willReturn($this->entityType->reveal());
     $entity_b->expects($this->atLeastOnce())
       ->method('label')
       ->willReturn('bar');
@@ -483,9 +474,7 @@ public function testSort() {
   public function testToArray() {
     $this->typedConfigManager->expects($this->never())
       ->method('getDefinition');
-    $this->entityType->expects($this->any())
-      ->method('getPropertiesToExport')
-      ->willReturn(['id' => 'configId', 'dependencies' => 'dependencies']);
+    $this->entityType->getPropertiesToExport()->willReturn(['id' => 'configId', 'dependencies' => 'dependencies']);
     $properties = $this->entity->toArray();
     $this->assertInternalType('array', $properties);
     $this->assertEquals(array('configId' => $this->entity->id(), 'dependencies' => array()), $properties);
@@ -505,13 +494,7 @@ public function testToArrayIdKey() {
       ->willReturn([]);
     $this->typedConfigManager->expects($this->never())
       ->method('getDefinition');
-    $this->entityType->expects($this->any())
-      ->method('getPropertiesToExport')
-      ->willReturn(['id' => 'configId', 'dependencies' => 'dependencies']);
-    $this->entityType->expects($this->once())
-      ->method('getKey')
-      ->with('id')
-      ->willReturn('id');
+    $this->entityType->getPropertiesToExport()->willReturn(['id' => 'configId', 'dependencies' => 'dependencies']);
     $properties = $entity->toArray();
     $this->assertInternalType('array', $properties);
     $this->assertEquals(['configId' => $entity->id(), 'dependencies' => []], $properties);
@@ -524,9 +507,7 @@ public function testToArraySchemaFallback() {
     $this->typedConfigManager->expects($this->once())
       ->method('getDefinition')
       ->will($this->returnValue(array('mapping' => array('id' => '', 'dependencies' => ''))));
-    $this->entityType->expects($this->any())
-      ->method('getPropertiesToExport')
-      ->willReturn([]);
+    $this->entityType->getPropertiesToExport()->willReturn([]);
     $properties = $this->entity->toArray();
     $this->assertInternalType('array', $properties);
     $this->assertEquals(array('id' => $this->entity->id(), 'dependencies' => array()), $properties);
@@ -538,9 +519,7 @@ public function testToArraySchemaFallback() {
    * @expectedException \Drupal\Core\Config\Schema\SchemaIncompleteException
    */
   public function testToArrayFallback() {
-    $this->entityType->expects($this->any())
-      ->method('getPropertiesToExport')
-      ->willReturn([]);
+    $this->entityType->getPropertiesToExport()->willReturn([]);
     $this->entity->toArray();
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php
index 508f39b..f3ec7ab 100644
--- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php
+++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php
@@ -8,6 +8,7 @@
 namespace Drupal\Tests\Core\Config\Entity {
 
 use Drupal\Core\Cache\Cache;
+use Drupal\Core\Config\Entity\ConfigEntityBase;
 use Drupal\Core\Config\Entity\ConfigEntityInterface;
 use Drupal\Core\Entity\EntityInterface;
 use Drupal\Core\Language\Language;
@@ -136,7 +137,7 @@ protected function setUp() {
       ->will($this->returnValue('the_config_prefix'));
     $this->entityType->expects($this->any())
       ->method('getClass')
-      ->will($this->returnValue(get_class($this->getMockEntity())));
+      ->willReturn(TestConfigEntityBase::class);
     $this->entityType->expects($this->any())
       ->method('getListCacheTags')
       ->willReturn(array('test_entity_type_list'));
@@ -945,6 +946,9 @@ public function getMockEntity(array $values = array(), $methods = array()) {
 
 }
 
+class TestConfigEntityBase extends ConfigEntityBase {
+}
+
 }
 namespace {
   if (!defined('SAVED_NEW')) {
diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/EntityDisplayModeBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/EntityDisplayModeBaseUnitTest.php
index 1476f6f..1dbfd47 100644
--- a/core/tests/Drupal/Tests/Core/Config/Entity/EntityDisplayModeBaseUnitTest.php
+++ b/core/tests/Drupal/Tests/Core/Config/Entity/EntityDisplayModeBaseUnitTest.php
@@ -8,6 +8,7 @@
 namespace Drupal\Tests\Core\Config\Entity;
 
 use Drupal\Core\DependencyInjection\ContainerBuilder;
+use Drupal\Core\Entity\EntityManagerInterface;
 use Drupal\Tests\UnitTestCase;
 
 /**
@@ -33,7 +34,7 @@ class EntityDisplayModeBaseUnitTest extends UnitTestCase {
   /**
    * The entity manager used for testing.
    *
-   * @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
+   * @var \Drupal\Core\Entity\EntityManagerInterface|\Prophecy\Prophecy\ObjectProphecy
    */
   protected $entityManager;
 
@@ -62,12 +63,12 @@ protected function setUp() {
       ->method('getProvider')
       ->will($this->returnValue('entity'));
 
-    $this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface');
+    $this->entityManager = $this->prophesize(EntityManagerInterface::class);
 
     $this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface');
 
     $container = new ContainerBuilder();
-    $container->set('entity.manager', $this->entityManager);
+    $container->set('entity.manager', $this->entityManager->reveal());
     $container->set('uuid', $this->uuid);
     \Drupal::setContainer($container);
   }
@@ -84,14 +85,8 @@ public function testCalculateDependencies() {
       ->will($this->returnValue('test_module'));
     $values = array('targetEntityType' => $target_entity_type_id);
 
-    $this->entityManager->expects($this->at(0))
-      ->method('getDefinition')
-      ->with($target_entity_type_id)
-      ->will($this->returnValue($target_entity_type));
-    $this->entityManager->expects($this->at(1))
-      ->method('getDefinition')
-      ->with($this->entityType)
-      ->will($this->returnValue($this->entityInfo));
+    $this->entityManager->getDefinition($target_entity_type_id)->willReturn($target_entity_type);
+    $this->entityManager->getDefinition($this->entityType)->willReturn($this->entityInfo);
 
     $this->entity = $this->getMockBuilder('\Drupal\Core\Entity\EntityDisplayModeBase')
       ->setConstructorArgs(array($values, $this->entityType))
@@ -106,6 +101,8 @@ public function testCalculateDependencies() {
    * @covers ::setTargetType
    */
   public function testSetTargetType() {
+    $this->entityManager->getDefinition('test_type')->willReturn($this->entityInfo);
+
     // Generate mock.
     $mock = $this->getMock(
       'Drupal\Core\Entity\EntityDisplayModeBase',
@@ -135,6 +132,8 @@ public function testSetTargetType() {
    * @covers ::getTargetType
    */
   public function testGetTargetType() {
+    $this->entityManager->getDefinition('test_type')->willReturn($this->entityInfo);
+
     // Generate mock.
     $mock = $this->getMock(
       'Drupal\Core\Entity\EntityDisplayModeBase',
diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityFormTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityFormTest.php
index 810bdd1..0e5b5fc 100644
--- a/core/tests/Drupal/Tests/Core/Entity/EntityFormTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/EntityFormTest.php
@@ -7,7 +7,10 @@
 
 namespace Drupal\Tests\Core\Entity;
 
+use Drupal\Core\DependencyInjection\ContainerBuilder;
 use Drupal\Core\Entity\EntityForm;
+use Drupal\Core\Entity\EntityManagerInterface;
+use Drupal\Core\Entity\EntityTypeInterface;
 use Drupal\Core\Form\FormState;
 use Drupal\Tests\UnitTestCase;
 
@@ -99,6 +102,16 @@ public function providerTestFormIds() {
    * @covers ::copyFormValuesToEntity
    */
   public function testCopyFormValuesToEntity() {
+    $entity_type = $this->prophesize(EntityTypeInterface::class);
+    $entity_type->getKey('id')->willReturn('id');
+
+    $entity_manager = $this->prophesize(EntityManagerInterface::class);
+    $entity_manager->getDefinition('test_config_entity')->willReturn($entity_type->reveal());
+
+    $container = new ContainerBuilder();
+    $container->set('entity.manager', $entity_manager->reveal());
+    \Drupal::setContainer($container);
+
     $entity_id = 'test_config_entity_id';
     $values = ['id' => $entity_id];
     $entity = $this->getMockBuilder('\Drupal\Tests\Core\Config\Entity\Fixtures\ConfigEntityBaseWithPluginCollections')
diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityLinkTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityLinkTest.php
index 9e54ebe..0200eb4 100644
--- a/core/tests/Drupal/Tests/Core/Entity/EntityLinkTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/EntityLinkTest.php
@@ -85,6 +85,7 @@ public function testLink($entity_label, $link_text, $expected_text, $link_rel =
     $entity_type->expects($this->any())
       ->method('getKey')
       ->willReturnMap([
+        ['id', 'id'],
         ['label', 'label'],
         ['langcode', 'langcode'],
       ]);
diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php
index 3f1e2e0..e056032 100644
--- a/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php
@@ -11,6 +11,7 @@
 use Drupal\Core\Cache\Cache;
 use Drupal\Core\DependencyInjection\ContainerBuilder;
 use Drupal\Core\Entity\Entity;
+use Drupal\Core\Entity\EntityTypeInterface;
 use Drupal\Core\Language\Language;
 use Drupal\entity_test\Entity\EntityTestMul;
 use Drupal\Tests\UnitTestCase;
@@ -32,7 +33,7 @@ class EntityUnitTest extends UnitTestCase {
   /**
    * The entity type used for testing.
    *
-   * @var \Drupal\Core\Entity\EntityTypeInterface|\PHPUnit_Framework_MockObject_MockObject
+   * @var EntityTypeInterface|\PHPUnit_Framework_MockObject_MockObject
    */
   protected $entityType;
 
@@ -96,16 +97,15 @@ protected function setUp() {
     );
     $this->entityTypeId = $this->randomMachineName();
 
-    $this->entityType = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface');
-    $this->entityType->expects($this->any())
-      ->method('getListCacheTags')
-      ->willReturn(array($this->entityTypeId . '_list'));
+    $this->entityType = $this->prophesize(EntityTypeInterface::class);
+    $this->entityType->getKey('id')->willReturn('id');
+    $this->entityType->getListCacheTags()->willReturn(array($this->entityTypeId . '_list'));
 
     $this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface');
     $this->entityManager->expects($this->any())
       ->method('getDefinition')
       ->with($this->entityTypeId)
-      ->will($this->returnValue($this->entityType));
+      ->willReturn($this->entityType->reveal());
 
     $this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface');
 
@@ -157,7 +157,7 @@ public function testIsNew() {
    * @covers ::getEntityType
    */
   public function testGetEntityType() {
-    $this->assertSame($this->entityType, $this->entity->getEntityType());
+    $this->assertSame($this->entityType->reveal(), $this->entity->getEntityType());
   }
 
   /**
@@ -180,16 +180,6 @@ public function testLabel() {
     $callback_container->expects($this->once())
       ->method(__FUNCTION__)
       ->will($this->returnValue($callback_label));
-    $this->entityType->expects($this->at(0))
-      ->method('getLabelCallback')
-      ->will($this->returnValue(array($callback_container, __FUNCTION__)));
-    $this->entityType->expects($this->at(1))
-      ->method('getLabelCallback')
-      ->will($this->returnValue(NULL));
-    $this->entityType->expects($this->at(2))
-      ->method('getKey')
-      ->with('label')
-      ->will($this->returnValue('label'));
 
     // Set a dummy property on the entity under test to test that the label can
     // be returned form a property if there is no callback.
@@ -201,9 +191,12 @@ public function testLabel() {
           'label' => 'label',
         ),
       )));
+    $this->entityType->getKey('label')->willReturn('label');
     $this->entity->label = $property_label;
 
+    $this->entityType->getLabelCallback()->willReturn([$callback_container, __FUNCTION__]);
     $this->assertSame($callback_label, $this->entity->label());
+    $this->entityType->getLabelCallback()->willReturn(NULL);
     $this->assertSame($property_label, $this->entity->label());
   }
 
@@ -231,11 +224,7 @@ public function testAccess() {
    * @covers ::language
    */
   public function testLanguage() {
-    $this->entityType->expects($this->any())
-      ->method('getKey')
-      ->will($this->returnValueMap(array(
-        array('langcode', 'langcode'),
-      )));
+    $this->entityType->getKey('langcode')->willReturn('langcode');
     $this->assertSame('en', $this->entity->language()->getId());
   }
 
@@ -386,6 +375,7 @@ public function testGetEntityTypeId() {
    * @covers ::preSave
    */
   public function testPreSave() {
+    $this->entityType->getBundleOf()->willReturn(NULL);
     // This method is internal, so check for errors on calling it only.
     $storage = $this->getMock('\Drupal\Core\Entity\EntityStorageInterface');
     // Our mocked entity->preSave() returns NULL, so assert that.
@@ -396,6 +386,7 @@ public function testPreSave() {
    * @covers ::postSave
    */
   public function testPostSave() {
+    $this->entityType->getLinkTemplates()->willReturn([]);
     $this->cacheTagsInvalidator->expects($this->at(0))
       ->method('invalidateTags')
       ->with(array(
@@ -462,7 +453,7 @@ public function testPostDelete() {
     $storage = $this->getMock('\Drupal\Core\Entity\EntityStorageInterface');
     $storage->expects($this->once())
       ->method('getEntityType')
-      ->willReturn($this->entityType);
+      ->willReturn($this->entityType->reveal());
 
     $entities = array($this->values['id'] => $this->entity);
     $this->entity->postDelete($storage, $entities);
diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php
index d19f473..b190043 100644
--- a/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php
@@ -10,6 +10,7 @@
 use Drupal\Core\Config\Entity\ConfigEntityInterface;
 use Drupal\Core\DependencyInjection\ContainerBuilder;
 use Drupal\Core\Entity\EntityInterface;
+use Drupal\Core\Entity\EntityTypeInterface;
 use Drupal\Core\Language\Language;
 use Drupal\Core\Language\LanguageInterface;
 use Drupal\Tests\UnitTestCase;
@@ -33,6 +34,11 @@ class EntityUrlTest extends UnitTestCase {
   protected $urlGenerator;
 
   /**
+   * @var \Drupal\Core\Entity\EntityTypeInterface|\Prophecy\Prophecy\ObjectProphecy
+   */
+  protected $entityType;
+
+  /**
    * {@inheritdoc}
    */
   protected function setUp() {
@@ -40,6 +46,15 @@ protected function setUp() {
 
     $this->entityManager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
     $this->urlGenerator = $this->getMock('Drupal\Core\Routing\UrlGeneratorInterface');
+    $this->entityType = $this->prophesize(EntityTypeInterface::class);
+    $this->entityType->getKey('id')->willReturn('id');
+    $this->entityType->getKey('langcode')->willReturn(NULL);
+    $this->entityManager
+      ->expects($this->any())
+      ->method('getDefinition')
+      ->with('test_entity_type')
+      ->willReturn($this->entityType->reveal());
+
 
     $container = new ContainerBuilder();
     $container->set('entity.manager', $this->entityManager);
@@ -150,23 +165,16 @@ public function providerTestUrlInfoForInvalidLinkTemplate() {
    *   The URL for this entity's link template.
    */
   protected function getTestUrlInfo(EntityInterface $entity, $link_template, array $options = [], $langcode = NULL) {
-    $entity_type = $this->getMock('Drupal\Core\Entity\EntityTypeInterface');
-    $entity_type->expects($this->any())
-      ->method('getLinkTemplates')
-      ->will($this->returnValue(array(
-        'edit-form' => 'test_entity_type.edit',
-      )));
+    $this->entityType->getKey('langcode')->willReturn(NULL);
+    $this->entityType->getLinkTemplates()->willReturn([
+      'edit-form' => 'test_entity_type.edit',
+    ]);
+    $this->entityType->getUriCallback()->willReturn(NULL);
 
     if ($langcode) {
       $entity->langcode = $langcode;
     }
 
-    $this->entityManager
-      ->expects($this->any())
-      ->method('getDefinition')
-      ->with('test_entity_type')
-      ->will($this->returnValue($entity_type));
-
     // If no link template is given, call without a value to test the default.
     if ($link_template) {
       $uri = $entity->urlInfo($link_template, $options);
@@ -203,18 +211,9 @@ public function testUrlInfoForNewEntity() {
    * @covers ::url
    */
   public function testUrl() {
-    $entity_type = $this->getMock('Drupal\Core\Entity\EntityTypeInterface');
-    $entity_type->expects($this->any())
-      ->method('getLinkTemplates')
-      ->will($this->returnValue(array(
-        'canonical' => 'test_entity_type.view',
-      )));
-
-    $this->entityManager
-      ->expects($this->any())
-      ->method('getDefinition')
-      ->with('test_entity_type')
-      ->will($this->returnValue($entity_type));
+    $this->entityType->getLinkTemplates()->willReturn([
+      'canonical' => 'test_entity_type.view',
+    ]);
 
     $invalid_entity = $this->getMockForAbstractClass('Drupal\Core\Entity\Entity', array(array(), 'test_entity_type'));
     $this->assertSame('', $invalid_entity->url());
@@ -251,20 +250,12 @@ public function testUrl() {
    * @dataProvider providerTestLinkTemplates
    */
   public function testLinkTemplates($override_templates, $expected) {
-    $entity_type = $this->getMock('Drupal\Core\Entity\EntityTypeInterface');
-    $entity_type->expects($this->any())
-      ->method('getLinkTemplates')
-      ->will($this->returnValue(array(
-        'canonical' => 'test_entity_type.view',
-      )));
-
-    $this->entityManager
-      ->expects($this->any())
-      ->method('getDefinition')
-      ->with('test_entity_type')
-      ->will($this->returnValue($entity_type));
+    $this->entityType->getLinkTemplates()->willReturn([
+      'canonical' => 'test_entity_type.view',
+    ]);
 
     $entity = $this->getMockForAbstractClass('Drupal\Core\Entity\Entity', array(array('id' => 'test_entity_id'), 'test_entity_type'), '', TRUE, TRUE, TRUE, array('linkTemplates'));
+    $entity_type = $this->entityType->reveal();
     $entity->expects($this->any())
       ->method('linkTemplates')
       ->will($this->returnCallback(function () use ($entity_type, $override_templates) {
