<?php

namespace Buckhill\RFC6238\tests\units;

require('vendor/autoload.php');

use Base32\Base32;
use mageekguy\atoum;
use Buckhill\RFC6238\OTP as Authenticator;

class OTP extends atoum
{
    public function testValidOTP()
    {
        $this
            ->given($auth = $this->getAuthenticator())
            ->then
                ->integer(855783)->isEqualTo($auth->at(1))
                ->integer(540149)->isEqualTo($auth->at(1388534401)) // 1.1.2014 @ 00:00:01
        ;
    }

    public function testVerifyOTP()
    {
        $this
            ->given($auth = $this->getAuthenticator())
            ->then
                ->boolean($auth->verify(540149, 1388534401))
            ;
    }

    protected function getAuthenticator()
    {
        $totp = new Authenticator();

        $totp->setSecret('JDDK4U6G3BJLEZ7Y');

        $totp->setConversionMethod(function($secret)
        {
            return Base32::decode($secret);
        });

        return $totp;
    }
}