<commit_before><?php

namespace Aureka\VBBundle\Tests\SingleLogin;

use Aureka\VBBundle\Tests\Application\AppKernel;
use Symfony\Component\Security\Core\AuthenticationEvents,
    Symfony\Component\Security\Core\Event\AuthenticationEvent;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class LoginTest extends WebTestCase
{

    private $container;
    private $dispatcher;

    protected static function createKernel(array $options = array())
    {
        return new AppKernel('test', true);
    }


    public function setUp()
    {
        $this->container = self::createClient()->getKernel()->getContainer();
        $this->dispatcher = $this->container->get('event_dispatcher');
    }


    /**
     * @test
     */
    public function itCreatesANewUserInVBulletinIfNotExists()
    {
        $vb_bridge = $this->getMock('Aureka\VBBundle\Bridge');
        $this->container->set('aureka_vb.bridge', $vb_bridge);
        $token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
        $token->expects($this->any())
            ->method('getUsername')
            ->will($this->returnValue('test_username'));
        $event = new AuthenticationEvent($token);

        $vb_bridge->expects($this->once())
            ->method('createUser')
            ->with('test_username');

        $this->dispatcher->dispatch(AuthenticationEvents::AUTHENTICATION_SUCCESS, $event);
    }



    /**
     * @test
     */
    public function itDoesNotCreateAUserInVBulletinIfAlreadyExists()
    {
        $vb_bridge = $this->getMock('Aureka\VBBundle\Bridge');
        $vb_bridge->expects($this->any())
            ->method('loadUser')
            ->will($this->returnValue(true));
        $this->container->set('aureka_vb.bridge', $vb_bridge);
        $token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
        $token->expects($this->any())
            ->method('getUsername')
            ->will($this->returnValue('test_username'));
        $event = new AuthenticationEvent($token);

        $vb_bridge->expects($this->never())
            ->method('createUser');

        $this->dispatcher->dispatch(AuthenticationEvents::AUTHENTICATION_SUCCESS, $event);
    }
}<commit_msg>Test refactorings<commit_after><?php

namespace Aureka\VBBundle\Tests\SingleLogin;

use Aureka\VBBundle\Tests\Application\AppKernel;
use Symfony\Component\Security\Core\AuthenticationEvents,
    Symfony\Component\Security\Core\Event\AuthenticationEvent;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class LoginTest extends WebTestCase
{

    private $container;
    private $dispatcher;

    protected static function createKernel(array $options = array())
    {
        return new AppKernel('test', true);
    }


    public function setUp()
    {
        $this->container = self::createClient()->getKernel()->getContainer();
        $this->dispatcher = $this->container->get('event_dispatcher');
    }


    /**
     * @test
     */
    public function itCreatesANewUserInVBulletinIfNotExists()
    {
        $vb_bridge = $this->mockVBBridge();
        $event = $this->getAuthenticationEventForUser('test_username');

        $vb_bridge->expects($this->once())
            ->method('createUser')
            ->with('test_username');

        $this->dispatcher->dispatch(AuthenticationEvents::AUTHENTICATION_SUCCESS, $event);
    }


    /**
     * @test
     */
    public function itDoesNotCreateAUserInVBulletinIfAlreadyExists()
    {
        $vb_bridge = $this->mockVBBridge(array('loadUser' => true));
        $event = $this->getAuthenticationEventForUser('test_username');

        $vb_bridge->expects($this->never())
            ->method('createUser');

        $this->dispatcher->dispatch(AuthenticationEvents::AUTHENTICATION_SUCCESS, $event);
    }


    private function getAuthenticationEventForUser($username)
    {
        $token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
        $token->expects($this->any())
            ->method('getUsername')
            ->will($this->returnValue('test_username'));
        return new AuthenticationEvent($token);
    }


    private function mockVBBridge(array $stubs = array())
    {
        $vb_bridge = $this->getMock('Aureka\VBBundle\Bridge');
        foreach ($stubs as $method => $return_value) {
            $vb_bridge->expects($this->any())
                ->method($method)
                ->will($this->returnValue($return_value));
        }
        $this->container->set('aureka_vb.bridge', $vb_bridge);
        return $vb_bridge;
    }
}
{'fraction_non_alphanumeric': 0.14812405118195618, 'fraction_numerical': 0.0, 'mean_word_length': 3.1032028469750887, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 80, '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': '6015471', 'n_tokens_mistral': 1332, 'n_tokens_neox': 1293, 'n_words': 171}