<commit_before><?php

/*
 * This file is part of the Elcodi package.
 *
 * Copyright (c) 2014 Elcodi.com
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * Feel free to edit as you please, and have fun.
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */

namespace Elcodi\Component\User\Tests\UnitTests\Wrapper;

use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\SecurityContextInterface;

use Elcodi\Component\User\Entity\Interfaces\CustomerInterface;
use Elcodi\Component\User\Factory\CustomerFactory;
use Elcodi\Component\User\Wrapper\CustomerWrapper;

/**
 * Class CustomerWrapperTest
 *
 * @author <NAME> <<EMAIL>>
 */
class CustomerWrapperTest extends \PHPUnit_Framework_TestCase
{
    /**
     *
     */
    public function testLoadCustomerFromToken()
    {
        $customer = $this->mockCustomer();
        $factory = $this->mockCustomerFactory();
        $token = $this->mockSecurityToken();
        $context = $this->mockSecurityContext();

        $context
            ->expects($this->once())
            ->method('getToken')
            ->willReturn($token);

        $token
            ->expects($this->atLeastOnce())
            ->method('getUser')
            ->willReturn($customer);

        $factory
            ->expects($this->never())
            ->method('create');

        $wrapper = new CustomerWrapper($factory, $context);
        $actual = $wrapper->loadCustomer();

        $this->assertSame($customer, $actual);
    }

    /**
     *
     */
    public function testCreateCustomerWhenTokenIsEmpty()
    {
        $customer = $this->mockCustomer();
        $factory = $this->mockCustomerFactory();
        $token = $this->mockSecurityToken();
        $context = $this->mockSecurityContext();

        $context
            ->expects($this->once())
            ->method('getToken')
            ->willReturn($token);

        $token
            ->expects($this->atLeastOnce())
            ->method('getUser')
            ->willReturn(null);

        $factory
            ->expects($this->once())
            ->method('create')
            ->willReturn($customer);

        $wrapper = new CustomerWrapper($factory, $context);
        $actual = $wrapper->loadCustomer();

        $this->assertSame($customer, $actual);
    }

    /**
     *
     */
    public function testCreateCustomerWhenNoSecurityContext()
    {
        $customer = $this->mockCustomer();
        $factory = $this->mockCustomerFactory();
<commit_msg>add behat-like scenario phpdocs to test<commit_after><?php

/*
 * This file is part of the Elcodi package.
 *
 * Copyright (c) 2014 Elcodi.com
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * Feel free to edit as you please, and have fun.
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */

namespace Elcodi\Component\User\Tests\UnitTests\Wrapper;

use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\SecurityContextInterface;

use Elcodi\Component\User\Entity\Interfaces\CustomerInterface;
use Elcodi\Component\User\Factory\CustomerFactory;
use Elcodi\Component\User\Wrapper\CustomerWrapper;

/**
 * Class CustomerWrapperTest
 *
 * @author <NAME> <<EMAIL>>
 */
class CustomerWrapperTest extends \PHPUnit_Framework_TestCase
{
    /**
     * Given a security token pointing to a valid customer C
     * When  I ask the wrapper to load a customer
     * Then  it returns C
     */
    public function testLoadCustomerFromToken()
    {
        $customer = $this->mockCustomer();
        $factory = $this->mockCustomerFactory();
        $token = $this->mockSecurityToken();
        $context = $this->mockSecurityContext();

        $context
            ->expects($this->once())
            ->method('getToken')
            ->willReturn($token);

        $token
            ->expects($this->atLeastOnce())
            ->method('getUser')
            ->willReturn($customer);

        $factory
            ->expects($this->never())
            ->method('create');

        $wrapper = new CustomerWrapper($factory, $context);
        $actual = $wrapper->loadCustomer();

        $this->assertSame($customer, $actual);
    }

    /**
     * Given a security token with no user
     *   and a customer factory F
     * When  I ask the wrapper to load a customer
     * Then  it calls F to create a new customer C
     *  and  it returns C
     */
    public function testCreateCustomerWhenTokenIsEmpty()
    {
        $customer = $this->mockCustomer();
        $factory = $this->mockCustomerFactory();
        $token = $this->mockSecurityToken();
        $context = $this->mockSecurityContext();

        $context
            ->expects($this->once())
            ->method('getToken')
            ->willReturn($token);

        $token
            ->expects($this->atLeastOnce())
            ->method('getUser')
            ->willReturn(null);

        $factory
            ->expects($this->once())
            ->method('create')
            ->willReturn($customer);

        $wrapper = new CustomerWrapper($factory, $context);
        $actual = $wrapper->loadCustomer();

        $this->assertSame($customer, $actual);
    }

    /**
     * Given there are no security token
     *   and a customer factory F
     * When  I ask the wrapper to load a customer
     * Then  it calls F to create a new customer C
     *  and  it returns C
     */
    public function testCreateCustomerWhenNoSecurityContext()
    {
        $customer = $this->mockCustomer();
        $factory = $this->mockCustomerFactory();

{'fraction_non_alphanumeric': 0.13334492350486787, 'fraction_numerical': 0.0013908205841446453, 'mean_word_length': 2.4346268656716417, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 95, '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': '5045948', 'n_tokens_mistral': 1565, 'n_tokens_neox': 1533, 'n_words': 371}