Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Adds new when() method #406

Merged
merged 3 commits into from
Sep 24, 2021
Merged

Adds new when() method #406

merged 3 commits into from
Sep 24, 2021

Conversation

mertasan
Copy link
Contributor

Q A
Bug fix? no
New feature? yes

It makes some expectations work conditionally.

when() is preferably used as an alternative to the skip() method, no need to write extra tests.

Examples

Before:

it('mysql test', function () {

   expect(new Foo())
         ->mysql
         ->toBeTrue();

})->skip(fn() => DB::getDriverName() === 'mysql', 'Only runs when using mysql');

it('sqlite test', function () {

   expect(new Foo())
         ->sqlite
         ->toBeTrue();

})->skip(fn() => DB::getDriverName() === 'sqlite', 'Only runs when using sqlite');

After:

it('database test', function () {

    $driver = DB::getDriverName();
    
    expect(new Foo())
        ->when($driver === 'mysql',
            fn($foo) => $foo->mysql->toBeTrue()
        )
        ->when($driver === 'sqlite',
            fn($foo) => $foo->sqlite->toBeTrue()
        )
        ->bar->toEqual('bar');

});

For more examples, please review the tests.

Thank you.

@mertasan mertasan mentioned this pull request Sep 23, 2021
@nunomaduro nunomaduro merged commit f23f857 into pestphp:master Sep 24, 2021
@nunomaduro
Copy link
Member

Can you pull request the docs please?

@nunomaduro
Copy link
Member

Can you also document the unless? b43a598

@mertasan
Copy link
Contributor Author

I'll make PR, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants