Does everything work for real if you create a ticket?
Dec 27, 2022
8
Level 3
Testing A Facade With A Fluent Interface
I'm having trouble figuring out how to assert that a method at the end of a chain on a facade has been called.
I'm using the huddledigital/zendesk-laravel package that provides a Huddle\Zendesk\Facades\Zendesk facade that I'm using in my controller to create a Zendesk ticket. The call looks like Zendesk::tickets()->create($data).
This is the method that is called by the controller when the /api/tickets/new route is posted to:
use Huddle\Zendesk\Facades\Zendesk;
public function create(Request $request)
{
Zendesk::tickets()->create($request->ticket);
}
This is my test:
use Huddle\Zendesk\Facades\Zendesk;
public function testCreateZendeskTicket()
{
Zendesk::spy();
$this->actingAs($this->user)
->json('POST', '/api/tickets/new', ['subject' => 'Testing']);
Zendesk::shouldHaveReceived('tickets->create');
}
I am simply attempting to spy on the facade and assert that Zendesk::tickets()->create() is called by the controller. However, when the test is run, it returns
Method tickets->create(<Any Arguments>) from Mockery_0_Huddle_Zendesk_Services_ZendeskService should be called
at least 1 times but called 0 times.
What am I doing wrong?
Please or to participate in this conversation.