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.6] Return instance of spy when swapping facade for a Mockery spy #24918

Merged
merged 1 commit into from
Jul 21, 2018

Conversation

dallincoons
Copy link
Contributor

One of the main benefits of spies is that you can move the assertion to the end of the test method. For example, instead of

$mock->shouldReceive('foo')->once()
//act on something

after the 'act' step in your test, you can do

// act on something
$spy->shouldHaveRecieved('foo')->once()

Right now, if I want to get an instance of the spy I have to do
$spy = Facade::getFacadeRoot()
so that I can use the spy in my assertions at the end of the test, which isn't as nice as it could be. This PR simply returns the spy after creating it.

@sisve
Copy link
Contributor

sisve commented Jul 21, 2018

I see you're changing an existing release (5.6). Could these changes cause existing code or packages to fail?

@dallincoons
Copy link
Contributor Author

It behaves the same but just has a return value now.

@taylorotwell
Copy link
Member

Why would you need an instance of the Spy? Can't you just do WhateverFacade::shouldHaveReceived?

@taylorotwell taylorotwell merged commit 0878503 into laravel:5.6 Jul 21, 2018
@GrahamCampbell GrahamCampbell changed the title Return instance of spy when swapping facade for a Mockery spy [5.6] Return instance of spy when swapping facade for a Mockery spy Jul 22, 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.

3 participants