<commit_before><?php

namespace fphammerle\yii2\auth\clientcert\tests;

use \fphammerle\helpers\ArrayHelper;
use \fphammerle\yii2\auth\clientcert\Authenticator;

class ClientCertAuthTest extends \PHPUnit_Framework_TestCase
{
    public function mockApplication()
    {
        $app = new \yii\web\Application([
            'id' => 'yii2-client-cert-auth-test',
            'basePath' => __DIR__,
            // 'vendorPath' => dirname(__DIR__) . '/vendor',
            'components' => [
                'db' => [
                    'class' => '\yii\db\Connection',
                    'dsn' => 'sqlite::memory:',
                ],
                'user' => [
                    'identityClass' => models\User::className(),
                ],
            ],
        ]);
        $this->assertEquals([], $app->db->getSchema()->getTableNames());
        (new migrations\CreateUserTable)->up();
        $this->assertNull($app->user->getIdentity());
        return $app;
    }

    public function testCreateUser()
    {
        $app = $this->mockApplication();
        (new models\User('a'))->save();
        (new models\User('b'))->save();
        $users = ArrayHelper::map(
            models\User::find()->all(),
            function($u) { return $u->getAttributes(); }
        );
        $this->assertEquals(2, sizeof($users));
        $this->assertContains(['id' => 1, 'username' => 'a'], $users);
        $this->assertContains(['id' => 2, 'username' => 'b'], $users);
    }
}<commit_msg>test login & logout<commit_after><?php

namespace fphammerle\yii2\auth\clientcert\tests;

use \fphammerle\helpers\ArrayHelper;
use \fphammerle\yii2\auth\clientcert\Authenticator;

class ClientCertAuthTest extends \PHPUnit_Framework_TestCase
{
    public function mockApplication()
    {
        $app = new \yii\web\Application([
            'id' => 'yii2-client-cert-auth-test',
            'basePath' => __DIR__,
            // 'vendorPath' => dirname(__DIR__) . '/vendor',
            'components' => [
                'db' => [
                    'class' => '\yii\db\Connection',
                    'dsn' => 'sqlite::memory:',
                ],
                'user' => [
                    'identityClass' => models\User::className(),
                ],
            ],
        ]);
        $this->assertEquals([], $app->db->getSchema()->getTableNames());
        (new migrations\CreateUserTable)->up();
        $this->assertNull($app->user->getIdentity());
        return $app;
    }

    public function testCreateUser()
    {
        $app = $this->mockApplication();
        (new models\User('a'))->save();
        (new models\User('b'))->save();
        $users = ArrayHelper::map(
            models\User::find()->all(),
            function($u) { return $u->getAttributes(); }
        );
        $this->assertEquals(2, sizeof($users));
        $this->assertContains(['id' => 1, 'username' => 'a'], $users);
        $this->assertContains(['id' => 2, 'username' => 'b'], $users);
    }

    public function testLoginLogout()
    {
        $app = $this->mockApplication();
        $alice = new models\User('alice');
        $alice->save();
        $this->assertTrue($app->user->login($alice));
        $this->assertSame($alice, $app->user->identity);
        $app->user->logout();
        $this->assertNull($app->user->identity);
    }
}
{'fraction_non_alphanumeric': 0.1872939766257117, 'fraction_numerical': 0.003596044351213665, 'mean_word_length': 2.0428441203281675, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 74, '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': '1430223', 'n_tokens_mistral': 998, 'n_tokens_neox': 980, 'n_words': 150}