<commit_before><?php

use Berg\LdapAuthenticator\Authenticator;
use \Mockery as m;

class AuthenticatorTest extends PHPUnit_Framework_TestCase {

    public function testInvalidCredentials()
    {
        $this->setExpectedException('Berg\LdapAuthenticator\Exceptions\InvalidCredentialsException');
        $driver = m::mock('Berg\LdapAuthenticator\Driver\LdapDriver');
        $driver->shouldReceive('validate')->andReturn(false);
        $authenticator = new Authenticator($driver);
        $authenticator->authenticate('username', 'password');
    }

    public function testUserDoesNotExist()
    {
        $this->setExpectedException('Berg\LdapAuthenticator\Exceptions\UserDoesNotExistException');
        $driver = m::mock('Berg\LdapAuthenticator\Driver\LdapDriver');
        $driver->shouldReceive('validate')->andReturn(true);
        $driver->shouldReceive('doesUserExist')->andReturn(false);
        $authenticator = new Authenticator($driver);
        $authenticator->authenticate('username', 'password');
    }

    public function testAuthenticationFails()
    {
        $this->setExpectedException('Berg\LdapAuthenticator\Exceptions\IncorrectCredentialsException');
        $driver = m::mock('Berg\LdapAuthenticator\Driver\LdapDriver');
        $driver->shouldReceive('validate')->andReturn(true);
        $driver->shouldReceive('doesUserExist')->andReturn(true);
        $driver->shouldReceive('authenticate')->andReturn(false);
        $authenticator = new Authenticator($driver);
        $authenticator->authenticate('username', 'password');
    }<commit_msg>Added tests for required config.<commit_after><?php

use Berg\LdapAuthenticator\Authenticator;
use Berg\LdapAuthenticator\Driver\LdapDriver;
use \Mockery as m;

class AuthenticatorTest extends PHPUnit_Framework_TestCase
{
    public function testInvalidConfiguration()
    {
        $this->setExpectedException('Berg\LdapAuthenticator\Exceptions\ConfigNotSetException');
        new LdapDriver(null);
    }

    public function testInvalidCredentials()
    {
        $this->setExpectedException('Berg\LdapAuthenticator\Exceptions\InvalidCredentialsException');
        $driver = m::mock('Berg\LdapAuthenticator\Driver\LdapDriver');
        $driver->shouldReceive('validate')->andReturn(false);
        $authenticator = new Authenticator($driver);
        $authenticator->authenticate('username', 'password');
    }

    public function testUserDoesNotExist()
    {
        $this->setExpectedException('Berg\LdapAuthenticator\Exceptions\UserDoesNotExistException');
        $driver = m::mock('Berg\LdapAuthenticator\Driver\LdapDriver');
        $driver->shouldReceive('validate')->andReturn(true);
        $driver->shouldReceive('doesUserExist')->andReturn(false);
        $authenticator = new Authenticator($driver);
        $authenticator->authenticate('username', 'password');
    }

    public function testAuthenticationFails()
    {
        $this->setExpectedException('Berg\LdapAuthenticator\Exceptions\IncorrectCredentialsException');
        $driver = m::mock('Berg\LdapAuthenticator\Driver\LdapDriver');
        $driver->shouldReceive('validate')->andReturn(true);
        $driver->shouldReceive('doesUserExist')->andReturn(true);
        $driver->shouldReceive('authenticate')->andReturn(false);
        $authenticator = new Authenticator($driver);
        $authenticator->authenticate('username', 'password');
    }
{'fraction_non_alphanumeric': 0.13315696649029982, 'fraction_numerical': 0.0, 'mean_word_length': 4.462279293739968, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 40, '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': '4794837', 'n_tokens_mistral': 953, 'n_tokens_neox': 945, 'n_words': 112}