As it says in the title, assertQueued is failing in my Bitbucket pipeline, but it doesn't fail locally.
The test in question can be seen below:
Mail::fake();
Queue::fake();
/*Generating users and triggering emails*/
$users = User::all();
foreach($users as $user){
Mail::assertQueued(Email::class, function ($mail) use ($user) {
return $mail->hasTo($user->preferred_email);
});
}
It simply creates users, sends emails to those users and then checks to see if those emails have been queued.
The phpunit.xml file sets the environment variables as seen below:
<env name="APP_ENV" value="testing"/>
<env name="DB_DATABASE_API" value="homestead"/>
<env name="MAIL_DRIVER" value="log"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="database"/>
All of this works locally. However, when running it all through Bitbucket pipelines, the test above fails by saying:
The expected [App\Mail\Email] mailable was not queued.
Failed asserting that false is true.
The email is below:
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class Email extends Mailable
{
use Queueable, SerializesModels;
public $email;
public $subject;
/**
* Create a new message instance.
*
* @param $email
* @param $subject
*/
public function __construct($email, $subject)
{
$this->email = $email;
$this->subject = $subject;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->subject($this->subject)->view('contact.emails.email');
}
}
Queueing the email:
Mail::to($user->preferred_email)->queue(new Email($user->preferred_email, $subject)));
The docker image being used is PHP:7.2-fpm. The following is installed:
Composer install and artisan migrate are both run before PHPUnit is run. All tests pass aside from that single test. No other tests make use of the assertQueued assertion. Database related tests work without issue and a test making use of assertSentTo
for a notification that uses the Queueable trait passes without issue.
If you require any further information, please let me know! I appreciate any help.
Verify that your package versions are up to date. It could be some weird hiccup with Bitbucket Pipelines, it knows to do that from time to time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With