Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add ability to extend TestCall to create custom chained helpers #1267

Open
wants to merge 1 commit into
base: 3.x
Choose a base branch
from

Conversation

JHWelch
Copy link
Contributor

@JHWelch JHWelch commented Sep 19, 2024

What:

  • Bug Fix
  • New Feature

Description:

Adds the ability to ->extend(...) TestCall in the same fashion that expectations are extendable.

test()->extend('fooBar', function () {
    return $this->with([
        'foo',
        'bar',
    ]);
});

I had this idea after discussing on Pinkary and realize this was not currently a way Pest could be extended.

This opens up the framework for a whole new area of extensibility.

If this is something you want to add, I can PR the docs repo wherever makes sense.

Comment on lines +664 to +666
$this->description = "extend: $name";
$this->testCaseMethod->closure = fn (): null => null;
Copy link
Contributor Author

@JHWelch JHWelch Sep 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is required because extend is being called non-statically. With this combination no errors are thrown and no output is included from a test()->extend(...) call.

I would need to add a different StaticallyExtendable or something like it to be able to use TestCall::extend(...) which is another possible API.

@JHWelch JHWelch force-pushed the add-test-call-extension branch 2 times, most recently from 1f28941 to 86cf528 Compare September 26, 2024 14:19
@JHWelch JHWelch force-pushed the add-test-call-extension branch from 86cf528 to 9f77459 Compare October 1, 2024 17:06
@JHWelch JHWelch force-pushed the add-test-call-extension branch from 9f77459 to 3009567 Compare October 26, 2024 19:53
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant