Support the ongoing development of Laravel.io →
posted 9 years ago
Testing
Last updated 1 year ago.
0

When I do this in my test:

Event::shouldReceive('fire')->once()->withArgs([Mockery::type('Fry\Events\RouteRequested')]);

I get past the above error, but then I get another:

testing.ERROR: exception 'Mockery\Exception\NoMatchingExpectationException' with message 'No matching handler found for Mockery_0_Illuminate_Events_Dispatcher::fire("creating: index", array(0=>'object(Illuminate\View\View)',)). Either the method was unexpected or its arguments matched no expected argument list for this method

Which is coming from another event being fired. My understanding is that the Mock matches the total method signature (including args), so I don't understand why this is happening.

Anyone else?

0

I have this problem too. When using Event::shouldRecieve('fire')->withArgs(Mockery::any()); I started writing out all events that Event should recieve, which is very time consuming.

But now I do this:


// Mock the Event facade.
Event::shouldReceive('fire')->once()->withArgs(['user.created.superuser', Mockery::any()]);

// Ignore the rest of Event-calls
Event::shouldReceive('fire')->withAnyArgs();

This will fail if the Event doesn't recieve the user.created.superuser call and keep going no matter which handlers it is missing.

I hope it helps you.

Niels.

Last updated 9 years ago.
0

Did anybody have luck with resolving this? I tried the code below and I get a pass and it should fail.

  Event::shouldReceive('fire')
    ->with('ManifestRecordCreated',['poseId' => 1, 'stateId' => 1, 'manifestId' => 1])
    ->once();

  Event::shouldReceive('fire')->withAnyArgs();

  Event::fire(new ManifestRecordCreated(2, 1, 1));
0

You also have to include Mockery::close() in the tearDown() method.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

bcdennis bcdennis Joined 13 Jan 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.