bin/behat @FootballTeamBundle в порядке, но bin/phing не для запуска FeatureContext

Если я использую bin/behat @FootballTeamBundle в терминале как в автономном режиме снимки экрана с ошибками принимаются и сохраняются в build/behat/ папка, которая хорошо, однако, если я бегу bin/phing тогда FeatureContext Кажется, что файл в целом игнорируется, поэтому ни снимки экрана, ни его внутренние методы не запускаются (например, я жду ** секунд), что странно. Кто-нибудь знает решение этой проблемы?

Я также обновил строку bin/behat -f progress --format html --out ${dir-report}/behat.html в bin/behat @FootballTeamBundle в моем build.xml но ничего не изменилось.

Заранее спасибо.

/var/www/html/local/sport/behat.yml

default:
    context:
        class: FeatureContext
        parameters:
            screen_shots_path: 'build/behat/'
    extensions:
        Behat\Symfony2Extension\Extension:
            mink_driver: true
            kernel:
                env: test
                debug: true
        Behat\MinkExtension\Extension:
            base_url: 'http://localhost/local/sport/web/app_test.php/'
            files_path: 'dummy/'
            browser_name: chrome
            goutte: ~
            selenium2: ~
    paths:
        features: src/Football/TeamBundle/Features
        bootstrap: %behat.paths.features%/Context

/var/www/html/local/sport/src/Football/TeamBundle/Features/Context/FeatureContext.php

<?php

namespace Football\TeamBundle\Features\Context;

use Behat\MinkExtension\Context\MinkContext;
use Behat\Mink\Exception\UnsupportedDriverActionException;
use Behat\Mink\Driver\Selenium2Driver;

class FeatureContext extends MinkContext
{
    /**
     * Where the failure images will be saved.
     *
     * @var string
     */
    protected $screenShotsPath;

    /**
     * Comes from behat.yml file.
     *
     * @param $parameters
     */
    public function __construct($parameters)
    {
        $this->screenShotsPath = $parameters['screen_shots_path'];
    }

    /**
     * Take screen-shot when step fails.
     * Works only with Selenium2Driver.
     *
     * @AfterStep
     * @param $event
     * @throws \Behat\Mink\Exception\UnsupportedDriverActionException
     */
    public function takeScreenshotAfterFailedStep($event)
    {
        if (4 === $event->getResult()) {
            $driver = $this->getSession()->getDriver();

            if (! ($driver instanceof Selenium2Driver)) {
                throw new UnsupportedDriverActionException(
                    'Taking screen-shots is not supported by %s, use Selenium2Driver instead.',
                    $driver
                );

                return;
            }

            if (! is_dir($this->screenShotsPath)) {
                mkdir($this->screenShotsPath, 0777, true);
            }

            $filename = sprintf(
                '%s_%s_%s.%s',
                $this->getMinkParameter('browser_name'),
                date('Y-m-d') . '_' . date('H:i:s'),
                uniqid('', true),
                'png'
            );

            file_put_contents($this->screenShotsPath . '/' . $filename, $driver->getScreenshot());
        }
    }

    /**
     * @Then /^I wait for "([^"]*)" seconds$/
     *
     * @param $seconds
     */
    public function iWaitForGivenSeconds($seconds)
    {
        $this->getSession()->wait($seconds*1000);
    }
}

/var/www/html/local/sport/build.xml

<!-- GLOBAL VARIABLES -->
<property name="dir-source" value="${project.basedir}/src" />
<property name="dir-report" value="${project.basedir}/build/phing" />
<!-- END -->

<!-- AVAILABLE CLI COMMANDS -->
<target name="build"
        description="Runs everything in order ..."
        depends="cache-clear, cache-warm, load-fixtures, codesniffer-psr2, behat-bdd" />
<!-- END -->

<!-- FILESET -->
<fileset id="sourcecode" dir="${dir-source}">
    <include name="**/*.php" />
</fileset>
<!-- END -->

............. OTHER TESTS ARE HERE, JUST REMOVED TO KEEP IT CLEAN

<!-- BEHAT - BDD -->
<target name="behat-bdd">
    <echo msg="Running Behat tests ..." />
    <exec logoutput="true" checkreturn="true"
          command="bin/behat -f progress --format html --out ${dir-report}/behat.html"
          dir="./" />
</target>
<!-- END -->

1 ответ

Решение

Я никогда не имел дело с фингом и фанатом Symfony. Надеюсь, это чисто проблема конфигурации. Попробуйте быть более точным с вашими путями, используя %behat.paths.base%, Также используйте пространства имен;)

default:
    context:
        class: Football\TeamBundle\Features\Context\FeatureContext
        parameters:
            screen_shots_path: %behat.paths.base%/build/behat/
    extensions:
        Behat\Symfony2Extension\Extension:
            mink_driver: true
            kernel:
                env: test
                debug: true
        Behat\MinkExtension\Extension:
            base_url: 'http://localhost/local/sport/web/app_test.php/'
            files_path: %behat.paths.base%/dummy/
            browser_name: chrome
            goutte: ~
            selenium2: ~
    paths:
        features: %behat.paths.base%/src
        bootstrap: %behat.paths.features%/Context

%behat.paths.base% где ты behat.yml сидит. Поэтому обновите конфиг, указав в нем правильные пути.

Другие вопросы по тегам