<commit_before><?php declare(strict_types=1);

namespace CodeCollabTest\Unit\CsrfToken;

use CodeCollab\CsrfToken\Storage\Storage;
use CodeCollab\CsrfToken\Generator\Generator;
use CodeCollab\CsrfToken\Handler;

class HandlerTest extends \PHPUnit_Framework_TestCase// implements Token
{
    /**
     * @covers CodeCollab\CsrfToken\Token::__construct
     */
    public function testImplementsCorrectInterface()
    {
        $storage = (new class implements Storage {
            public function exists(string $key): bool {}

            public function get(string $key): string {}

            public function set(string $key, string $token) {}
        });

        $generator = (new class implements Generator {
            public function generate(): string {}
        });

        $this->assertInstanceOf('CodeCollab\CsrfToken\Token', new Handler($storage, $generator));
    }

    /**
     * @covers CodeCollab\CsrfToken\Token::__construct
     * @covers CodeCollab\CsrfToken\Token::get
     */
    public function testGetAlreadyExists()
    {
        $storage = (new class implements Storage {
            public function exists(string $key): bool {
                return true;
            }

            public function get(string $key): string {
                return $key;
            }

            public function set(string $key, string $token) {}
        });

        $generator = (new class implements Generator {
            public function generate(): string {}
        });

        $this->assertSame('csrfToken', (new Handler($storage, $generator))->get());
    }

    /**
     * @covers CodeCollab\CsrfToken\Token::__construct
     * @covers CodeCollab\CsrfToken\Token::generate
     * @covers CodeCollab\CsrfToken\Token::get
     */
    public function testGetBeingGenerated()
    {
        $storage = (new class implements Storage {
            public function exists(string $key): bool {
                return false;
            }

            public function get(string $key): string {
                return $key;
            }

            public function set(string $key, string $token) {
                \PHPUnit_Framework_Assert::assertSame('csrfToken', $key);
                \PHPUnit_Framework_Assert::assertSame('generatedtoken', $token);
            }
        });

        $generator = (new class implements Generator {
            public function generate(): string {
                return 'generatedtoken';
            }
        });

        $this->assertSame('csrfToken', (new Handler($storage, $generator))->get());
    }

    /**
     * @covers CodeCollab\CsrfToken\Token::__construct
     * @covers CodeCollab\CsrfToken\Token::isValid
     */
    public function testIsValidNotValid()
    {
        $storage = (new class implements Storage {
            public function exists(string $key): bool {
                return true;
            }

            public function get(string $key): string {
                return $key;
            }

            public function set(string $key, string $token) {}
        });

        $generator = (new class implements Generator {
            public function generate(): string {}
        });

        $this->assertFalse((new Handler($storage, $generator))->isValid('not valid'));
    }

    /**
     * @covers CodeCollab\CsrfToken\Token::__construct
     * @covers CodeCollab\CsrfToken\Token::isValid
     */
    public function testIsValidValid()
    {
        $storage = (new class implements Storage {
            public function exists(string $key): bool {
                return true;
            }

            public function get(string $key): string {
                return $key;
            }

            public function set(string $key, string $token) {}
        });

        $generator = (new class implements Generator {
            public function generate(): string {}
        });

        $this->assertTrue((new Handler($storage, $generator))->isValid('csrfToken'));
    }
}<commit_msg>Unfuckify tests<commit_after><?php declare(strict_types=1);

namespace CodeCollabTest\Unit\CsrfToken;

use CodeCollab\CsrfToken\Handler;

class HandlerTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @covers CodeCollab\CsrfToken\Token::__construct
     */
    public function testImplementsCorrectInterface()
    {
        $storage = $this->getMock('CodeCollab\CsrfToken\Storage\Storage');

        $generator = $this->getMock('CodeCollab\CsrfToken\Generator\Generator');

        $this->assertInstanceOf('CodeCollab\CsrfToken\Token', new Handler($storage, $generator));
    }

    /**
     * @covers CodeCollab\CsrfToken\Token::__construct
     * @covers CodeCollab\CsrfToken\Token::get
     */
    public function testGetAlreadyExists()
    {
        $storage = $this->getMock('CodeCollab\CsrfToken\Storage\Storage');

        $storage
            ->expects($this->once())
            ->method('exists')
            ->with($this->equalTo('csrfToken'))
            ->willReturn(true)
        ;

        $storage
            ->expects($this->once())
            ->method('get')
            ->with($this->equalTo('csrfToken'))
            ->willReturn('TheToken')
        ;

        $generator = $this->getMock('CodeCollab\CsrfToken\Generator\Generator');

        $this->assertSame('TheToken', (new Handler($storage, $generator))->get());
    }

    /**
     * @covers CodeCollab\CsrfToken\Token::__construct
     * @covers CodeCollab\CsrfToken\Token::generate
     * @covers CodeCollab\CsrfToken\Token::get
     */
    public function testGetBeingGenerated()
    {
        $storage = $this->getMock('CodeCollab\CsrfToken\Storage\Storage');

        $storage
            ->expects($this->once())
            ->method('exists')
            ->with($this->equalTo('csrfToken'))
            ->willReturn(false)
        ;

        $storage
            ->expects($this->once())
            ->method('set')
            ->with($this->equalTo('csrfToken'), $this->equalTo('generatedtoken'))
            ->willReturn('TheToken')
        ;

        $storage
            ->expects($this->once())
            ->method('get')
            ->with($this->equalTo('csrfToken'))
            ->willReturn('TheToken')
        ;

        $generator = $this->getMock('CodeCollab\CsrfToken\Generator\Generator');

        $generator
            ->expects($this->once())
            ->method('generate')
            ->willReturn('generatedtoken')
        ;

        $this->assertSame('TheToken', (new Handler($storage, $generator))->get());
    }

    /**
     * @covers CodeCollab\CsrfToken\Token::__construct
     * @covers CodeCollab\CsrfToken\Token::isValid
     */
    public function testIsValidNotValid()
    {
        $storage = $this->getMock('CodeCollab\CsrfToken\Storage\Storage');

        $storage
            ->expects($this->once())
            ->method('exists')
            ->with($this->equalTo('csrfToken'))
            ->willReturn(true)
        ;

        $storage
            ->expects($this->once())
            ->method('get')
            ->with($this->equalTo('csrfToken'))
            ->willReturn('TheToken')
        ;

        $generator = $this->getMock('CodeCollab\CsrfToken\Generator\Generator');

        $this->assertFalse((new Handler($storage, $generator))->isValid('not valid'));
    }

    /**
     * @covers CodeCollab\CsrfToken\Token::__construct
     * @covers CodeCollab\CsrfToken\Token::isValid
     */
    public function testIsValidValid()
    {
        $storage = $this->getMock('CodeCollab\CsrfToken\Storage\Storage');

        $storage
            ->expects($this->once())
            ->method('exists')
            ->with($this->equalTo('csrfToken'))
            ->willReturn(true)
        ;

        $storage
            ->expects($this->once())
            ->method('get')
            ->with($this->equalTo('csrfToken'))
            ->willReturn('TheToken')
        ;

        $generator = $this->getMock('CodeCollab\CsrfToken\Generator\Generator');

        $this->assertTrue((new Handler($storage, $generator))->isValid('TheToken'));
    }
}
{'fraction_non_alphanumeric': 0.13989830088056554, 'fraction_numerical': 0.00024804663276696017, 'mean_word_length': 2.138964577656676, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 90, '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': '741878', 'n_tokens_mistral': 2263, 'n_tokens_neox': 2158, 'n_words': 377}