Skip to content

Doc : Using with APIs #17

@silverbackdan

Description

@silverbackdan

I've got a solution if you are using this with Behat and API calls. It may be useful in the docs or if it's wrong I'm happy for comments.

I extend the MailerContext to my own like this:

<?php

declare(strict_types=1);

namespace App\Tests\Behat;

use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\MinkExtension\Context\MinkContext;
use Kocal\SymfonyMailerTesting\MailerLogger;

/**
 * @author Daniel West <daniel@silverback.is>
 */
class MailerContext extends \Kocal\SymfonyMailerTesting\Bridge\Behat\MailerContext
{
    /**
     * @BeforeScenario
     */
    public function setMinkContainerLogger(BeforeScenarioScope $scope)
    {
        /** @var MinkContext $minkContext */
        $minkContext = $scope->getEnvironment()->getContext(MinkContext::class);
        $this->setMailerLogger($minkContext->getSession()->getDriver()->getClient()->getContainer()->get('test.service_container')->get(MailerLogger::class));
    }
}

This way we are getting the logger service being used in the container for the final request when the Mink extension is used.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions