<commit_before><?php

namespace ApiBundle\Features\Context;

use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Behat\Tester\Exception\PendingException;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
use Behat\MinkExtension\Context\MinkContext;
use Behat\Symfony2Extension\Context\KernelAwareContext;
use Symfony\Component\HttpKernel\KernelInterface;

/**
 * Defines application features from the specific context.
 *
 * @package ApiBundle\Features\Context
 * @author  <NAME> <<EMAIL>>
 */
class FeatureContext extends BaseApiFeature implements Context, SnippetAcceptingContext
{
    /**
     * Initializes context.
     *
     * Every scenario gets its own context instance.
     * You can also pass arbitrary arguments to the
     * context constructor through behat.yml.
     */
    public function __construct($host)
    {
        parent::__construct($host);
    }

    /**
     * @Given I want to make an API request with the data in file :arg1
     */
    public function iWantToMakeAnApiRequestWithTheDataInFile($file)
    {
        $fileContent = $this->readFile($file);
        $this->setRequestData($fileContent);
    }

    /**
     * @When I make a :arg1 request to :arg2
     */
    public function iAmMakingARequestTo($requestMethod, $requestUrl)
    {
        $requestUrl = 'app_dev.php/' . $requestUrl;
        $requestData     = $this->getRequestData();

        $responseWrapper = $this->getGuzzleClient()->createRequest($requestMethod, $requestUrl, null, $requestData)->send();
        $this->setResponseData($responseWrapper);
    }

    /**
     * @Then the response has a status code of :arg1
     */
    public function theResponseHasAStatusCodeOf($expectedStatusCode)
    {
        $actualStatusCode = $this->getResponseData()->getStatusCode();

        \PHPUnit_Framework_TestCase::assertEquals($expectedStatusCode, $actualStatusCode, "Expected the response to have a status code of {$actualStatusCode}.");
    }

    /**
     * @Then the response contains valid JSON
     */
    public function theResponseContainsValidJson()
    {
        $responseBody = $this->getResponseData()->getBody(true);

        \PHPUnit_Framework_TestCase::assertJson($responseBody, 'Expected the response to be valid JSON.');
    }

    /**
     * @Then the response has the same contents as the file :arg1<commit_msg>Remove app_dev.php from paths, no longer needed<commit_after><?php

namespace ApiBundle\Features\Context;

use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Behat\Tester\Exception\PendingException;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
use Behat\MinkExtension\Context\MinkContext;
use Behat\Symfony2Extension\Context\KernelAwareContext;
use Symfony\Component\HttpKernel\KernelInterface;

/**
 * Defines application features from the specific context.
 *
 * @package ApiBundle\Features\Context
 * @author  <NAME> <<EMAIL>>
 */
class FeatureContext extends BaseApiFeature implements Context, SnippetAcceptingContext
{
    /**
     * Initializes context.
     *
     * Every scenario gets its own context instance.
     * You can also pass arbitrary arguments to the
     * context constructor through behat.yml.
     */
    public function __construct($host)
    {
        parent::__construct($host);
    }

    /**
     * @Given I want to make an API request with the data in file :arg1
     */
    public function iWantToMakeAnApiRequestWithTheDataInFile($file)
    {
        $fileContent = $this->readFile($file);
        $this->setRequestData($fileContent);
    }

    /**
     * @When I make a :arg1 request to :arg2
     */
    public function iAmMakingARequestTo($requestMethod, $requestUrl)
    {
        $requestData     = $this->getRequestData();

        $responseWrapper = $this->getGuzzleClient()->createRequest($requestMethod, $requestUrl, null, $requestData)->send();
        $this->setResponseData($responseWrapper);
    }

    /**
     * @Then the response has a status code of :arg1
     */
    public function theResponseHasAStatusCodeOf($expectedStatusCode)
    {
        $actualStatusCode = $this->getResponseData()->getStatusCode();

        \PHPUnit_Framework_TestCase::assertEquals($expectedStatusCode, $actualStatusCode, "Expected the response to have a status code of {$actualStatusCode}.");
    }

    /**
     * @Then the response contains valid JSON
     */
    public function theResponseContainsValidJson()
    {
        $responseBody = $this->getResponseData()->getBody(true);

        \PHPUnit_Framework_TestCase::assertJson($responseBody, 'Expected the response to be valid JSON.');
    }

    /**
     * @Then the response has the same contents as the file :arg1
{'fraction_non_alphanumeric': 0.10781841109709962, 'fraction_numerical': 0.0025220680958385876, 'mean_word_length': 3.447663551401869, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 31, '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': '7143883', 'n_tokens_mistral': 1330, 'n_tokens_neox': 1327, 'n_words': 326}