Skip to content

Add support for partially ordered parameter set matching #6548

@laloona

Description

@laloona

Summary

PHPUnit currently provides:

  • withParameterSetsInOrder() (strict ordering)
  • withParameterSetsInAnyOrder() (no ordering constraints)

There is no way to express partial ordering, where some calls must occur at specific positions while others may occur in any order.

Proposal

Introduce: withParameterSetsInPartialOrder() - partially ordered arguments

$mock->expects($this->exactly(4))
    ->method('dispatch')
    ->withParameterSetsInPartialOrder(
        $this->fixed($a),
        [$b],
        [$c],
        $this->fixed($d),
    );
  • fixed(...) parameter sets must match exactly at their declared position
  • other parameter sets may match remaining positions in any order
  • all parameter sets must be matched exactly once

This allows expressing common patterns such as:

  • setup → arbitrary operations → cleanup
  • fixed first/last calls with flexible middle

I am open to alternative API designs if there is a better way to express this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions