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

[5.7] Make expectation closure optional for mock and spy instances #26242

Merged
merged 1 commit into from
Oct 24, 2018
Merged

[5.7] Make expectation closure optional for mock and spy instances #26242

merged 1 commit into from
Oct 24, 2018

Conversation

cmorbitzer
Copy link
Contributor

@cmorbitzer cmorbitzer commented Oct 24, 2018

#26171 introduced the ability to more conveniently add mock and spy instances to the container in a test. These methods require a closure as the second argument.

Passing the closure is perfectly valid, and is the example given in the blog announcement. However, examples of the use of this closure is rare. In fact, AFAIK it's completely undocumented by Laravel and Mockery. Also, requiring the closure is inconvenient where no expectations are desired.

This PR makes the second argument optional.

Before:

class ExampleTest extends TestCase
{
    /**
     * A basic test example.
     *
     * @return void
     */
    public function testExample()
    {
        $mailer = $this->spy(Mailer::class, function ($mock) {
            $mock->shouldReceive('send')->andReturn(true);
        });

        // SUT here

        $mailer->shouldHaveReceived('send');
    }
}

After:

class ExampleTest extends TestCase
{
    /**
     * A basic test example.
     *
     * @return void
     */
    public function testExample()
    {
        $mailer = $this->spy(Mailer::class);
        $mailer->shouldReceive('send')->andReturn(true);

        // SUT here

        $mailer->shouldHaveReceived('send');
    }
}

@taylorotwell taylorotwell merged commit de266be into laravel:5.7 Oct 24, 2018
@GrahamCampbell GrahamCampbell changed the title Make expectation closure optional for mock and spy instances [5.7] Make expectation closure optional for mock and spy instances Oct 30, 2018
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.

None yet

2 participants