<commit_before><?php

namespace Behat\Mink\Behat\Context;

use Behat\Gherkin\Node\TableNode;

use Behat\Behat\Context\TranslatedContextInterface,
    Behat\Behat\Context\BehatContext,
    Behat\Behat\Event\ScenarioEvent;

use Behat\Mink\Mink,
    Behat\Mink\Session,
    Behat\Mink\Driver\GoutteDriver,
    Behat\Mink\Driver\SahiDriver,
    Behat\Mink\Exception\ElementNotFoundException,
    Behat\Mink\Exception\ExpectationFailedException,
    Behat\Mink\Exception\PlainTextResponseException,
    Behat\Mink\Exception\ElementContentException,
    Behat\Mink\Exception\ElementTextException;

use Goutte\Client as GoutteClient;

use Behat\SahiClient\Connection as SahiConnection,
    Behat\SahiClient\Client as SahiClient;

require_once 'PHPUnit/Autoload.php';
require_once 'PHPUnit/Framework/Assert/Functions.php';

/*
 * This file is part of the Behat\Mink.
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

/**
 * Mink context for Behat testing tool.
 *
 * @author      <NAME> <<EMAIL>>
 */
class MinkContext extends BehatContext implements TranslatedContextInterface
{
    private static $minkInstance;
    private $parameters;

    /**
     * Initializes Mink environment.
     *
     * @param   array   $parameters     list of context parameters
     */
    public function __construct(array $parameters = array())
    {
        $this->parameters = array_merge(array(
            'default_session' => 'goutte',
            'base_url'        => 'http://localhost',
            'show_cmd'        => null,
            'browser'         => 'firefox',
            'goutte' => array(
                'zend_config'       => array(),
                'server_parameters' => array()
            ),
            'sahi' => array(
                'sid'  => uniqid(),
                'host' => 'localhost',
                'port' => 9999
            )
        ), $parameters);

        if (null === self::$minkInstance) {
            self::$minkInstance = new Mink();
            $this->registerSessions(self::$minkInstance);
        }
    }

    /**
     * Locates url, based on provided path.
     *
     * @param   string  $path
     *
     * @return  string
     */
    public function locatePath($path)
    {
        $startUrl = rtrim($this->getParameter('base_url'), '/') . '/';

        return 0 !== strpos('http', $path) ? $startUrl . ltrim($path, '/') : $path;
    }

    /**
     * Returns Mink instance.
     *
     * @return  Behat\Mink\Mink
     */
    public function getMink()
    {
        return self::$minkInstance;
    }

    /**
     * Returns current Mink session.
     *
     * @param   string|null name of the session OR active session will be used
     *
     * @return  Behat\Mink\Session
     */
    public function getSession($name = null)
    {
        return $this->getMink()->getSession($name);
    }

    /**
     * Returns all context parameters.<commit_msg>check, that Mink is initialized<commit_after><?php

namespace Behat\Mink\Behat\Context;

use Behat\Gherkin\Node\TableNode;

use Behat\Behat\Context\TranslatedContextInterface,
    Behat\Behat\Context\BehatContext,
    Behat\Behat\Event\ScenarioEvent;

use Behat\Mink\Mink,
    Behat\Mink\Session,
    Behat\Mink\Driver\GoutteDriver,
    Behat\Mink\Driver\SahiDriver,
    Behat\Mink\Exception\ElementNotFoundException,
    Behat\Mink\Exception\ExpectationFailedException,
    Behat\Mink\Exception\PlainTextResponseException,
    Behat\Mink\Exception\ElementContentException,
    Behat\Mink\Exception\ElementTextException;

use Goutte\Client as GoutteClient;

use Behat\SahiClient\Connection as SahiConnection,
    Behat\SahiClient\Client as SahiClient;

require_once 'PHPUnit/Autoload.php';
require_once 'PHPUnit/Framework/Assert/Functions.php';

/*
 * This file is part of the Behat\Mink.
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

/**
 * Mink context for Behat testing tool.
 *
 * @author      <NAME> <<EMAIL>>
 */
class MinkContext extends BehatContext implements TranslatedContextInterface
{
    private static $minkInstance;
    private $parameters;

    /**
     * Initializes Mink environment.
     *
     * @param   array   $parameters     list of context parameters
     */
    public function __construct(array $parameters = array())
    {
        $this->parameters = array_merge(array(
            'default_session' => 'goutte',
            'base_url'        => 'http://localhost',
            'show_cmd'        => null,
            'browser'         => 'firefox',
            'goutte' => array(
                'zend_config'       => array(),
                'server_parameters' => array()
            ),
            'sahi' => array(
                'sid'  => uniqid(),
                'host' => 'localhost',
                'port' => 9999
            )
        ), $parameters);

        if (null === self::$minkInstance) {
            self::$minkInstance = new Mink();
            $this->registerSessions(self::$minkInstance);
        }
    }

    /**
     * Locates url, based on provided path.
     *
     * @param   string  $path
     *
     * @return  string
     */
    public function locatePath($path)
    {
        $startUrl = rtrim($this->getParameter('base_url'), '/') . '/';

        return 0 !== strpos('http', $path) ? $startUrl . ltrim($path, '/') : $path;
    }

    /**
     * Returns Mink instance.
     *
     * @return  Behat\Mink\Mink
     */
    public function getMink()
    {
        if (null === self::$minkInstance) {
            throw new \RuntimeException(
                'Mink is not initialized. Forgot to call parent context constructor?'
            );
        }

        return self::$minkInstance;
    }

    /**
     * Returns current Mink session.
     *
     * @param   string|null name of the session OR active session will be used
     *
     * @return  Behat\Mink\Session
     */
    public function getSession($name = null)
    {
        return $this->getMink()->getSession($name);
    }

    /**
     * Returns all context parameters.
{'fraction_non_alphanumeric': 0.12255772646536411, 'fraction_numerical': 0.0016147263038914905, 'mean_word_length': 2.2159916926272065, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3510907', 'n_tokens_mistral': 1894, 'n_tokens_neox': 1841, 'n_words': 401}