<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;

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);
    }

    /**
     * @Then I should be redirected to :url
     */
    public function iAmRedirected($url)
    {
        $headers = $this->getSession()->getResponseHeaders();

        Assert::assertArrayHasKey('location', $headers, 'The response contains a "location" header');

        Assert::assertEquals($url, $headers['location'][0], 'The "location" header does not point to the correct URI');

        $client = $this->getClient();
        $client->followRedirects(true);
        $client->followRedirect();
    }<commit_msg>added step for following current redirects (i.e. while sending mail) without knowing target url<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
     */
    public function iAmRedirected($url)
    {
        $headers = $this->getSession()->getResponseHeaders();

        Assert::assertArrayHasKey('location', $headers, 'The response contains a "location" header');

        Assert::assertEquals($url, $headers['location'][0], 'The "location" header does not point to the correct URI');

        $client = $this->getClient();
        $client->followRedirects(true);
        $client->followRedirect();
    }
{'fraction_non_alphanumeric': 0.12631222485607857, 'fraction_numerical': 0.0006772773450728074, 'mean_word_length': 3.2998544395924307, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 30, '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': '3861566', 'n_tokens_mistral': 824, 'n_tokens_neox': 811, 'n_words': 177}