From f47a90e987dc15f2eedaef49d2d64ee5c874d29e Mon Sep 17 00:00:00 2001
From: Aad Mathijssen <aad.mathijssen@iodigital.com>
Date: Mon, 15 Jul 2024 14:53:58 +0200
Subject: [PATCH 1/2] Avoid mandatory `void` return type of the inherited
 `setUp` method in PHPUnit 10

This is done by renaming the inherited `setUp` method to a new `setUpTestCase` method and adding an `@before` annotation.
---
 tests/Constraint/ConstraintTest.php          | 6 +++++-
 tests/Constraint/MatchAllConstraintTest.php  | 6 +++++-
 tests/Constraint/MatchNoneConstraintTest.php | 6 +++++-
 tests/Constraint/MultiConstraintTest.php     | 6 +++++-
 4 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/tests/Constraint/ConstraintTest.php b/tests/Constraint/ConstraintTest.php
index 9a058969a..b289ea24a 100644
--- a/tests/Constraint/ConstraintTest.php
+++ b/tests/Constraint/ConstraintTest.php
@@ -25,7 +25,11 @@ class ConstraintTest extends TestCase
      */
     protected $versionProvide;
 
-    protected function setUp()
+    /**
+     * @before
+     * @return void
+     */
+    public function setUpTestCase()
     {
         $this->constraint = new Constraint('==', '1');
         $this->versionProvide = new Constraint('==', 'dev-foo');
diff --git a/tests/Constraint/MatchAllConstraintTest.php b/tests/Constraint/MatchAllConstraintTest.php
index 21e5978e3..ad4152e46 100644
--- a/tests/Constraint/MatchAllConstraintTest.php
+++ b/tests/Constraint/MatchAllConstraintTest.php
@@ -24,7 +24,11 @@ class MatchAllConstraintTest extends TestCase
      */
     protected $matchAllConstraint;
 
-    protected function setUp()
+    /**
+     * @before
+     * @return void
+     */
+    public function setUpTestCase()
     {
         $this->versionProvide = new Constraint('==', '1.1');
         $this->matchAllConstraint = new MatchAllConstraint();
diff --git a/tests/Constraint/MatchNoneConstraintTest.php b/tests/Constraint/MatchNoneConstraintTest.php
index 8e7d73cb3..801d2af5c 100644
--- a/tests/Constraint/MatchNoneConstraintTest.php
+++ b/tests/Constraint/MatchNoneConstraintTest.php
@@ -20,7 +20,11 @@ class MatchNoneConstraintTest extends TestCase
      */
     protected $matchNoneConstraint;
 
-    protected function setUp()
+    /**
+     * @before
+     * @return void
+     */
+    public function setUpTestCase()
     {
         $this->matchNoneConstraint = new MatchNoneConstraint();
     }
diff --git a/tests/Constraint/MultiConstraintTest.php b/tests/Constraint/MultiConstraintTest.php
index 9093e73ae..f8e86842b 100644
--- a/tests/Constraint/MultiConstraintTest.php
+++ b/tests/Constraint/MultiConstraintTest.php
@@ -26,7 +26,11 @@ class MultiConstraintTest extends TestCase
      */
     protected $versionRequireEnd;
 
-    protected function setUp()
+    /**
+     * @before
+     * @return void
+     */
+    public function setUpTestCase()
     {
         $this->versionRequireStart = new Constraint('>', '1.0');
         $this->versionRequireEnd = new Constraint('<', '1.2');

From 3ad9b776142fab4a8e97ec6a6629300311f9099d Mon Sep 17 00:00:00 2001
From: Aad Mathijssen <aad.mathijssen@iodigital.com>
Date: Mon, 15 Jul 2024 14:52:13 +0200
Subject: [PATCH 2/2] Use `onlyMethods` instead of `setMethods` on MockBuilder
 instance when available

This resolves the following error when running the test suite using PHPUnit 10:

    Call to undefined method PHPUnit\Framework\MockObject\MockBuilder::setMethods()
---
 tests/Constraint/ConstraintTest.php | 36 +++++++++++++----------------
 1 file changed, 16 insertions(+), 20 deletions(-)

diff --git a/tests/Constraint/ConstraintTest.php b/tests/Constraint/ConstraintTest.php
index b289ea24a..5dc59109f 100644
--- a/tests/Constraint/ConstraintTest.php
+++ b/tests/Constraint/ConstraintTest.php
@@ -377,33 +377,29 @@ public function testVersionMatchFails($requireOperator, $requireVersion, $provid
     public function testInverseMatchingOtherConstraints()
     {
         $constraint = new Constraint('>', '1.0.0');
+        $otherConstraintClasses = array(
+            'Composer\Semver\Constraint\MultiConstraint',
+            'Composer\Semver\Constraint\MatchAllConstraint'
+        );
 
-        $multiConstraint = $this
-            ->getMockBuilder('Composer\Semver\Constraint\MultiConstraint')
-            ->disableOriginalConstructor()
-            ->setMethods(array('matches'))
-            ->getMock()
-        ;
-
-        $matchAllConstraint = $this
-            ->getMockBuilder('Composer\Semver\Constraint\MatchAllConstraint')
-            ->setMethods(array('matches'))
-            ->getMock()
-        ;
-
-        foreach (array($multiConstraint, $matchAllConstraint) as $mock) {
-            $mock
+        foreach ($otherConstraintClasses as $otherConstraintClass) {
+            $otherConstraintMockBuilder =  $this->getMockBuilder($otherConstraintClass);
+            $otherConstraintMockBuilder->disableOriginalConstructor();
+            if (method_exists($otherConstraintMockBuilder, 'onlyMethods')) {
+                $otherConstraintMockBuilder->onlyMethods(array('matches'));
+            } elseif (method_exists($otherConstraintMockBuilder, 'setMethods')) {
+                $otherConstraintMockBuilder->setMethods(array('matches'));
+            }
+            $otherConstraintMock = $otherConstraintMockBuilder->getMock();
+            $otherConstraintMock
                 ->expects($this->once())
                 ->method('matches')
                 ->with($constraint)
                 ->willReturn(true)
             ;
+            // @phpstan-ignore-next-line
+            $this->assertTrue($constraint->matches($otherConstraintMock));
         }
-
-        // @phpstan-ignore-next-line
-        $this->assertTrue($constraint->matches($multiConstraint));
-        // @phpstan-ignore-next-line
-        $this->assertTrue($constraint->matches($matchAllConstraint));
     }
 
     public function testComparableBranches()