Feb 12, 2017
0
Level 5
Mock request() global helper
I have a test that creates a user in Stripe. In order to do this, I am using the request() helper because of it's convenience. This is what my create method looks like to create the Stripe customer:
public function create()
{
return Customer::create([
'description' => request('lastName') . ', ' . request('firstName'),
'email' => request('email'),
'source' => request('token'),
'metadata' => [
'first_name' => request('firstName'),
'last_name' => request('lastName'),
'address' => request('address'),
'zip' => request('zip'),
'phone' => request('phone'),
]
], ['api_key' => config('services.stripe.secret')]);
}
This is not in the controller, but in its own class called StripeCustomer. This would be a unit test because it is part of a series of events that happens when a donation is posted, otherwise I would test it using $this->post()...
So, how can I mock the global request so that I can add the fields necessary to test my method?
Please or to participate in this conversation.