3 namespace Tests\Wallabag\CoreBundle\Helper
;
5 use Monolog\Handler\TestHandler
;
7 use Psr\Log\NullLogger
;
8 use Wallabag\CoreBundle\Helper\CryptoProxy
;
10 class CryptoProxyTest
extends \PHPUnit_Framework_TestCase
12 public function testCrypto()
14 $logHandler = new TestHandler();
15 $logger = new Logger('test', [$logHandler]);
17 $crypto = new CryptoProxy(sys_get_temp_dir() . '/' . uniqid('', true) . '.txt', $logger);
18 $crypted = $crypto->crypt('test');
19 $decrypted = $crypto->decrypt($crypted);
21 $this->assertSame('test', $decrypted);
23 $records = $logHandler->getRecords();
24 $this->assertCount(2, $records);
25 $this->assertContains('Crypto: crypting value', $records[0]['message']);
26 $this->assertContains('Crypto: decrypting value', $records[1]['message']);
30 * @expectedException \RuntimeException
31 * @expectedExceptionMessage Decrypt fail
33 * @return [type] [description]
35 public function testDecryptBadValue()
37 $crypto = new CryptoProxy(sys_get_temp_dir() . '/' . uniqid('', true) . '.txt', new NullLogger());
38 $crypto->decrypt('badvalue');