PHP Classes

File: tests/TimeLockCryptTest.php

Recommend this page to a friend!
  Classes of Lukas Mestan  >  Time Lock Crypt  >  tests/TimeLockCryptTest.php  >  Download  
File: tests/TimeLockCryptTest.php
Role: Unit test script
Content type: text/plain
Description: Unit test script
Class: Time Lock Crypt
Encrypt data using key generated for a time period
Author: By
Last change:
Date: 5 years ago
Size: 1,502 bytes
 

Contents

Class file image Download
<?php

use \TimeLockCrypt\TimeLockCrypt;

class
TimeLockCryptTest extends PHPUnit_Framework_TestCase
{

   
/**
     * Test equals generate key by time and generate key by iterations
     *
     * @access public
     */
   
public function testKey()
    {
       
$key = '12345';
       
$timeLock = new TimeLockCrypt($key);

       
$key1 = $this->invokeMethod($timeLock, 'generateByTime', array($key, '+1 seconds'));
       
$key2 = $this->invokeMethod($timeLock, 'generateByIterations', array($key, $timeLock->getIterations()));

       
$this->assertEquals($key1, $key2);
    }

   
/**
     * Test equals time lock encrypt and decrypt message
     *
     * @access public
     */
   
public function testMessage()
    {
       
$timeLock = new TimeLockCrypt('123');

       
$message = 'secret message';
       
$encrypted = $timeLock->encrypt('+1 second', $message);

       
$this->assertEquals($message, $timeLock->decrypt($encrypted, $timeLock->getIterations()));
    }

   
/**
     * Call protected/private method of a class.
     *
     * @access public
     * @param object $object
     * @param string $methodName
     * @param array $parameters
     * @return mixed
     */
   
public function invokeMethod(&$object, $methodName, array $parameters = array())
    {
       
$reflection = new ReflectionClass(get_class($object));
       
$method = $reflection->getMethod($methodName);
       
$method->setAccessible(TRUE);

        return
$method->invokeArgs($object, $parameters);
    }

}

For more information send a message to info at phpclasses dot org.