<commit_before><?php

namespace bizley\podium\api\tests;

use bizley\podium\api\repositories\Member as MemberRepo;
use bizley\podium\api\repositories\RepoNotFoundException;
use yii\db\Query;

class MemberRepoTest extends TestCase
{
    /**
     * @param bool $clear
     * @return MemberRepo|bool
     */
    protected function repo($clear = false)
    {
        return $this->podium()->member->getRepo('member', $clear);
    }

    protected function tableName()
    {
        return MemberRepo::tableName();
    }

    public function testAddingRepoErroneous()
    {
        $this->assertFalse($this->repo(true)->store(['username' => null]));
        $this->assertNotEmpty($this->repo()->errors);
    }

    public function testAddingRepoSuccessful()
    {
        $this->assertTrue($this->repo(true)->store(['username' => 'test']));
        $this->assertEmpty($this->repo()->errors);

        $repo = (new Query())->select(['username', 'slug', 'status'])->from($this->tableName())->where(['username' => 'test'])->one(static::$db);
        $this->assertEquals([
            'username' => 'test',
            'slug' => 'test',
            'status' => '0',
        ], $repo);
    }

    public function testAddingRepoDuplicate()
    {
        $this->assertTrue($this->repo(true)->store(['username' => 'test2']));
        $this->assertFalse($this->repo(true)->store(['username' => 'test2']));
        $this->assertNotEmpty($this->repo()->errors);
    }

    public function testRepoMissing()
    {
        $this->expectException(RepoNotFoundException::class);
        $this->assertFalse($this->repo(true)->fetch(-1));
    }

    public function testUpdatingRepoErroneous()
    {
        $repo = $this->repo(true);
        $repo->store(['username' => 'test3']);
        $repoId = (new Query())->select($repo::primaryKey())->from($this->tableName())->where(['username' => 'test3'])->scalar(static::$db);

        $this->assertEquals(0, $repo->fetch($repoId)->store(['username' => null]));
        $this->assertNotEmpty($repo->errors);
    }

    public function testUpdatingRepoSuccessful()
    {
        $repo = $this->repo(true);
        $repo->store(['username' => 'test4']);
        $repoId = (new Query())->select($repo::primaryKey())->from($this->tableName())->where(['username' => 'test4'])->scalar(static::$db);

        $this->assertEquals(1, $this->repo()->fetch($repoId)->store(['username' => 'testUpdated']));
        $this->assertEmpty($this->repo()->errors);

        $repoTest = (new Query())->select(['username', 'slug', 'status'])->from($this->tableName())->where(['username' => 'testUpdated'])->one(static::$db);
        $this->assertEquals([
            'username' => 'testUpdated',
            'slug' => 'testupdated',
            'status' => '0',
        ], $repoTest);
    }

    public function testCheckingRepoExists()
    {
        $repo = $this->repo(true);
        $repo->store(['username' => 'test5']);

        $this->assertTrue($repo->check(['id' => $repo->id]));
    }

    public function testDeletingRepoSuccessful()
    {
        $repo = $this->repo(true);
        $repo->store(['username' => 'test6']);
        $repoId = (new Query())->select($repo::primaryKey())->from($this->tableName())->where(['username' => 'test6'])->scalar(static::$db);

        $this->assertEquals(1, $this->repo()->fetch($repoId)->remove());
    }
}<commit_msg>tests<commit_after><?php

namespace bizley\podium\api\tests;

use bizley\podium\api\repositories\Member as MemberRepo;
use bizley\podium\api\repositories\RepoNotFoundException;
use yii\db\Query;

class MemberRepoTest extends TestCase
{
    /**
     * @param bool $clear
     * @return MemberRepo|bool
     */
    protected function repo($clear = false)
    {
        return $this->podium()->member->getRepo('member', $clear);
    }

    protected function tableName()
    {
        return MemberRepo::tableName();
    }

    public function testAddingRepoErroneous()
    {
        $this->assertFalse($this->repo(true)->store(['username' => null]));
        $this->assertNotEmpty($this->repo()->errors);
    }

    public function testAddingRepoSuccessful()
    {
        $this->assertTrue($this->repo(true)->store(['username' => 'test']));
        $this->assertEmpty($this->repo()->errors);

        $repo = (new Query())->select(['username', 'slug', 'status'])->from($this->tableName())->where(['username' => 'test'])->one(static::$db);
        $this->assertEquals([
            'username' => 'test',
            'slug' => 'test',
            'status' => '0',
        ], $repo);
    }

    public function testAddingRepoDuplicate()
    {
        $this->assertTrue($this->repo(true)->store(['username' => 'test2']));
        $this->assertFalse($this->repo(true)->store(['username' => 'test2']));
        $this->assertNotEmpty($this->repo()->errors);
    }

    public function testRepoMissing()
    {
        $this->expectException(RepoNotFoundException::class);
        $this->assertFalse($this->repo(true)->fetch(-1));
    }

    public function testUpdatingRepoErroneous()
    {
        $repo = $this->repo(true);
        $repo->store(['username' => 'test3']);
        $repoId = $repo->id;

        $this->assertEquals(0, $repo->fetch($repoId)->store(['username' => null]));
        $this->assertNotEmpty($repo->errors);

        $repoTest = (new Query())->select('username')->from($this->tableName())->where(['username' => 'test3'])->one(static::$db);
        $this->assertEquals(['username' => 'test3'], $repoTest);
    }

    public function testUpdatingRepoSuccessful()
    {
        $repo = $this->repo(true);
        $repo->store(['username' => 'test4']);
        $repoId = $repo->id;

        $this->assertEquals(1, $this->repo(true)->fetch($repoId)->store(['username' => 'testUpdated']));
        $this->assertEmpty($this->repo()->errors);

        $repoTest = (new Query())->select(['username', 'slug', 'status'])->from($this->tableName())->where(['username' => 'testUpdated'])->one(static::$db);
        $this->assertEquals([
            'username' => 'testUpdated',
            'slug' => 'testupdated',
            'status' => '0',
        ], $repoTest);
        $repoGone = (new Query())->select(['username', 'slug', 'status'])->from($this->tableName())->where(['username' => 'test4'])->one(static::$db);
        $this->assertEmpty($repoGone);
    }

    public function testCheckingRepoExists()
    {
        $repo = $this->repo(true);
        $repo->store(['username' => 'test5']);

        $this->assertTrue($repo->check(['id' => $repo->id]));
    }

    public function testCheckingRepoNonExists()
    {
        $repo = $this->repo(true);
        $this->assertFalse($repo->check(['id' => -1]));
    }

    public function testDeletingRepoSuccessful()
    {
        $repo = $this->repo(true);
        $repo->store(['username' => 'test6']);
        $repoId = $repo->id;

        $this->assertEquals(1, $this->repo(true)->fetch($repoId)->remove());
    }
}
{'fraction_non_alphanumeric': 0.21913268981414782, 'fraction_numerical': 0.004466215242760409, 'mean_word_length': 3.137067938021454, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 215, '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': '5253222', 'n_tokens_mistral': 2088, 'n_tokens_neox': 2105, 'n_words': 289}