diff --git a/core/tests/Drupal/Tests/Component/Plugin/Context/ContextTest.php b/core/tests/Drupal/Tests/Component/Plugin/Context/ContextTest.php
index 192331c993724dd132483dd11abf6f0fd9cdfde3..f9656cfc5e00c383c30f1bedb9fd6c0ed649e2c8 100644
--- a/core/tests/Drupal/Tests/Component/Plugin/Context/ContextTest.php
+++ b/core/tests/Drupal/Tests/Component/Plugin/Context/ContextTest.php
@@ -103,7 +103,7 @@ public function providerHasContextValue() {
    */
   public function testHasContextValue($has_context_value, $default_value): void {
     $mock_definition = $this->getMockBuilder('Drupal\Component\Plugin\Context\ContextDefinitionInterface')
-      ->setMethods(['getDefaultValue'])
+      ->onlyMethods(['getDefaultValue'])
       ->getMockForAbstractClass();
 
     $mock_definition->expects($this->atLeastOnce())