From: Joe Nahmias <jello@debian.org>
Date: Fri, 12 Sep 2025 15:14:35 -0400
Subject: use rector to change withConsecutive() to willReturnCallback()

---
 .../ByteStream/FileByteStreamAcceptanceTest.php    |  52 +--
 .../AbstractStreamBufferAcceptanceTest.php         |  52 +--
 .../unit/Swift/ByteStream/ArrayByteStreamTest.php  |  52 +--
 .../KeyCache/SimpleKeyCacheInputStreamTest.php     |  58 +++-
 tests/unit/Swift/Mime/SimpleHeaderSetTest.php      | 385 ++++++++++++---------
 5 files changed, 371 insertions(+), 228 deletions(-)

diff --git a/tests/acceptance/Swift/ByteStream/FileByteStreamAcceptanceTest.php b/tests/acceptance/Swift/ByteStream/FileByteStreamAcceptanceTest.php
index 9c48432..5480e55 100644
--- a/tests/acceptance/Swift/ByteStream/FileByteStreamAcceptanceTest.php
+++ b/tests/acceptance/Swift/ByteStream/FileByteStreamAcceptanceTest.php
@@ -79,19 +79,27 @@ class Swift_ByteStream_FileByteStreamAcceptanceTest extends \PHPUnit\Framework\T
         $file = $this->createFileStream($this->testFile, true);
         $is1 = $this->createMockInputStream();
         $is2 = $this->createMockInputStream();
-
-        $is1->expects($this->exactly(2))
-            ->method('write')
-            ->withConsecutive(
-                ['x'],
-                ['y']
-            );
-        $is2->expects($this->exactly(2))
-            ->method('write')
-            ->withConsecutive(
-                ['x'],
-                ['y']
-            );
+        $matcher = $this->exactly(2);
+
+        $is1->expects($matcher)
+            ->method('write')->willReturnCallback(function (...$parameters) use ($matcher) {
+            if ($matcher->numberOfInvocations() === 1) {
+                $this->assertSame('x', $parameters[0]);
+            }
+            if ($matcher->numberOfInvocations() === 2) {
+                $this->assertSame('y', $parameters[0]);
+            }
+        });
+        $matcher = $this->exactly(2);
+        $is2->expects($matcher)
+            ->method('write')->willReturnCallback(function (...$parameters) use ($matcher) {
+            if ($matcher->numberOfInvocations() === 1) {
+                $this->assertSame('x', $parameters[0]);
+            }
+            if ($matcher->numberOfInvocations() === 2) {
+                $this->assertSame('y', $parameters[0]);
+            }
+        });
 
         $file->bind($is1);
         $file->bind($is2);
@@ -124,13 +132,17 @@ class Swift_ByteStream_FileByteStreamAcceptanceTest extends \PHPUnit\Framework\T
         $file = $this->createFileStream($this->testFile, true);
         $is1 = $this->createMockInputStream();
         $is2 = $this->createMockInputStream();
-
-        $is1->expects($this->exactly(2))
-            ->method('write')
-            ->withConsecutive(
-                ['x'],
-                ['y']
-            );
+        $matcher = $this->exactly(2);
+
+        $is1->expects($matcher)
+            ->method('write')->willReturnCallback(function (...$parameters) use ($matcher) {
+            if ($matcher->numberOfInvocations() === 1) {
+                $this->assertSame('x', $parameters[0]);
+            }
+            if ($matcher->numberOfInvocations() === 2) {
+                $this->assertSame('y', $parameters[0]);
+            }
+        });
         $is2->expects($this->once())
             ->method('write')
             ->with('x');
diff --git a/tests/acceptance/Swift/Transport/StreamBuffer/AbstractStreamBufferAcceptanceTest.php b/tests/acceptance/Swift/Transport/StreamBuffer/AbstractStreamBufferAcceptanceTest.php
index f8fc840..5feb9d3 100644
--- a/tests/acceptance/Swift/Transport/StreamBuffer/AbstractStreamBufferAcceptanceTest.php
+++ b/tests/acceptance/Swift/Transport/StreamBuffer/AbstractStreamBufferAcceptanceTest.php
@@ -58,19 +58,27 @@ abstract class Swift_Transport_StreamBuffer_AbstractStreamBufferAcceptanceTest e
 
         $is1 = $this->createMockInputStream();
         $is2 = $this->createMockInputStream();
-
-        $is1->expects($this->exactly(2))
-            ->method('write')
-            ->withConsecutive(
-                ['x'],
-                ['y']
-            );
-        $is2->expects($this->exactly(2))
-            ->method('write')
-            ->withConsecutive(
-                ['x'],
-                ['y']
-            );
+        $matcher = $this->exactly(2);
+
+        $is1->expects($matcher)
+            ->method('write')->willReturnCallback(function (...$parameters) use ($matcher) {
+            if ($matcher->numberOfInvocations() === 1) {
+                $this->assertSame('x', $parameters[0]);
+            }
+            if ($matcher->numberOfInvocations() === 2) {
+                $this->assertSame('y', $parameters[0]);
+            }
+        });
+        $matcher = $this->exactly(2);
+        $is2->expects($matcher)
+            ->method('write')->willReturnCallback(function (...$parameters) use ($matcher) {
+            if ($matcher->numberOfInvocations() === 1) {
+                $this->assertSame('x', $parameters[0]);
+            }
+            if ($matcher->numberOfInvocations() === 2) {
+                $this->assertSame('y', $parameters[0]);
+            }
+        });
 
         $this->buffer->bind($is1);
         $this->buffer->bind($is2);
@@ -103,13 +111,17 @@ abstract class Swift_Transport_StreamBuffer_AbstractStreamBufferAcceptanceTest e
 
         $is1 = $this->createMockInputStream();
         $is2 = $this->createMockInputStream();
-
-        $is1->expects($this->exactly(2))
-            ->method('write')
-            ->withConsecutive(
-                ['x'],
-                ['y']
-            );
+        $matcher = $this->exactly(2);
+
+        $is1->expects($matcher)
+            ->method('write')->willReturnCallback(function (...$parameters) use ($matcher) {
+            if ($matcher->numberOfInvocations() === 1) {
+                $this->assertSame('x', $parameters[0]);
+            }
+            if ($matcher->numberOfInvocations() === 2) {
+                $this->assertSame('y', $parameters[0]);
+            }
+        });
         $is2->expects($this->once())
             ->method('write')
             ->with('x');
diff --git a/tests/unit/Swift/ByteStream/ArrayByteStreamTest.php b/tests/unit/Swift/ByteStream/ArrayByteStreamTest.php
index 3cb67e7..0dd8e7f 100644
--- a/tests/unit/Swift/ByteStream/ArrayByteStreamTest.php
+++ b/tests/unit/Swift/ByteStream/ArrayByteStreamTest.php
@@ -131,19 +131,27 @@ class Swift_ByteStream_ArrayByteStreamTest extends \PHPUnit\Framework\TestCase
         $bs = $this->createArrayStream('');
         $is1 = $this->getMockBuilder('Swift_InputByteStream')->getMock();
         $is2 = $this->getMockBuilder('Swift_InputByteStream')->getMock();
-
-        $is1->expects($this->exactly(2))
-            ->method('write')
-            ->withConsecutive(
-                ['x'],
-                ['y']
-            );
-        $is2->expects($this->exactly(2))
-            ->method('write')
-            ->withConsecutive(
-                ['x'],
-                ['y']
-            );
+        $matcher = $this->exactly(2);
+
+        $is1->expects($matcher)
+            ->method('write')->willReturnCallback(function (...$parameters) use ($matcher) {
+            if ($matcher->numberOfInvocations() === 1) {
+                $this->assertSame('x', $parameters[0]);
+            }
+            if ($matcher->numberOfInvocations() === 2) {
+                $this->assertSame('y', $parameters[0]);
+            }
+        });
+        $matcher = $this->exactly(2);
+        $is2->expects($matcher)
+            ->method('write')->willReturnCallback(function (...$parameters) use ($matcher) {
+            if ($matcher->numberOfInvocations() === 1) {
+                $this->assertSame('x', $parameters[0]);
+            }
+            if ($matcher->numberOfInvocations() === 2) {
+                $this->assertSame('y', $parameters[0]);
+            }
+        });
 
         $bs->bind($is1);
         $bs->bind($is2);
@@ -174,13 +182,17 @@ class Swift_ByteStream_ArrayByteStreamTest extends \PHPUnit\Framework\TestCase
         $bs = $this->createArrayStream('');
         $is1 = $this->getMockBuilder('Swift_InputByteStream')->getMock();
         $is2 = $this->getMockBuilder('Swift_InputByteStream')->getMock();
