]> git.immae.eu Git - github/wallabag/wallabag.git/blame - tests/Wallabag/CoreBundle/Helper/CryptoProxyTest.php
Run php-cs-fixer for fixing coding standard issues (on ContentProxyTest)
[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 6use Monolog\Logger;
bd91bd5c 7use PHPUnit\Framework\TestCase;
f808b016 8use Psr\Log\NullLogger;
906424c1
JB
9use Wallabag\CoreBundle\Helper\CryptoProxy;
10
bd91bd5c 11class CryptoProxyTest extends TestCase
906424c1
JB
12{
13 public function testCrypto()
14 {
15 $logHandler = new TestHandler();
16 $logger = new Logger('test', [$logHandler]);
17
f808b016 18 $crypto = new CryptoProxy(sys_get_temp_dir() . '/' . uniqid('', true) . '.txt', $logger);
906424c1
JB
19 $crypted = $crypto->crypt('test');
20 $decrypted = $crypto->decrypt($crypted);
21
22 $this->assertSame('test', $decrypted);
23
24 $records = $logHandler->getRecords();
25 $this->assertCount(2, $records);
26 $this->assertContains('Crypto: crypting value', $records[0]['message']);
27 $this->assertContains('Crypto: decrypting value', $records[1]['message']);
28 }
29
30 /**
f808b016 31 * @expectedException \RuntimeException
906424c1
JB
32 * @expectedExceptionMessage Decrypt fail
33 *
34 * @return [type] [description]
35 */
36 public function testDecryptBadValue()
37 {
f808b016 38 $crypto = new CryptoProxy(sys_get_temp_dir() . '/' . uniqid('', true) . '.txt', new NullLogger());
906424c1
JB
39 $crypto->decrypt('badvalue');
40 }
41}