vendredi 29 mai 2020

How I can assert that an Attachment on a Mailable class equals to a file?

In a laravel project I have the following Mailable:

class MyMail extends Mailable
{
  public function build()
  {
     return $this            
                ->from('hentaiouji@neko.com', 'Hentai Prince witouh Story cat')
                ->subject("Stony Cat Lists")
                ->attach('myFile.xlsx', [
                    'as'   => 'myFile.xlsx',
                    'mime' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
                ])
                ->bcc('konekochan@example.com');
  }
}

And I want to assert that the correct file is attached so I need to locate the path and compare the md5's that are generated by reading the files.

The question is how from a mailable can retrieve the attachments so I can manually read them in php. The approach I want to follow is the:

public function testAtachmentIsTheSame()
{
   $expectedAttatchmentMd5=md5(file_get_contents('myFile.xlsx'));
   $mailable=(new MyMail())->build();
   $attatchmentMd5; //Contains the md5 read from the mailable Atachment

   $this->assertEquals($expectedAttatchmentMd5,$attatchmentMd5);
}

So in my test how I can get the attatchment from a Mailable without sending the actual email?

Aucun commentaire:

Enregistrer un commentaire