<commit_before><?php

namespace TreeHouse\BehatCommon;

use Behat\Mink\Driver\BrowserKitDriver;
use Behat\Mink\Exception\UnsupportedDriverActionException;
use Behat\MinkExtension\Context\RawMinkContext;
use PHPUnit_Framework_Assert as Assert;
use Symfony\Component\BrowserKit\Client;
use Symfony\Component\HttpFoundation\RedirectResponse;

class RedirectContext extends RawMinkContext
{
    /**
     * @AfterScenario
     */
    public function afterScenario($event)
    {
        if ($this->getSession()->getDriver() instanceof BrowserKitDriver) {
            $this->getClient()->followRedirects(true);
        }
    }

    /**
     * @When I do not follow redirects
     */
    public function iDoNotFollowRedirects()
    {
        $this->getClient()->followRedirects(false);
    }

    /**
     * @When I follow the current redirect
     */
    public function iFollowTheCurrentRedirect()
    {
        $response = $this->getClient()->getResponse();

        Assert::assertInstanceOf(RedirectResponse::class, $response);

        $this->getSession()->visit($response->getTargetUrl());
    }

    /**
     * @Then I should be redirected to :url
     * @Then I should be redirected to :url with :status
     *
     * @param string $url
     * @param int    $status
     */
    public function iAmRedirected($url, $status = 301)<commit_msg>Default to 302 as Symfony does<commit_after><?php

namespace TreeHouse\BehatCommon;

use Behat\Mink\Driver\BrowserKitDriver;
use Behat\Mink\Exception\UnsupportedDriverActionException;
use Behat\MinkExtension\Context\RawMinkContext;
use PHPUnit_Framework_Assert as Assert;
use Symfony\Component\BrowserKit\Client;
use Symfony\Component\HttpFoundation\RedirectResponse;

class RedirectContext extends RawMinkContext
{
    /**
     * @AfterScenario
     */
    public function afterScenario($event)
    {
        if ($this->getSession()->getDriver() instanceof BrowserKitDriver) {
            $this->getClient()->followRedirects(true);
        }
    }

    /**
     * @When I do not follow redirects
     */
    public function iDoNotFollowRedirects()
    {
        $this->getClient()->followRedirects(false);
    }

    /**
     * @When I follow the current redirect
     */
    public function iFollowTheCurrentRedirect()
    {
        $response = $this->getClient()->getResponse();

        Assert::assertInstanceOf(RedirectResponse::class, $response);

        $this->getSession()->visit($response->getTargetUrl());
    }

    /**
     * @Then I should be redirected to :url
     * @Then I should be redirected to :url with :status
     *
     * @param string $url
     * @param int    $status
     */
    public function iAmRedirected($url, $status = 302)
{'fraction_non_alphanumeric': 0.1164256581386726, 'fraction_numerical': 0.0033370411568409346, 'mean_word_length': 3.0632530120481927, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, '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': '7382653', 'n_tokens_mistral': 782, 'n_tokens_neox': 761, 'n_words': 166}