<commit_before><?php

/**
 * Linna Framework.
 *
 * @author <NAME> <<EMAIL>>
 * @copyright (c) 2017, <NAME>
 * @license http://opensource.org/licenses/MIT MIT License
 */
declare(strict_types=1);

use PHPUnit\Framework\TestCase;

class UserTest extends TestCase
{
    public function testTemp()
    {
        $this->assertEquals(true, true);<commit_msg>setPassword and changePassword tests added<commit_after><?php

/**
 * Linna Framework.
 *
 * @author <NAME> <<EMAIL>>
 * @copyright (c) 2017, <NAME>
 * @license http://opensource.org/licenses/MIT MIT License
 */
declare(strict_types=1);

use Linna\Auth\Password;
use Linna\Auth\User;
use Linna\Foo\Mappers\UserMapper;
use Linna\Storage\StorageFactory;
use PHPUnit\Framework\TestCase;

class UserTest extends TestCase
{
    protected $userMapper;

    public function setUp()
    {
        $options = [
            'dsn'      => $GLOBALS['pdo_mysql_dsn'],
            'user'     => $GLOBALS['pdo_mysql_user'],
            'password' => $GLOBALS['pdo_mysql_password'],
            'options'  => [PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ, PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING],
        ];

        $pdo = (new StorageFactory())->createConnection('mysqlpdo', $options);
        
        $password = new Password();
        
        $this->userMapper = new UserMapper($pdo, $password);
    }
    
    public function testCreateUser()
    {
        $user = $this->userMapper->create();
        
        $this->assertInstanceOf(User::class, $user);
    }
    
    public function testSetPassword()
    {
        $user = $this->userMapper->create();
        
        $user->setPassword('password');
        
        $this->assertInstanceOf(User::class, $user);
        $this->assertEquals(true, password_verify('password', $user->password));
        
    }
    
    public function testChangePassword()
    {
        $user = $this->userMapper->create();
        
        $user->setPassword('password');
        
        $this->assertInstanceOf(User::class, $user);
        $this->assertEquals(true, $user->chagePassword('new_password', 'password'));
        $this->assertEquals(true, $user->chagePassword('other_new_password', '<PASSWORD>'));
        $this->assertEquals(false, $user->chagePassword('password', '<PASSWORD>'));
{'fraction_non_alphanumeric': 0.15731814198071867, 'fraction_numerical': 0.0043821209465381246, 'mean_word_length': 2.9635416666666665, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 41, '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': '3914717', 'n_tokens_mistral': 705, 'n_tokens_neox': 687, 'n_words': 121}