mardi 9 mai 2017

How to use a Facade outside of Laravel

I'm running PHPUnit with Selenium in Laravel to test my app and I need to test email sending.I found this solution that sounds very good for me. Testing Email with Assertions

In my case, I'm using Selenium:

class ExampleTest extends PHPUnit_Extensions_Selenium2TestCase
{
    use MailTracking;

So my problem is here on this part:

public function setUpMailTracking()
    {
        Mailer::getSwiftMailer()
            ->registerPlugin(new TestMailEventListener($this));
    }

Im getting this error message:

Using $this when not in object context

After digging inside the code I realize that there's no SwiftMailer instantiated yet because I'm out of Laravel app (Tests run inside /tests folder).I don't know how to access the Mailer class that is instantiated when the application boot. In my head I have these options to solve this problem:

  • Retrieve the Application instance somehow and access the Mailer class.
  • Create a new app instance inside the tests and then instantiate a new Mailer following the code in MailServiceProvider.php

What do you guys think?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire