wallabag/tests/Wallabag/CoreBundle/Helper/CryptoProxyTest.php

42 lines
1.2 KiB
PHP
Raw Normal View History

2017-06-11 23:05:19 +02:00
<?php
namespace Tests\Wallabag\CoreBundle\Helper;
use Monolog\Handler\TestHandler;
2017-07-01 09:52:38 +02:00
use Monolog\Logger;
2017-12-16 22:17:42 +01:00
use PHPUnit\Framework\TestCase;
2017-07-01 09:52:38 +02:00
use Psr\Log\NullLogger;
2017-06-11 23:05:19 +02:00
use Wallabag\CoreBundle\Helper\CryptoProxy;
2017-12-16 22:17:42 +01:00
class CryptoProxyTest extends TestCase
2017-06-11 23:05:19 +02:00
{
public function testCrypto()
{
$logHandler = new TestHandler();
$logger = new Logger('test', [$logHandler]);
2017-07-01 09:52:38 +02:00
$crypto = new CryptoProxy(sys_get_temp_dir() . '/' . uniqid('', true) . '.txt', $logger);
2017-06-11 23:05:19 +02:00
$crypted = $crypto->crypt('test');
$decrypted = $crypto->decrypt($crypted);
$this->assertSame('test', $decrypted);
$records = $logHandler->getRecords();
$this->assertCount(2, $records);
$this->assertContains('Crypto: crypting value', $records[0]['message']);
$this->assertContains('Crypto: decrypting value', $records[1]['message']);
}
/**
2017-07-01 09:52:38 +02:00
* @expectedException \RuntimeException
2017-06-11 23:05:19 +02:00
* @expectedExceptionMessage Decrypt fail
*
* @return [type] [description]
*/
public function testDecryptBadValue()
{
2017-07-01 09:52:38 +02:00
$crypto = new CryptoProxy(sys_get_temp_dir() . '/' . uniqid('', true) . '.txt', new NullLogger());
2017-06-11 23:05:19 +02:00
$crypto->decrypt('badvalue');
}
}