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.5] Fix NotificationFake interfaces and return fake object. #22396

Merged
merged 2 commits into from
Dec 14, 2017

Conversation

mathieutu
Copy link
Contributor

Hi,
This PR:

  • adds the missing Dispatcher contract on NotificationFake: it failed when injected, and it's supposed to replace the ChannelMannager in the container, which has this contract. (1st commit)
  • return the created Fake object when Notification::fake() method is called. It permits to use it directly in tests. Tests was added for that. (2nd commit)

Thanks.
Matt'

@mathieutu mathieutu force-pushed the fix/interface-notification-fake branch from 4e81435 to 7934447 Compare December 12, 2017 11:20
@taylorotwell
Copy link
Member

So how do we recreate the problem this created?

@mathieutu
Copy link
Contributor Author

Using Dependency Injection instead of facade:

public function store(Dispatcher $notifications)
{
        // (...)

        $notifications->send(
            $users,
            new FooNotification()
        );
}

And it's even not only about "what failed". In my opinion this is just an oversight. The other interface of ChannelManager, is already implemented, the methods from the interface are implemented, and the container already resolves app(Dispatcher::class) as NotificationFake...

@taylorotwell
Copy link
Member

taylorotwell commented Dec 13, 2017

If you are using dependency injection, why would you use the fake method at all? You would just make the dispatcher directly? The fake method only exists for when testing with facades.

@mathieutu
Copy link
Contributor Author

hum ? Didn't understand your point..
The missing interface hasn't any link with the fake method, it's just a missing interface!
As BusFake implements the Bus/Dispatcher, NotificationFake must implements the Notification/Dispatcher. It must because it's a fake. It's supposed to implement the same method, and simulate the same behavior. You already use the same methods, and it's binding in its usage, so it's really just an oversight.

And btw the fake is not just only for the Facade but for all the ways to access to the container. If you use $notifiable->notify() it will be exactly the same, because it's just app(Dispatcher::class) behind the scene.

This is just a little PR with two different things around the same topic :

  • 1st commit is just fixing a bug by implementing a missing interface.
  • 2nd is simply about returning the fake from the Facade fake method. It doesn't change anything to the actual usage, it just permits to use it directly afterwards.

@taylorotwell taylorotwell merged commit d0ebf33 into laravel:5.5 Dec 14, 2017
ph4r05 added a commit to ph4r05/framework that referenced this pull request Dec 14, 2017
* commit 'a1795b1ba29df8c6a9ac27a525cc42f61a4544dc':
  formatting
  [5.5] Fix NotificationFake interfaces and return fake object. (laravel#22396)
  Add cattle to $uncountable (laravel#22415)
  Fix database events phpdoc (laravel#22420)
  Delete unused comment (laravel#22418)
  5.5 database queue - transactions wrapped in closures, tsx management fixed
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