npo/phpunit-extension

Library containing PHPUnit helper classes

1.1 2024-02-13 14:24 UTC

This package is not auto-updated.

Last update: 2024-04-26 09:41:57 UTC


README

A ;ibrary containing phpunit helper classes

Doc

Constraints

Consecutive

The Consecutive constraint class be used to replace the InvocationMocker::withConsecutive, which was deprecated as of phpunit version 10. Prior to version 10, consecutive calls could be tested according the following example.


        $mockObject
            ->expects($this->exactly(3))
            ->method('foo')
            ->withConsecutive(
                ['a1', 'a2'],
                ['b1', 'b2'],
                ['c1', null],
            )'

In version 10 the Consecutive constraint class can be used to mimic this behavior as illustrated in the following example:


        $mockObject
            ->expects($this->exactly(3))
            ->method('foo')
            ->with(
                new Consecutive(
                    'a1',
                    'b1',
                    'c1'
                ),
                new Consecutive(
                    'a2',
                    // you can also pass constraints
                    $this->equalTo('b1'),
                    $this->isNull()
                )
            );