seec/phpunit-consecutive-params

Drop-in Trait to use removed ConsecutiveParams from PhpUnit

Maintainers

👁 bytes-commerce

Package info

github.com/bytes-max/phpunit-consecutive-params

Homepage

Issues

pkg:composer/seec/phpunit-consecutive-params

Statistics

Installs: 772 370

Dependents: 8

Suggesters: 0

Stars: 18

1.2 2025-04-20 11:15 UTC

Requires

  • php: ^8.0

Suggests

None

Provides

None

Conflicts

None

Replaces

None

GPL-3.0-or-later 0459921733421396f10a4956d5b860cbf1756eb9

phpunitTDDunit testingvariadicconsecutive params


README

👁 Latest Stable Version
👁 Total Downloads
👁 Latest Unstable Version
👁 License
👁 PHP Version Require

PHPUnit Consecutive Parameters

After PHPUnit has removed the possibility to use withConsecutive, which was used by thousand of UnitTests, developers need a replacement which is not offered in a neat way at the moment.

Until this problem is solved directly in PHPUnit, this library offers a simple solution to use a replacement of withConsecutive again. The original solution posted here.

Installation

$ composer require --dev seec/phpunit-consecutive-params

Usage

<?php

declare(strict_types=1);

namespace Your\Namespace\For\Tests;

use SEEC\PhpUnit\Helper\ConsecutiveParams;

final class TestRunnerContextTest extends TestCase
{
 use ConsecutiveParams;
 ...

 public function test_it_can_use_consecutive_replacement(): void
 {
 $mock = $this->createMock(\stdClass::class);
 $mock->expects($this->exactly(3))
 ->method('foo')
 ->with(...$this->withConsecutive(
 ['a', 'b'],
 ['c', 'd'],
 ['e', 'f']
 ));
 }

Another example for automatic replacement in correctly formatted code:

->withConsecutive(
 ['a', 'b'],
 ['c', 'd'],
 ['e', 'f']
)

becomes

->with(...$this->withConsecutive(
 ['a', 'b'],
 ['c', 'd'],
 ['e', 'f']
))