]> git.immae.eu Git - github/wallabag/wallabag.git/blame - tests/Wallabag/CoreBundle/Helper/CryptoProxyTest.php
Add a real configuration for CS-Fixer
[github/wallabag/wallabag.git] / tests / Wallabag / CoreBundle / Helper / CryptoProxyTest.php
CommitLineData
906424c1
JB
1<?php
2
3namespace Tests\Wallabag\CoreBundle\Helper;
4
906424c1 5use Monolog\Handler\TestHandler;
f808b016
JB
6use Monolog\Logger;
7use Psr\Log\NullLogger;
906424c1
JB
8use Wallabag\CoreBundle\Helper\CryptoProxy;
9
10class CryptoProxyTest extends \PHPUnit_Framework_TestCase
11{
12 public function testCrypto()
13 {
14 $logHandler = new TestHandler();
15 $logger = new Logger('test', [$logHandler]);
16
f808b016 17 $crypto = new CryptoProxy(sys_get_temp_dir() . '/' . uniqid('', true) . '.txt', $logger);
906424c1
JB
18 $crypted = $crypto->crypt('test');
19 $decrypted = $crypto->decrypt($crypted);
20
21 $this->assertSame('test', $decrypted);
22
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']);
27 }
28
29 /**
f808b016 30 * @expectedException \RuntimeException
906424c1
JB
31 * @expectedExceptionMessage Decrypt fail
32 *
33 * @return [type] [description]
34 */
35 public function testDecryptBadValue()
36 {
f808b016 37 $crypto = new CryptoProxy(sys_get_temp_dir() . '/' . uniqid('', true) . '.txt', new NullLogger());
906424c1
JB
38 $crypto->decrypt('badvalue');
39 }
40}