diff --git a/core/modules/forum/tests/src/Unit/Breadcrumb/ForumListingBreadcrumbBuilderTest.php b/core/modules/forum/tests/src/Unit/Breadcrumb/ForumListingBreadcrumbBuilderTest.php
index 6e4b4d89d61936a865606fbaf79ed7424725da1a..29cc3e3eb58704ff89e93cc45e992f9e1aa70aaf 100644
--- a/core/modules/forum/tests/src/Unit/Breadcrumb/ForumListingBreadcrumbBuilderTest.php
+++ b/core/modules/forum/tests/src/Unit/Breadcrumb/ForumListingBreadcrumbBuilderTest.php
@@ -8,6 +8,7 @@
 use Drupal\Core\Entity\EntityTypeManagerInterface;
 use Drupal\Core\Link;
 use Drupal\forum\Breadcrumb\ForumListingBreadcrumbBuilder;
+use Drupal\taxonomy\Entity\Term;
 use Drupal\taxonomy\TermStorageInterface;
 use Drupal\Tests\UnitTestCase;
 use Symfony\Component\DependencyInjection\Container;
@@ -47,12 +48,21 @@ protected function setUp(): void {
    * @dataProvider providerTestApplies
    * @covers ::applies
    */
-  public function testApplies($expected, $route_name = NULL, $parameter_map = []) {
+  public function testApplies(bool $expected, ?string $route_name = NULL, array $parameter_map = []): void {
     // Make some test doubles.
     $entity_type_manager = $this->createMock(EntityTypeManagerInterface::class);
     $config_factory = $this->getConfigFactoryStub([]);
     $forum_manager = $this->createMock('Drupal\forum\ForumManagerInterface');
     $translation_manager = $this->createMock('Drupal\Core\StringTranslation\TranslationInterface');
+    $map = [];
+    if ($parameter_map) {
+      foreach ($parameter_map as $parameter) {
+        $map[] = [
+          $parameter[0],
+          $parameter[1] === TRUE ? $this->getMockBuilder(Term::class)->disableOriginalConstructor()->getMock() : $parameter[1],
+        ];
+      }
+    }
 
     // Make an object to test.
     $builder = new ForumListingBreadcrumbBuilder($entity_type_manager, $config_factory, $forum_manager, $translation_manager);
@@ -63,7 +73,7 @@ public function testApplies($expected, $route_name = NULL, $parameter_map = [])
       ->willReturn($route_name);
     $route_match->expects($this->any())
       ->method('getParameter')
-      ->willReturnMap($parameter_map);
+      ->willReturnMap($map);
 
     $this->assertEquals($expected, $builder->applies($route_match));
   }
@@ -71,40 +81,17 @@ public function testApplies($expected, $route_name = NULL, $parameter_map = [])
   /**
    * Provides test data for testApplies().
    *
-   * @return array
-   *   Array of datasets for testApplies(). Structured as such:
+   * @return \Generator
+   *   Datasets for testApplies(). Structured as such:
    *   - ForumListBreadcrumbBuilder::applies() expected result.
    *   - ForumListBreadcrumbBuilder::applies() $attributes input array.
    */
-  public function providerTestApplies() {
-    // Send a Node mock, because NodeInterface cannot be mocked.
-    $mock_term = $this->getMockBuilder('Drupal\taxonomy\Entity\Term')
-      ->disableOriginalConstructor()
-      ->getMock();
-
-    return [
-      [
-        FALSE,
-      ],
-      [
-        FALSE,
-        'NOT.forum.page',
-      ],
-      [
-        FALSE,
-        'forum.page',
-      ],
-      [
-        TRUE,
-        'forum.page',
-        [['taxonomy_term', 'anything']],
-      ],
-      [
-        TRUE,
-        'forum.page',
-        [['taxonomy_term', $mock_term]],
-      ],
-    ];
+  public static function providerTestApplies(): \Generator {
+    yield [FALSE];
+    yield [FALSE, 'NOT.forum.page'];
+    yield [FALSE, 'forum.page'];
+    yield [TRUE, 'forum.page', [['taxonomy_term', 'anything']]];
+    yield [TRUE, 'forum.page', [['taxonomy_term', TRUE]]];
   }
 
   /**
diff --git a/core/modules/forum/tests/src/Unit/Breadcrumb/ForumNodeBreadcrumbBuilderTest.php b/core/modules/forum/tests/src/Unit/Breadcrumb/ForumNodeBreadcrumbBuilderTest.php
index 5912342fcbac922e91c7568f0ef5c64f2a7bdc54..47b223916a96842ec218d2dcfa02070dc2fe8db8 100644
--- a/core/modules/forum/tests/src/Unit/Breadcrumb/ForumNodeBreadcrumbBuilderTest.php
+++ b/core/modules/forum/tests/src/Unit/Breadcrumb/ForumNodeBreadcrumbBuilderTest.php
@@ -8,6 +8,7 @@
 use Drupal\Core\Entity\EntityTypeManagerInterface;
 use Drupal\Core\Link;
 use Drupal\forum\Breadcrumb\ForumNodeBreadcrumbBuilder;
+use Drupal\node\Entity\Node;
 use Drupal\taxonomy\TermStorageInterface;
 use Drupal\Tests\UnitTestCase;
 use Symfony\Component\DependencyInjection\Container;
@@ -47,10 +48,19 @@ protected function setUp(): void {
    * @dataProvider providerTestApplies
    * @covers ::applies
    */
-  public function testApplies($expected, $route_name = NULL, $parameter_map = []) {
+  public function testApplies(bool $expected, ?string $route_name = NULL, array $parameter_map = []): void {
     // Make some test doubles.
     $entity_type_manager = $this->createMock(EntityTypeManagerInterface::class);
     $config_factory = $this->getConfigFactoryStub([]);
+    $map = [];
+    if ($parameter_map) {
+      foreach ($parameter_map as $parameter) {
+        $map[] = [
+          $parameter[0],
+          $parameter[1] === TRUE ? $this->getMockBuilder(Node::class)->disableOriginalConstructor()->getMock() : $parameter[1],
+        ];
+      }
+    }
 
     $forum_manager = $this->createMock('Drupal\forum\ForumManagerInterface');
     $forum_manager->expects($this->any())
@@ -68,7 +78,7 @@ public function testApplies($expected, $route_name = NULL, $parameter_map = [])
       ->willReturn($route_name);
     $route_match->expects($this->any())
       ->method('getParameter')
-      ->willReturnMap($parameter_map);
+      ->willReturnMap($map);
 
     $this->assertEquals($expected, $builder->applies($route_match));
   }
@@ -78,40 +88,17 @@ public function testApplies($expected, $route_name = NULL, $parameter_map = [])
    *
    * Note that this test is incomplete, because we can't mock NodeInterface.
    *
-   * @return array
-   *   Array of datasets for testApplies(). Structured as such:
+   * @return \Generator
+   *   Datasets for testApplies(). Structured as such:
    *   - ForumNodeBreadcrumbBuilder::applies() expected result.
    *   - ForumNodeBreadcrumbBuilder::applies() $attributes input array.
    */
-  public function providerTestApplies() {
-    // Send a Node mock, because NodeInterface cannot be mocked.
-    $mock_node = $this->getMockBuilder('Drupal\node\Entity\Node')
-      ->disableOriginalConstructor()
-      ->getMock();
-
-    return [
-      [
-        FALSE,
-      ],
-      [
-        FALSE,
-        'NOT.entity.node.canonical',
-      ],
-      [
-        FALSE,
-        'entity.node.canonical',
-      ],
-      [
-        FALSE,
-        'entity.node.canonical',
-        [['node', NULL]],
-      ],
-      [
-        TRUE,
-        'entity.node.canonical',
-        [['node', $mock_node]],
-      ],
-    ];
+  public static function providerTestApplies(): \Generator {
+    yield [FALSE];
+    yield [FALSE, 'NOT.entity.node.canonical'];
+    yield [FALSE, 'entity.node.canonical'];
+    yield [FALSE, 'entity.node.canonical', [['node', NULL]]];
+    yield [TRUE, 'entity.node.canonical', [['node', TRUE]]];
   }
 
   /**