<?php

namespace buckhill\encrypter;

class EncrypterTest extends \PhpUnit_Framework_TestCase
{
    public function testEncrypt()
    {
        $method = 'aes-256-cbc';
        $secret = openssl_random_pseudo_bytes(32);

        $encrypter = new Encrypter($method, $secret);

        $string = 'Lorem Ipsum Dolor Sit Amet';

        $encrypted = $encrypter->encrypt($string);
        $decrypted = $encrypter->decrypt($encrypted);

        $this->assertEquals($string, $decrypted);
    }

    public function testDecrypt()
    {
        $method = 'aes-256-cbc';
        $secret = openssl_random_pseudo_bytes(32);

        $encrypter = new Encrypter($method, $secret);
        $decrypter = new Encrypter($method, $secret, $encrypter->getIV());

        $text = 'This is text.';

        $this->assertEquals($text, $decrypter->decrypt($encrypter->encrypt($text)));
    }
}