<commit_before><?php

namespace AppBundle\Tests\Controller;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class DefaultControllerTest extends WebTestCase
{
    public function testIndex()
    {
        $client = static::createClient();

        $crawler = $client->request('GET', '/');

        $this->assertEquals(200, $client->getResponse()->getStatusCode());
        $this->assertContains('Welcome to Symfony', $crawler->filter('#container h1')->text());
    }
}
<commit_msg>Add functional tests for the API controller<commit_after><?php

namespace AppBundle\Tests\Controller;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class ApiControllerTest extends WebTestCase
{
    public function testGame()
    {
        $id = $this->doTestNewGame();
        $this->doTestGuess($id);
    }

    public function doTestNewGame()
    {
        $client = static::createClient();

        $container = $client->getContainer();
        $route = $container->get('router')->generate('game');

        // POST to /game
        $client->request('POST', $route);

        // Expect a 201 CREATED status code
        $this->assertEquals(201, $client->getResponse()->getStatusCode());

        $content = $client->getResponse()->getContent();
        // Should not contain an error, but should contain at least data and id
        $this->assertNotContains('error', $content);
        $this->assertContains('data', $content);
        $this->assertContains('id', $content);

        // Get the new game ID
        $data = json_decode($content, true);

        return $data['data']['id'];
    }

    public function doTestGuess($id)
    {
        $client = static::createClient();

        $container = $client->getContainer();
        $route = $container->get('router')->generate('guess', ['id' => $id]);

        // PUT to /game/{id} with a JSON body containing a letter
        $client->request(
            'PUT',
            $route,
            [],
            [],
            ['CONTENT_TYPE' => 'application/json'],
            '{ "letter": "a" }'
        );

        // Expect a 200 OK status code
        $this->assertEquals(200, $client->getResponse()->getStatusCode());

        $content = $client->getResponse()->getContent();
        // Should not contain an error, but should contain at least data, word, tries_left and status
        $this->assertNotContains('error', $content);
        $this->assertContains('data', $content);
        $this->assertContains('word', $content);
        $this->assertContains('tries_left', $content);
        $this->assertContains('status', $content);
    }
}

{'fraction_non_alphanumeric': 0.15827890895121013, 'fraction_numerical': 0.006146753745678064, 'mean_word_length': 2.7521613832853027, 'pattern_counts': {'":': 1, '<': 5, '<?xml version=': 0, '>': 40, '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': '1687273', 'n_tokens_mistral': 720, 'n_tokens_neox': 699, 'n_words': 160}