<commit_before><?php

namespace ElvoTest\Mvc\Authentication;

use Elvo\Mvc\Authentication\IdentityFactory;


class IdentityFactoryTest extends \PHPUnit_Framework_TestCase
{

    protected $factory;


    public function setUp()
    {
        $this->factory = new IdentityFactory();
    }


    public function testCreateIdentityWithoutUniqueId()
    {
        $this->setExpectedException('Elvo\Mvc\Authentication\Exception\MissingUniqueIdException');
        
        $this->factory->createIdentity(array(
            'foo' => 'bar'
        ));
    }


    public function testCreateIdentityWithEmptyUniqueId()
    {
        $this->setExpectedException('Elvo\Mvc\Authentication\Exception\MissingUniqueIdException');
        
        $this->factory->createIdentity(array(
            'voter_id' => ''
        ));
    }


    public function testCreateIdentityWithMissingRole()
    {
        $this->setExpectedException('Elvo\Mvc\Authentication\Exception\MissingRoleException');
        
        $this->factory->createIdentity(array(
            'voter_id' => '123'
        ));
    }


    /**
     * @dataProvider createIdentityProvider
     */
    public function testDecodeRoles($encodedRoles, $decodedRoles)
    {
        $this->assertEquals($decodedRoles, $this->factory->decodeRoles($encodedRoles));
    }


    public function testCreateIdentity()
    {
        $id = 'abc';
        $encodedRoles = 4;
        $expectedRoles = array(
            'academic'
        );
        
        $identity = $this->factory->createIdentity(array(
            'voter_id' => $id,
            'voter_roles' => $encodedRoles
        ));
        
        $this->assertInstanceOf('Elvo\Mvc\Authentication\Identity', $identity);
        $this->assertSame($id, $identity->getId());
        $this->assertEquals($expectedRoles, $identity->getRoles());
    }


    public function createIdentityProvider()
    {
        return array(
            array(
                'encodedRoles' => - 1,
                'decodedRoles' => array()
            ),
            array(
                'encodedRoles' => 0,
                'decodedRoles' => array()
            ),
            array(
                'encodedRoles' => 1,
                'decodedRoles' => array(
                    'student'
                )
            ),
            array(
                'encodedRoles' => 2,
                'decodedRoles' => array(
                    'academic'
                )
            ),
            array(
                'encodedRoles' => 3,
                'decodedRoles' => array(
                    'student',
                    'academic'
                )
            ),
            array(
                'encodedRoles' => 4,
                'decodedRoles' => array(
                    'academic'
                )
            ),
            array(
                'encodedRoles' => 5,
                'decodedRoles' => array(
                    'student',
                    'academic'
                )
            ),
            array(
                'encodedRoles' => 6,
                'decodedRoles' => array(
                    'academic'
                )
            ),
            array(
                'encodedRoles' => 7,
                'decodedRoles' => array(
                    'student',
                    'academic'
                )
            )
        );
    }
}
<commit_msg>fixed tests after ZfcShib update<commit_after><?php

namespace ElvoTest\Mvc\Authentication;

use Elvo\Mvc\Authentication\IdentityFactory;
use ZfcShib\Authentication\Identity\Data;


class IdentityFactoryTest extends \PHPUnit_Framework_TestCase
{

    protected $factory;


    public function setUp()
    {
        $this->factory = new IdentityFactory();
    }


    public function testCreateIdentityWithoutUniqueId()
    {
        $this->setExpectedException('Elvo\Mvc\Authentication\Exception\MissingUniqueIdException');
        
        $this->factory->createIdentity($this->getIdentityData(array(
            'foo' => 'bar'
        )));
    }


    public function testCreateIdentityWithEmptyUniqueId()
    {
        $this->setExpectedException('Elvo\Mvc\Authentication\Exception\MissingUniqueIdException');
        
        $this->factory->createIdentity($this->getIdentityData(array(
            'voter_id' => ''
        )));
    }


    public function testCreateIdentityWithMissingRole()
    {
        $this->setExpectedException('Elvo\Mvc\Authentication\Exception\MissingRoleException');
        
        $this->factory->createIdentity($this->getIdentityData(array(
            'voter_id' => '123'
        )));
    }


    /**
     * @dataProvider createIdentityProvider
     */
    public function testDecodeRoles($encodedRoles, $decodedRoles)
    {
        $this->assertEquals($decodedRoles, $this->factory->decodeRoles($encodedRoles));
    }


    public function testCreateIdentity()
    {
        $id = 'abc';
        $encodedRoles = 4;
        $expectedRoles = array(
            'academic'
        );
        
        $identity = $this->factory->createIdentity($this->getIdentityData(array(
            'voter_id' => $id,
            'voter_roles' => $encodedRoles
        )));
        
        $this->assertInstanceOf('Elvo\Mvc\Authentication\Identity', $identity);
        $this->assertSame($id, $identity->getId());
        $this->assertEquals($expectedRoles, $identity->getRoles());
    }


    public function createIdentityProvider()
    {
        return array(
            array(
                'encodedRoles' => - 1,
                'decodedRoles' => array()
            ),
            array(
                'encodedRoles' => 0,
                'decodedRoles' => array()
            ),
            array(
                'encodedRoles' => 1,
                'decodedRoles' => array(
                    'student'
                )
            ),
            array(
                'encodedRoles' => 2,
                'decodedRoles' => array(
                    'academic'
                )
            ),
            array(
                'encodedRoles' => 3,
                'decodedRoles' => array(
                    'student',
                    'academic'
                )
            ),
            array(
                'encodedRoles' => 4,
                'decodedRoles' => array(
                    'academic'
                )
            ),
            array(
                'encodedRoles' => 5,
                'decodedRoles' => array(
                    'student',
                    'academic'
                )
            ),
            array(
                'encodedRoles' => 6,
                'decodedRoles' => array(
                    'academic'
                )
            ),
            array(
                'encodedRoles' => 7,
                'decodedRoles' => array(
                    'student',
                    'academic'
                )
            )
        );
    }


    protected function getIdentityData($userData = array(), $systemData = array())
    {
        return new Data($userData, $systemData);
    }
}

{'fraction_non_alphanumeric': 0.11637748624629708, 'fraction_numerical': 0.003667654112004514, 'mean_word_length': 1.3680694722778892, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 93, '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': '3635612', 'n_tokens_mistral': 1929, 'n_tokens_neox': 1832, 'n_words': 270}