-
-        $is1->expects($this->exactly(2))
-            ->method('write')
-            ->withConsecutive(
-                ['x'],
-                ['y']
-            );
+        $matcher = $this->exactly(2);
+
+        $is1->expects($matcher)
+            ->method('write')->willReturnCallback(function (...$parameters) use ($matcher) {
+            if ($matcher->numberOfInvocations() === 1) {
+                $this->assertSame('x', $parameters[0]);
+            }
+            if ($matcher->numberOfInvocations() === 2) {
+                $this->assertSame('y', $parameters[0]);
+            }
+        });
         $is2->expects($this->once())
             ->method('write')
             ->with('x');
diff --git a/tests/unit/Swift/KeyCache/SimpleKeyCacheInputStreamTest.php b/tests/unit/Swift/KeyCache/SimpleKeyCacheInputStreamTest.php
index 5bf06b9..e36eafc 100644
--- a/tests/unit/Swift/KeyCache/SimpleKeyCacheInputStreamTest.php
+++ b/tests/unit/Swift/KeyCache/SimpleKeyCacheInputStreamTest.php
@@ -7,13 +7,28 @@ class Swift_KeyCache_SimpleKeyCacheInputStreamTest extends \PHPUnit\Framework\Te
     public function testStreamWritesToCacheInAppendMode()
     {
         $cache = $this->getMockBuilder('Swift_KeyCache')->getMock();
-        $cache->expects($this->exactly(3))
-              ->method('setString')
-              ->withConsecutive(
-                  [$this->nsKey, 'foo', 'a', Swift_KeyCache::MODE_APPEND],
-                  [$this->nsKey, 'foo', 'b', Swift_KeyCache::MODE_APPEND],
-                  [$this->nsKey, 'foo', 'c', Swift_KeyCache::MODE_APPEND]
-              );
+        $matcher = $this->exactly(3);
+        $cache->expects($matcher)
+              ->method('setString')->willReturnCallback(function (...$parameters) use ($matcher) {
+            if ($matcher->numberOfInvocations() === 1) {
+                $this->assertSame($this->nsKey, $parameters[0]);
+                $this->assertSame('foo', $parameters[1]);
+                $this->assertSame('a', $parameters[2]);
+                $this->assertSame(Swift_KeyCache::MODE_APPEND, $parameters[3]);
+            }
+            if ($matcher->numberOfInvocations() === 2) {
+                $this->assertSame($this->nsKey, $parameters[0]);
+                $this->assertSame('foo', $parameters[1]);
+                $this->assertSame('b', $parameters[2]);
+                $this->assertSame(Swift_KeyCache::MODE_APPEND, $parameters[3]);
+            }
+            if ($matcher->numberOfInvocations() === 3) {
+                $this->assertSame($this->nsKey, $parameters[0]);
+                $this->assertSame('foo', $parameters[1]);
+                $this->assertSame('c', $parameters[2]);
+                $this->assertSame(Swift_KeyCache::MODE_APPEND, $parameters[3]);
+            }
+        });
 
         $stream = new Swift_KeyCache_SimpleKeyCacheInputStream();
         $stream->setKeyCache($cache);
@@ -43,13 +58,28 @@ class Swift_KeyCache_SimpleKeyCacheInputStreamTest extends \PHPUnit\Framework\Te
     public function testClonedStreamStillReferencesSameCache()
     {
         $cache = $this->getMockBuilder('Swift_KeyCache')->getMock();
-        $cache->expects($this->exactly(3))
-              ->method('setString')
-              ->withConsecutive(
-                  [$this->nsKey, 'foo', 'a', Swift_KeyCache::MODE_APPEND],
-                  [$this->nsKey, 'foo', 'b', Swift_KeyCache::MODE_APPEND],
-                  ['test', 'bar', 'x', Swift_KeyCache::MODE_APPEND]
-              );
+        $matcher = $this->exactly(3);
+        $cache->expects($matcher)
+              ->method('setString')->willReturnCallback(function (...$parameters) use ($matcher) {
+            if ($matcher->numberOfInvocations() === 1) {
+                $this->assertSame($this->nsKey, $parameters[0]);
+                $this->assertSame('foo', $parameters[1]);
+                $this->assertSame('a', $parameters[2]);
+                $this->assertSame(Swift_KeyCache::MODE_APPEND, $parameters[3]);
+            }
+            if ($matcher->numberOfInvocations() === 2) {
+                $this->assertSame($this->nsKey, $parameters[0]);
+                $this->assertSame('foo', $parameters[1]);
+                $this->assertSame('b', $parameters[2]);
+                $this->assertSame(Swift_KeyCache::MODE_APPEND, $parameters[3]);
+            }
+            if ($matcher->numberOfInvocations() === 3) {
+                $this->assertSame('test', $parameters[0]);
+                $this->assertSame('bar', $parameters[1]);
+                $this->assertSame('x', $parameters[2]);
+                $this->assertSame(Swift_KeyCache::MODE_APPEND, $parameters[3]);
+            }
+        });
 
         $stream = new Swift_KeyCache_SimpleKeyCacheInputStream();
         $stream->setKeyCache($cache);
diff --git a/tests/unit/Swift/Mime/SimpleHeaderSetTest.php b/tests/unit/Swift/Mime/SimpleHeaderSetTest.php
index 16ec1cc..c62a06e 100644
--- a/tests/unit/Swift/Mime/SimpleHeaderSetTest.php
+++ b/tests/unit/Swift/Mime/SimpleHeaderSetTest.php
@@ -204,16 +204,20 @@ class Swift_Mime_SimpleHeaderSetTest extends \PHPUnit\Framework\TestCase
     public function testHasCanDistinguishMultipleHeaders()
     {
         $factory = $this->createFactory();
-        $factory->expects($this->exactly(2))
-                ->method('createIdHeader')
-                ->withConsecutive(
-                    ['Message-ID', 'some@id'],
-                    ['Message-ID', 'other@id']
-                )
-                ->willReturnOnConsecutiveCalls(
-                    $this->createHeader('Message-ID'),
-                    $this->createHeader('Message-ID')
-                );
+        $matcher = $this->exactly(2);
+        $factory->expects($matcher)
+                ->method('createIdHeader')->willReturnCallback(function (...$parameters) use ($matcher) {
+            if ($matcher->numberOfInvocations() === 1) {
+                $this->assertSame('Message-ID', $parameters[0]);
+                $this->assertSame('some@id', $parameters[1]);
+                return $this->createHeader('Message-ID');
+            }
+            if ($matcher->numberOfInvocations() === 2) {
+                $this->assertSame('Message-ID', $parameters[0]);
+                $this->assertSame('other@id', $parameters[1]);
+                return $this->createHeader('Message-ID');
+            }
+        });
 
         $set = $this->createSet($factory);
         $set->addIdHeader('Message-ID', 'some@id');
@@ -241,18 +245,25 @@ class Swift_Mime_SimpleHeaderSetTest extends \PHPUnit\Framework\TestCase
         $header1 = $this->createHeader('Message-ID');
         $header2 = $this->createHeader('Message-ID');
         $factory = $this->createFactory();
-        $factory->expects($this->exactly(3))
-                ->method('createIdHeader')
-                ->withConsecutive(
-                    ['Message-ID', 'some@id'],
-                    ['Message-ID', 'other@id'],
-                    ['Message-ID', 'more@id']
-                )
-                ->willReturnOnConsecutiveCalls(
-                    $header0,
-                    $header1,
-                    $header2
-                );
+        $matcher = $this->exactly(3);
+        $factory->expects($matcher)
+                ->method('createIdHeader')->willReturnCallback(function (...$parameters) use ($matcher) {
+            if ($matcher->numberOfInvocations() === 1) {
+                $this->assertSame('Message-ID', $parameters[0]);
+                $this->assertSame('some@id', $parameters[1]);
+                return $header0;
+            }
+            if ($matcher->numberOfInvocations() === 2) {
+                $this->assertSame('Message-ID', $parameters[0]);
+                $this->assertSame('other@id', $parameters[1]);
+                return $header1;
+            }
+            if ($matcher->numberOfInvocations() === 3) {
+                $this->assertSame('Message-ID', $parameters[0]);
+                $this->assertSame('more@id', $parameters[1]);
+                return $header2;
+            }
+        });
 
         $set = $this->createSet($factory);
         $set->addIdHeader('Message-ID', 'some@id');
@@ -273,18 +284,25 @@ class Swift_Mime_SimpleHeaderSetTest extends \PHPUnit\Framework\TestCase
         $header1 = $this->createHeader('Message-ID');
         $header2 = $this->createHeader('Message-ID');
         $factory = $this->createFactory();
-        $factory->expects($this->exactly(3))
-                ->method('createIdHeader')
-                ->withConsecutive(
-                    ['Message-ID', 'some@id'],
-                    ['Message-ID', 'other@id'],
-                    ['Message-ID', 'more@id']
-                )
-                ->willReturnOnConsecutiveCalls(
-                    $header0,
-                    $header1,
-                    $header2
-                );
+        $matcher = $this->exactly(3);
+        $factory->expects($matcher)
+                ->method('createIdHeader')->willReturnCallback(function (...$parameters) use ($matcher) {
+            if ($matcher->numberOfInvocations() === 1) {
+                $this->assertSame('Message-ID', $parameters[0]);
+                $this->assertSame('some@id', $parameters[1]);
+                return $header0;
+            }
+            if ($matcher->numberOfInvocations() === 2) {
+                $this->assertSame('Message-ID', $parameters[0]);
+                $this->assertSame('other@id', $parameters[1]);
+                return $header1;
+            }
+            if ($matcher->numberOfInvocations() === 3) {
+                $this->assertSame('Message-ID', $parameters[0]);
+                $this->assertSame('more@id', $parameters[1]);
+                return $header2;
+            }
+        });
 
         $set = $this->createSet($factory);
         $set->addIdHeader('Message-ID', 'some@id');
@@ -302,18 +320,25 @@ class Swift_Mime_SimpleHeaderSetTest extends \PHPUnit\Framework\TestCase
         $header1 = $this->createHeader('Subject');
         $header2 = $this->createHeader('To');
         $factory = $this->createFactory();
-        $factory->expects($this->exactly(3))
-                ->method('createIdHeader')
-                ->withConsecutive(
-                    ['Message-ID', 'some@id'],
-                    ['Subject', 'thing'],
-                    ['To', 'person@example.org']
-                )
-                ->willReturnOnConsecutiveCalls(
-                    $header0,
-                    $header1,
-                    $header2
-                );
+        $matcher = $this->exactly(3);
+        $factory->expects($matcher)
+                ->method('createIdHeader')->willReturnCallback(function (...$parameters) use ($matcher) {
+            if ($matcher->numberOfInvocations() === 1) {
+                $this->assertSame('Message-ID', $parameters[0]);
+                $this->assertSame('some@id', $parameters[1]);
+                return $header0;
+            }
+            if ($matcher->numberOfInvocations() === 2) {
+                $this->assertSame('Subject', $parameters[0]);
+                $this->assertSame('thing', $parameters[1]);
+                return $header1;
+            }
+            if ($matcher->numberOfInvocations() === 3) {
+                $this->assertSame('To', $parameters[0]);
+                $this->assertSame('person@example.org', $parameters[1]);
+                return $header2;
+            }
+        });
 
         $set = $this->createSet($factory);
         $set->addIdHeader('Message-ID', 'some@id');
@@ -351,16 +376,20 @@ class Swift_Mime_SimpleHeaderSetTest extends \PHPUnit\Framework\TestCase
         $header0 = $this->createHeader('Message-ID');
         $header1 = $this->createHeader('Message-ID');
         $factory = $this->createFactory();
-        $factory->expects($this->exactly(2))
-                ->method('createIdHeader')
-                ->withConsecutive(
-                    ['Message-ID', 'some@id'],
-                    ['Message-ID', 'other@id']
-                )
-                ->willReturnOnConsecutiveCalls(
-                    $header0,
-                    $header1
-                );
+        $matcher = $this->exactly(2);
+        $factory->expects($matcher)
+                ->method('createIdHeader')->willReturnCallback(function (...$parameters) use ($matcher) {
+            if ($matcher->numberOfInvocations() === 1) {
+                $this->assertSame('Message-ID', $parameters[0]);
+                $this->assertSame('some@id', $parameters[1]);
+                return $header0;
+            }
+            if ($matcher->numberOfInvocations() === 2) {
+                $this->assertSame('Message-ID', $parameters[0]);
+                $this->assertSame('other@id', $parameters[1]);
+                return $header1;
+            }
+        });
 
         $set = $this->createSet($factory);
         $set->addIdHeader('Message-ID', 'some@id');
@@ -379,16 +408,20 @@ class Swift_Mime_SimpleHeaderSetTest extends \PHPUnit\Framework\TestCase
         $header0 = $this->createHeader('Message-ID');
         $header1 = $this->createHeader('Message-ID');
         $factory = $this->createFactory();
-        $factory->expects($this->exactly(2))
-                ->method('createIdHeader')
-                ->withConsecutive(
-                    ['Message-ID', 'some@id'],
-                    ['Message-ID', 'other@id']
-                )
-                ->willReturnOnConsecutiveCalls(
-                    $header0,
-                    $header1
-                );
+        $matcher = $this->exactly(2);
+        $factory->expects($matcher)
+                ->method('createIdHeader')->willReturnCallback(function (...$parameters) use ($matcher) {
+            if ($matcher->numberOfInvocations() === 1) {
+                $this->assertSame('Message-ID', $parameters[0]);
+                $this->assertSame('some@id', $parameters[1]);
+                return $header0;
+            }
+            if ($matcher->numberOfInvocations() === 2) {
+                $this->assertSame('Message-ID', $parameters[0]);
+                $this->assertSame('other@id', $parameters[1]);
+                return $header1;
+            }
+        });
 
         $set = $this->createSet($factory);
         $set->addIdHeader('Message-ID', 'some@id');
@@ -417,16 +450,20 @@ class Swift_Mime_SimpleHeaderSetTest extends \PHPUnit\Framework\TestCase
         $header0 = $this->createHeader('Message-ID');
         $header1 = $this->createHeader('Message-ID');
         $factory = $this->createFactory();
-        $factory->expects($this->exactly(2))
-                ->method('createIdHeader')
-                ->withConsecutive(
-                    ['Message-ID', 'some@id'],
-                    ['Message-ID', 'other@id']
-                )
-                ->willReturnOnConsecutiveCalls(
-                    $header0,
-                    $header1
-                );
+        $matcher = $this->exactly(2);
+        $factory->expects($matcher)
+                ->method('createIdHeader')->willReturnCallback(function (...$parameters) use ($matcher) {
+            if ($matcher->numberOfInvocations() === 1) {
+                $this->assertSame('Message-ID', $parameters[0]);
+                $this->assertSame('some@id', $parameters[1]);
+                return $header0;
+            }
+            if ($matcher->numberOfInvocations() === 2) {
+                $this->assertSame('Message-ID', $parameters[0]);
+                $this->assertSame('other@id', $parameters[1]);
+                return $header1;
+            }
+        });
 
         $set = $this->createSet($factory);
         $set->addIdHeader('Message-ID', 'some@id');
@@ -511,16 +548,20 @@ class Swift_Mime_SimpleHeaderSetTest extends \PHPUnit\Framework\TestCase
     public function testToStringJoinsHeadersTogether()
     {
         $factory = $this->createFactory();
-        $factory->expects($this->exactly(2))
-                ->method('createTextHeader')
-                ->withConsecutive(
-                    ['Foo', 'bar'],
-                    ['Zip', 'buttons']
-                )
-                ->willReturnOnConsecutiveCalls(
-                    $this->createHeader('Foo', 'bar'),
-                    $this->createHeader('Zip', 'buttons')
-                );
+        $matcher = $this->exactly(2);
+        $factory->expects($matcher)
+                ->method('createTextHeader')->willReturnCallback(function (...$parameters) use ($matcher) {
+            if ($matcher->numberOfInvocations() === 1) {
+                $this->assertSame('Foo', $parameters[0]);
+                $this->assertSame('bar', $parameters[1]);
+                return $this->createHeader('Foo', 'bar');
+            }
+            if ($matcher->numberOfInvocations() === 2) {
+                $this->assertSame('Zip', $parameters[0]);
+                $this->assertSame('buttons', $parameters[1]);
+                return $this->createHeader('Zip', 'buttons');
+            }
+        });
 
         $set = $this->createSet($factory);
         $set->addTextHeader('Foo', 'bar');
@@ -535,16 +576,20 @@ class Swift_Mime_SimpleHeaderSetTest extends \PHPUnit\Framework\TestCase
     public function testHeadersWithoutBodiesAreNotDisplayed()
     {
         $factory = $this->createFactory();
-        $factory->expects($this->exactly(2))
-                ->method('createTextHeader')
-                ->withConsecutive(
-                    ['Foo', 'bar'],
-                    ['Zip', '']
-                )
-                ->willReturnOnConsecutiveCalls(
-                    $this->createHeader('Foo', 'bar'),
-                    $this->createHeader('Zip', '')
-                );
+        $matcher = $this->exactly(2);
+        $factory->expects($matcher)
+                ->method('createTextHeader')->willReturnCallback(function (...$parameters) use ($matcher) {
+            if ($matcher->numberOfInvocations() === 1) {
+                $this->assertSame('Foo', $parameters[0]);
+                $this->assertSame('bar', $parameters[1]);
+                return $this->createHeader('Foo', 'bar');
+            }
+            if ($matcher->numberOfInvocations() === 2) {
+                $this->assertSame('Zip', $parameters[0]);
+                $this->assertSame('', $parameters[1]);
+                return $this->createHeader('Zip', '');
+            }
+        });
 
         $set = $this->createSet($factory);
         $set->addTextHeader('Foo', 'bar');
@@ -558,16 +603,20 @@ class Swift_Mime_SimpleHeaderSetTest extends \PHPUnit\Framework\TestCase
     public function testHeadersWithoutBodiesCanBeForcedToDisplay()
     {
         $factory = $this->createFactory();
-        $factory->expects($this->exactly(2))
-                ->method('createTextHeader')
-                ->withConsecutive(
-                    ['Foo', ''],
-                    ['Zip', '']
-                )
-                ->willReturnOnConsecutiveCalls(
-                    $this->createHeader('Foo', ''),
-                    $this->createHeader('Zip', '')
-                );
+        $matcher = $this->exactly(2);
+        $factory->expects($matcher)
+                ->method('createTextHeader')->willReturnCallback(function (...$parameters) use ($matcher) {
+            if ($matcher->numberOfInvocations() === 1) {
+                $this->assertSame('Foo', $parameters[0]);
+                $this->assertSame('', $parameters[1]);
+                return $this->createHeader('Foo', '');
+            }
+            if ($matcher->numberOfInvocations() === 2) {
+                $this->assertSame('Zip', $parameters[0]);
+                $this->assertSame('', $parameters[1]);
+                return $this->createHeader('Zip', '');
+            }
+        });
 
         $set = $this->createSet($factory);
         $set->addTextHeader('Foo', '');
@@ -583,18 +632,25 @@ class Swift_Mime_SimpleHeaderSetTest extends \PHPUnit\Framework\TestCase
     public function testHeaderSequencesCanBeSpecified()
     {
         $factory = $this->createFactory();
-        $factory->expects($this->exactly(3))
-                ->method('createTextHeader')
-                ->withConsecutive(
-                    ['Third', 'three'],
-                    ['First', 'one'],
-                    ['Second', 'two']
-                )
-                ->willReturnOnConsecutiveCalls(
-                    $this->createHeader('Third', 'three'),
-                    $this->createHeader('First', 'one'),
-                    $this->createHeader('Second', 'two')
-                );
+        $matcher = $this->exactly(3);
+        $factory->expects($matcher)
+                ->method('createTextHeader')->willReturnCallback(function (...$parameters) use ($matcher) {
+            if ($matcher->numberOfInvocations() === 1) {
+                $this->assertSame('Third', $parameters[0]);
+                $this->assertSame('three', $parameters[1]);
+                return $this->createHeader('Third', 'three');
+            }
+            if ($matcher->numberOfInvocations() === 2) {
+                $this->assertSame('First', $parameters[0]);
+                $this->assertSame('one', $parameters[1]);
+                return $this->createHeader('First', 'one');
+            }
+            if ($matcher->numberOfInvocations() === 3) {
+                $this->assertSame('Second', $parameters[0]);
+                $this->assertSame('two', $parameters[1]);
+                return $this->createHeader('Second', 'two');
+            }
+        });
 
         $set = $this->createSet($factory);
         $set->addTextHeader('Third', 'three');
@@ -614,22 +670,35 @@ class Swift_Mime_SimpleHeaderSetTest extends \PHPUnit\Framework\TestCase
     public function testUnsortedHeadersAppearAtEnd()
     {
         $factory = $this->createFactory();
-        $factory->expects($this->exactly(5))
-                ->method('createTextHeader')
-                ->withConsecutive(
-                    ['Fourth', 'four'],
-                    ['Fifth', 'five'],
-                    ['Third', 'three'],
-                    ['First', 'one'],
-                    ['Second', 'two']
-                )
-                ->willReturnOnConsecutiveCalls(
-                    $this->createHeader('Fourth', 'four'),
-                    $this->createHeader('Fifth', 'five'),
-                    $this->createHeader('Third', 'three'),
-                    $this->createHeader('First', 'one'),
-                    $this->createHeader('Second', 'two')
-                );
+        $matcher = $this->exactly(5);
+        $factory->expects($matcher)
+                ->method('createTextHeader')->willReturnCallback(function (...$parameters) use ($matcher) {
+            if ($matcher->numberOfInvocations() === 1) {
+                $this->assertSame('Fourth', $parameters[0]);
+                $this->assertSame('four', $parameters[1]);
+                return $this->createHeader('Fourth', 'four');
+            }
+            if ($matcher->numberOfInvocations() === 2) {
+                $this->assertSame('Fifth', $parameters[0]);
+                $this->assertSame('five', $parameters[1]);
+                return $this->createHeader('Fifth', 'five');
+            }
+            if ($matcher->numberOfInvocations() === 3) {
+                $this->assertSame('Third', $parameters[0]);
+                $this->assertSame('three', $parameters[1]);
+                return $this->createHeader('Third', 'three');
+            }
+            if ($matcher->numberOfInvocations() === 4) {
+                $this->assertSame('First', $parameters[0]);
+                $this->assertSame('one', $parameters[1]);
+                return $this->createHeader('First', 'one');
+            }
+            if ($matcher->numberOfInvocations() === 5) {
+                $this->assertSame('Second', $parameters[0]);
+                $this->assertSame('two', $parameters[1]);
+                return $this->createHeader('Second', 'two');
+            }
+        });
 
         $set = $this->createSet($factory);
         $set->addTextHeader('Fourth', 'four');
@@ -655,16 +724,20 @@ class Swift_Mime_SimpleHeaderSetTest extends \PHPUnit\Framework\TestCase
         $subject = $this->createHeader('Subject', 'some text');
         $xHeader = $this->createHeader('X-Header', 'some text');
         $factory = $this->createFactory();
-        $factory->expects($this->exactly(2))
-                ->method('createTextHeader')
-                ->withConsecutive(
-                    ['Subject', 'some text'],
-                    ['X-Header', 'some text']
-                )
-                ->willReturnOnConsecutiveCalls(
-                    $subject,
-                    $xHeader
-                );
+        $matcher = $this->exactly(2);
+        $factory->expects($matcher)
+                ->method('createTextHeader')->willReturnCallback(function (...$parameters) use ($matcher) {
+            if ($matcher->numberOfInvocations() === 1) {
+                $this->assertSame('Subject', $parameters[0]);
+                $this->assertSame('some text', $parameters[1]);
+                return $subject;
+            }
+            if ($matcher->numberOfInvocations() === 2) {
+                $this->assertSame('X-Header', $parameters[0]);
+                $this->assertSame('some text', $parameters[1]);
+                return $xHeader;
+            }
+        });
         $subject->expects($this->once())
                 ->method('setCharset')
                 ->with('utf-8');
@@ -684,16 +757,20 @@ class Swift_Mime_SimpleHeaderSetTest extends \PHPUnit\Framework\TestCase
         $subject = $this->createHeader('Subject', 'some text');
         $xHeader = $this->createHeader('X-Header', 'some text');
         $factory = $this->createFactory();
-        $factory->expects($this->exactly(2))
-                ->method('createTextHeader')
-                ->withConsecutive(
-                    ['Subject', 'some text'],
-                    ['X-Header', 'some text']
-                )
-                ->willReturnOnConsecutiveCalls(
-                    $subject,
-                    $xHeader
-                );
+        $matcher = $this->exactly(2);
+        $factory->expects($matcher)
+                ->method('createTextHeader')->willReturnCallback(function (...$parameters) use ($matcher) {
+            if ($matcher->numberOfInvocations() === 1) {
+                $this->assertSame('Subject', $parameters[0]);
+                $this->assertSame('some text', $parameters[1]);
+                return $subject;
+            }
+            if ($matcher->numberOfInvocations() === 2) {
+                $this->assertSame('X-Header', $parameters[0]);
+                $this->assertSame('some text', $parameters[1]);
+                return $xHeader;
+            }
+        });
         $subject->expects($this->once())
                 ->method('setCharset')
                 ->with('utf-8');
