Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

assertQueued failing in Bitbucket pipeline

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:

  • git
  • curl
  • libmcrypt-dev
  • default-mysql-client
  • zip
  • unzip
  • composer

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.

like image 890
Alex Avatar asked Nov 07 '22 11:11

Alex


1 Answers

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.

like image 101
Vladan Avatar answered Nov 11 '22 15:11

Vladan