<?php

namespace AuthStack\AuthProfile\tests\units;


use mageekguy\atoum;
use Illuminate\Support\Collection;
use AuthStack\AuthProfile\Model\AuthProfile;
use AuthStack\AuthProfile\ProfileManager as AuthProfileManager;

class ProfileManager extends atoum
{
    public function testCreateProfileManager()
    {
        $this
            ->given($profiles = AuthProfileManager::fromArray($this->getProfileArray(), 'a94a8fe5ccb19ba61c4c0873d391e987982fbbd3'))
            ->then
                ->object($profiles->getCollection())->isInstanceOf(Collection::class)
                ->object($profiles->getActiveProfile())->isInstanceOf(AuthProfile::class)
            ;
    }

    public function testAuthProfileToArray()
    {
        $this
            ->given($profiles = AuthProfileManager::fromArray($this->getProfileArray(), 'a94a8fe5ccb19ba61c4c0873d391e987982fbbd3'))
            ->then
                ->object($active = $profiles->getActiveProfile())->isInstanceOf(AuthProfile::class)
                ->array($active->toArray(function() {
                    return [
                        'app_title' => 'Test app'
                    ];
                }))->hasKey('app_title')

            ;
    }

    protected function getProfileArray()
    {
        return [

            [
                'protocol'          => 'SAML',
                'session_id'        => 'a94a8fe5ccb19ba61c4c0873d391e987982fbbd3',
                'conn_id'           => 2,
                'application_id'    => 1,
                'user_id'           => 9,
                'browser'           => '',
                'ip'                => '10.0.0.60',
                'created_at'        => '2016-08-30 22:22:22'
            ]
        ];
    }
}