<commit_before><?php

namespace tests\codeception\unit\models;

use app\models\User;
use app\tests\codeception\unit\fixtures\UserFixture;
use Codeception\Util\Stub;
use yii\base\InvalidParamException;
use yii\codeception\TestCase;
use Yii;

class UserTest extends TestCase
{
    /** @var User */
    private $_user = null;

    public function globalFixtures()
    {
        return [
            'user' => UserFixture::className(),
        ];
    }

    public function fixtures()
    {
        return [
            'user' => [
                'class' => UserFixture::className(),
                'dataFile' => '@app/tests/codeception/unit/fixtures/data/userModels.php'
            ]
        ];
    }

    protected function setUp()
    {
        parent::setUp();
        $this->_user = new User;
    }

    /* VALIDATION RULES */

    public function testValidateReturnsFalseIfParametersAreNotSet()
    {
        $this->assertFalse($this->_user->validate());
    }

    public function testValidateReturnsTrueIfParametersAreSet()
    {
        $this->_user->attributes = [
            'username' => 'a valid username',
            'password' => '<PASSWORD>',
            'authkey' => 'a valid authkey'
        ];

        $this->assertTrue($this->_user->validate());
    }

    /* getId() */

    public function testGetIdReturnsTheExpectedId()
    {
        $expectedId = 123;
        $this->_user->id = $expectedId;

        $this->assertEquals($expectedId, $this->_user->getId());
    }

    /* getAuthKey() */
<commit_msg>added BDD style tests using Specify and Verify<commit_after><?php

namespace tests\codeception\unit\models;

use app\models\User;
use app\tests\codeception\unit\fixtures\UserFixture;
use yii\base\InvalidParamException;
use yii\codeception\TestCase;
use Codeception\Specify;
use Yii;

class UserTest extends TestCase
{
    use Specify;

    /** @var User */
    private $_user = null;

    public function globalFixtures()
    {
        return [
            'user' => UserFixture::className(),
        ];
    }

    public function fixtures()
    {
        return [
            'user' => [
                'class' => UserFixture::className(),
                'dataFile' => '@app/tests/codeception/unit/fixtures/data/userModels.php'
            ]
        ];
    }

    protected function setUp()
    {
        parent::setUp();
        $this->_user = new User;
    }

    /* VALIDATION RULES */

    public function testValidationRules()
    {
        $this->specify(
            'user should validate if all attributes are set',
            function () {
                $this->_user->attributes = [
                    'username'=>'valid username',
                    'password'=>'<PASSWORD>',
                    'authkey' =>'valid authkey'
                ];
                verify_that($this->_user->validate());
            }
        );

        $this->specify(
            'user should not validate if no attribute is set',
            function () {
                verify_not($this->_user->validate());
            }
        );

        $this->specify(
            'user with username too long should not validate',
            function () {
                $this->_user->username = 'this is a username longer than 24 characters';

                verify_not($this->_user->validate('username'));
                verify($this->_user->getErrors('username'))->notEmpty();
            }
        );

        $this->specify(
            'user with password too long should not validate',
            function () {
                $this->_user->password = '<PASSWORD> <PASSWORD> this is an password longer than 128 characters this is an password longer than 128 characters';

                verify_not($this->_user->validate('password'));
                verify($this->_user->getErrors('password'))->notEmpty();
            }
        );

        $this->specify(
            'user with authkey too long should not validate',
            function () {
                $this->_user->authkey = 'this is an authkey longer than 255 characters this is an authkey longer than 255 characters this is an authkey longer than 255 characters this is an authkey longer than 255 characters this is an authkey longer than 255 characters this is an authkey longer than 255 characters';

                verify_not($this->_user->validate('authkey'));
                verify($this->_user->getErrors('authkey'))->notEmpty();
            }
        );
    }

    public function testValidateReturnsFalseIfParametersAreNotSet()
    {
        $this->assertFalse($this->_user->validate());
    }

    public function testValidateReturnsTrueIfParametersAreSet()
    {
        $this->_user->attributes = [
            'username' => 'a valid username',
            'password' => '<PASSWORD>',
            'authkey' => 'a valid authkey'
        ];

        $this->assertTrue($this->_user->validate());
    }

    /* getId() */

    public function testGetIdReturnsTheExpectedId()
    {
        $expectedId = 123;
        $this->_user->id = $expectedId;

        $this->assertEquals($expectedId, $this->_user->getId());
    }

    /* getAuthKey() */

{'fraction_non_alphanumeric': 0.12920147658830386, 'fraction_numerical': 0.006217213911016126, 'mean_word_length': 1.986078886310905, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 85, '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': '2886053', 'n_tokens_mistral': 1419, 'n_tokens_neox': 1350, 'n_words': 311}