<commit_before><?php
declare(strict_types = 1);
/**
 * /tests/AppBundle/integration/Entity/UserTest.php
 *
 * @author  TLe, <NAME> <<EMAIL>>
 */
namespace AppBundle\integration\Entity;

use App\Entity\User;
use App\Tests\EntityTestCase;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * Class UserTest
 *
 * @package AppBundle\integration\Entity
 * @author  TLe, <NAME> <<EMAIL>>
 */
class UserTest extends EntityTestCase
{
    /**
     * @var User
     */
    protected $entity;

    /**
     * @var string
     */
    protected $entityName = User::class;

    /**
     * @dataProvider dataProviderTestThatPasswordHashingIsWorkingAsExpected
     *
     * @param   callable    $callable
     * @param   string      $password
     * @param   string      $expected
     */
    public function testThatPasswordHashingIsWorkingAsExpected(callable $callable, string $password, string $expected)
    {
        $this->entity->setPassword($callable, $password);

        static::assertSame($expected, $this->entity->getPassword());
    }

    public function testThatSetPlainPasswordIsWorkingAsExpected()
    {
        // First set new password
        $this->entity->setPassword('<PASSWORD>', 'password');

        // Set plain password
        $this->entity->setPlainPassword('<PASSWORD>');

        static::assertEmpty($this->entity->getPassword());
        static::assertSame('plainPassword', $this->entity->getPlainPassword());
    }

    public function testThatSetEmptyPlainPasswordDoesNotResetPassword()
    {
        // First set new password
        $this->entity->setPassword('<PASSWORD>', 'password');

        // Set plain password
        $this->entity->setPlainPassword('');

        static::assertNotEmpty($this->entity->getPassword());
        static::assertEmpty($this->entity->getPlainPassword());
    }

    public function testThatUserEntityCanBeSerializedAndUnSerializedAsExpected()
    {
        // First set some data for entity
        $this->entity->setUsername('john');
        $this->entity->setPassword('<PASSWORD>', 'password');

        /** @var User $entity */
        $entity = \unserialize(\serialize($this->entity), ['allowed_classes' => \stdClass::class]);

        // Assert that unserialized object returns expected data

        static::assertSame('john', $entity->getUsername());
        static::assertSame('<PASSWORD>', $entity->getPassword());
    }

    public function testThatGetUserGroupsReturnsInstanceOfArrayCollection()
    {
        static::assertInstanceOf(ArrayCollection::class, $this->entity->getUserGroups());
    }

    public function testThatGetRolesReturnsAnArray()
    {
        static::assertInternalType('array', $this->entity->getRoles());<commit_msg>test: Fix for PHP 7.1<commit_after><?php
declare(strict_types = 1);
/**
 * /tests/AppBundle/integration/Entity/UserTest.php
 *
 * @author  TLe, <NAME> <<EMAIL>>
 */
namespace AppBundle\integration\Entity;

use App\Entity\User;
use App\Tests\EntityTestCase;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * Class UserTest
 *
 * @package AppBundle\integration\Entity
 * @author  TLe, <NAME> <<EMAIL>>
 */
class UserTest extends EntityTestCase
{
    /**
     * @var User
     */
    protected $entity;

    /**
     * @var string
     */
    protected $entityName = User::class;

    /**
     * @dataProvider dataProviderTestThatPasswordHashingIsWorkingAsExpected
     *
     * @param   callable    $callable
     * @param   string      $password
     * @param   string      $expected
     */
    public function testThatPasswordHashingIsWorkingAsExpected(callable $callable, string $password, string $expected)
    {
        $this->entity->setPassword($callable, $password);

        static::assertSame($expected, $this->entity->getPassword());
    }

    public function testThatSetPlainPasswordIsWorkingAsExpected()
    {
        // First set new password
        $this->entity->setPassword('<PASSWORD>', 'password');

        // Set plain password
        $this->entity->setPlainPassword('<PASSWORD>');

        static::assertEmpty($this->entity->getPassword());
        static::assertSame('plainPassword', $this->entity->getPlainPassword());
    }

    public function testThatSetEmptyPlainPasswordDoesNotResetPassword()
    {
        // First set new password
        $this->entity->setPassword('<PASSWORD>', 'password');

        // Set plain password
        $this->entity->setPlainPassword('');

        static::assertNotEmpty($this->entity->getPassword());
        static::assertEmpty($this->entity->getPlainPassword());
    }

    public function testThatUserEntityCanBeSerializedAndUnSerializedAsExpected()
    {
        // First set some data for entity
        $this->entity->setUsername('john');
        $this->entity->setPassword('<PASSWORD>', 'password');

        /** @var User $entity */
        $entity = \unserialize(\serialize($this->entity), ['allowed_classes' => [\stdClass::class]]);

        // Assert that unserialized object returns expected data

        static::assertSame('john', $entity->getUsername());
        static::assertSame('<PASSWORD>', $entity->getPassword());
    }

    public function testThatGetUserGroupsReturnsInstanceOfArrayCollection()
    {
        static::assertInstanceOf(ArrayCollection::class, $this->entity->getUserGroups());
    }

    public function testThatGetRolesReturnsAnArray()
    {
        static::assertInternalType('array', $this->entity->getRoles());
{'fraction_non_alphanumeric': 0.14164827078734363, 'fraction_numerical': 0.0007358351729212656, 'mean_word_length': 3.2946287519747237, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 89, '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': '2005185', 'n_tokens_mistral': 1500, 'n_tokens_neox': 1458, 'n_words': 265}