ssaweb/phpunit-slot

A package to help you catch method parameters for testing.

v1.1.0 2024-03-07 16:07 UTC

This package is auto-updated.

Last update: 2025-06-07 19:00:59 UTC


README

A feature that allows you to capture method parameters as you would do with Mockk capture() - https://mockk.io/#capturing

Well, I just created this package to make parameter assertions more readable (my personal thought).

Of course you can say doing the way below already work, but I dunno when there's a need to add a callback for each parameter it didn't look well to me.

That's why I decided to create this package and make this more the way I was used to in Kotlin (with the mockk library =)

$mock
    ->expects($this->once())
    ->method('foo')
    ->with(self::callback(function ($value): bool {
        self::assertEquals('value', $value);
        return true;
    }))

Instead of that I am doing something like this

$slot = new Slot();

$mock
    ->expects($this->once())
    ->method('foo')
    ->with($slot->capture())

//other mock declarations

//then
self::assertEquals(1, $slot->captured);

v1.1.0+ It now supports multiple method calls. So, if your method is being called more than once, the captured value will be an array of each capture value.

$slot = new Slot();

$mock
    ->expects($this->any())
    ->method('foo')
    ->with($slot->capture())

//other mock declarations

//then
self::assertEquals(1, $slot->captured[0]);
self::assertEquals(2, $slot->captured[1]);