Skip to content

Use Application factory in BehatContainerTrait #11

@jonathanjfshaw

Description

@jonathanjfshaw

Currently in BehatContainerTrait we setup a container ourselves.

I suspect that the best way to intitalise Behat inside phpunitbehat might be to create our own factory class extending \Behat\Behat\ApplicationFactory and then call that factory inside our BehatContainerTrait. This should have good forward-compatability with future versions of Behat, and require us duplicating less Behat code inside phpunitbehat.

There is a gist https://gist.github.com/martinlindhe/83aa60468671e7cf8bed that suggests this:

<?php

use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\ConsoleOutput;
use Behat\Behat\ApplicationFactory;

class BehatTest extends TestCase
{
    /**
     * @group Behat
     */
    public function testRunBehat()
    {
        $behat = (new ApplicationFactory)->createApplication();
        $behat->setAutoExit(false);

        $input = new ArrayInput(['behat', '--format', 'progress']);
        $output = new ConsoleOutput();
        $result = $behat->run($input, $output);

        $this->assertEquals(0, $result);
    }
}

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