I am creating a RESTFUL API for forgot password feature in my Laravel project. I finished it.
However, I don't know how to build unittest to testing event send email occurred?
How do I build it?
$mock = Mockery::mock('Swift_Mailer');
$this->app['mailer']->setSwiftMailer($mock);
$mock->shouldReceive('send')->once()
->andReturnUsing(function($msg) {
$this->assertEquals('My subject', $msg->getSubject());
$this->assertEquals('foo#bar.com', $msg->getTo());
$this->assertContains('Some string', $msg->getBody());
});
you can see this:
Laravel unit testing emails
Related
can somebody send example how to make integration test - i need to test automatic email sender when object saved in database. So i need to ADD object to database for ex h-2 , when its add my service method also sending email to user. How to test by greenmail ? As i see in tutorials there is lot of examples testing only sending service/method, not testing with other methods ..
I need test for POST, add object to database, and test if email going fine to client email.
I have been some problems making webhooks of Stripe works with my application.
So after being able to create, update, delete, resume subscriptions, and create my endpoint to my domain:
www.domain.com
I always recieve 419 http code when a user interact with my application.
Why does it happen?
I write this in case helps someone:
My problem was I hadn't included a route for stripe in my web.php, like this:
Route::post(
'stripe/webhook',
'\Laravel\Cashier\Http\Controllers\WebhookController#handleWebhook'
);
and you can't forget to include stripe in your verifycsrftoken middleware, like this:
protected $except = [
'stripe/*',
];
and once you have done it, you have to configure your endpoint in stripe dashboard to call to the previous route:
www.domain.com/stripe/webhook
and include all the events you want to listen to.
To test it in local you can use stripe cli, that works perfectly:
https://stripe.com/docs/stripe-cli
I am currently testing Stripe webhooks using the latest Laravel Spark. I've got a Stripe account working, meaning that I can add (fake) creditcards and charge subscriptions/single payments. Next, I am using a fake hook endpoint (ultrahook.com) to retrieve webhooks requests from Stripe.
My vanilla route file is from the Spark installation:
$router->post('/webhook/stripe', 'Settings\Billing\StripeWebhookController#handleWebhook');
And should handle all the webhooks fine. To test the webhooks, I checked the StripeWebhookController object and changed a method to log some info:
protected function handleInvoicePaymentSucceeded(array $payload)
{
Log::info('This is some useful handleInvoicePaymentSucceeded.');
}
However, nothing gets logged when I call run a Stripe test webhook of type: invoice.payment_succeeded.
I do see the request coming into the ultrahook console and it gets returned a 200. I can also copy paste the JSON Stripe test webhook and paste it into Postman after which it gets send to http://localhost:80/webhook/stripe ... again a 200 response but nothing logged.
Any advice?
Laravel Cashier instructs you to exclude the webhook routes from VerifyCsrfToken middleware as stated here:
https://laravel.com/docs/5.5/billing#handling-stripe-webhooks
Spark uses Cashier, I'd imagine you need to do the same then.
Well, it appears that I needed to add
CASHIER_ENV=testing
in the env file. Nice to see that in the documentation Laravel... not
stripe webhooks don't call localhost, it should have a domain name to call.
you may use ultrahook gem for that..
it will create a temporary binding url which you can provide in stripe dashboard as callback url
like this
ultrahook stripe 80
which would give you an url that you map it in stripe dashboard
http://stripe.somename.ultrahook.com -> http://localhost:80
NOTE: You can access this url on a browser, it is just a virtual binding
I want to add read receipts function on email send using GMail smtp in Codeigniter. How can I do that? I searched in google and it's only have for pure PHP Mail Function and PHPMailer. But i don't want to use phpmailer plugin. So help me to do with Codeigniter Mail function. Thanks.
you can use the CodeIgniter function to add some extra header in your email:
with Read-Receipt-To: , X-Confirm-reading-to: or Disposition-Notification-To: headers and you put your email or your compagny name followed by your email for the value.
The fonction is $this->email->set_header($header, $value);
But be careful, it doesn't works everytime because of web services security boxes, sometimes they don't let these headers to return to the value's email adress put.
Im having trouble understanding how to process the data sent to my post route from the mandrill webhook.
I have set up my route and registered it in the mandrill settings. Sending a test from the dashboard works fine (webhook is triggered on send, open, and hard_bounce):
Route::post('/mailApi/webhooks', 'ContactController#postMandrill');
Currently, I'm just trying to ensure that I can receive the webhook and make sure that I understand the format.
I have created a function for in my ContactController for testing purposes:
public function postMandrill(){
$data = Input::get("mandrill_events");
$mandrill = new Mandrillemail;
$mandrill->event = $data;
$mandrill->msg_subject = 'test';
$mandrill->save();
}
When I send an email to trigger the webhook, I get no errors and nothing is saved in the database. It seems like the route isn't touched at all. What do I need to do to access the webhook?