<commit_before><?php

namespace Tests\Functional\BackendBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Client;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\BrowserKit\Cookie;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Symfony\Component\Security\Guard\Token\PostAuthenticationGuardToken;

class RepositoriesControllerTest extends WebTestCase
{
    public function testTheRepositoriesListRequiresAuthentication()
    {
        $client = static::createClient();
        $client->request('GET', '/backend/repositories');

        $this->assertTrue($client->getResponse()->isRedirect('/login'));
    }

    public function testThatAnAuthorizedUserCanAccessTheRepositoriesList()
    {
        $client = static::createClient();
        $this->logIn($client, 'admin');
        $client->request('GET', '/backend/repositories');

        $this->assertTrue($client->getResponse()->isSuccessful());
    }

    private function logIn(Client $client, string $username)
    {
        $container = $client->getContainer();
        $session = $container->get('session');
        $user = $container->get('regis.repository.users')->findByUsername($username);

        $firewall = 'main';
        $token = new PostAuthenticationGuardToken($user, 'github', $user->getRoles());

        $container->get('security.token_storage')->setToken($token);

        $session->set('_security_'.$firewall, serialize($token));
        $session->save();

        $cookie = new Cookie($session->getName(), $session->getId());
        $client->getCookieJar()->set($cookie);
    }
}
<commit_msg>Delete useless use statement<commit_after><?php

namespace Tests\Functional\BackendBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Client;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\BrowserKit\Cookie;
use Symfony\Component\Security\Guard\Token\PostAuthenticationGuardToken;

class RepositoriesControllerTest extends WebTestCase
{
    public function testTheRepositoriesListRequiresAuthentication()
    {
        $client = static::createClient();
        $client->request('GET', '/backend/repositories');

        $this->assertTrue($client->getResponse()->isRedirect('/login'));
    }

    public function testThatAnAuthorizedUserCanAccessTheRepositoriesList()
    {
        $client = static::createClient();
        $this->logIn($client, 'admin');
        $client->request('GET', '/backend/repositories');

        $this->assertTrue($client->getResponse()->isSuccessful());
    }

    private function logIn(Client $client, string $username)
    {
        $container = $client->getContainer();
        $session = $container->get('session');
        $user = $container->get('regis.repository.users')->findByUsername($username);

        $firewall = 'main';
        $token = new PostAuthenticationGuardToken($user, 'github', $user->getRoles());

        $container->get('security.token_storage')->setToken($token);

        $session->set('_security_'.$firewall, serialize($token));
        $session->save();

        $cookie = new Cookie($session->getName(), $session->getId());
        $client->getCookieJar()->set($cookie);
    }
}

{'fraction_non_alphanumeric': 0.15434985968194576, 'fraction_numerical': 0.0, 'mean_word_length': 4.092063492063492, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3230024', 'n_tokens_mistral': 865, 'n_tokens_neox': 854, 'n_words': 127}