Cómo probar el correo electrónico en la prueba funcional (Symfony2)

Estoy tratando de probar el correo electrónico en la prueba funcional ...

Mi código fuente es el mismo que elejemplo del libro de cocina,

el controlador :

public function sendEmailAction($name)
{
    $message = \Swift_Message::newInstance()
        ->setSubject('Hello Email')
        ->setFrom('[email protected]')
        ->setTo('[email protected]')
        ->setBody('You should see me from the profiler!')
    ;

    $this->get('mailer')->send($message);

    return $this->render(...);
}

Y la prueba:

// src/Acme/DemoBundle/Tests/Controller/MailControllerTest.php
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class MailControllerTest extends WebTestCase
{
    public function testMailIsSentAndContentIsOk()
    {
        $client = static::createClient();

        // Enable the profiler for the next request (it does nothing if the profiler is not available)
        $client->enableProfiler();

        $crawler = $client->request('POST', '/path/to/above/action');

        $mailCollector = $client->getProfile()->getCollector('swiftmailer');

        // Check that an e-mail was sent
        $this->assertEquals(1, $mailCollector->getMessageCount());

        $collectedMessages = $mailCollector->getMessages();
        $message = $collectedMessages[0];

        // Asserting e-mail data
        $this->assertInstanceOf('Swift_Message', $message);
        $this->assertEquals('Hello Email', $message->getSubject());
        $this->assertEquals('[email protected]', key($message->getFrom()));
        $this->assertEquals('[email protected]', key($message->getTo()));
        $this->assertEquals(
            'You should see me from the profiler!',
            $message->getBody()
        );
    }
}

sin embargo me salió este error:

Error fatal de PHP: llamar a una función miembro getCollector () en un no objeto

El problema viene de esta línea:

$mailCollector = $client->getProfile()->getCollector('swiftmailer');

alguna idea ?

Respuestas a la pregunta(1)

Su respuesta a la pregunta