]> git.immae.eu Git - github/wallabag/wallabag.git/blame_incremental - tests/Wallabag/CoreBundle/Helper/CryptoProxyTest.php
Merge pull request #3725 from Tobi823/master
[github/wallabag/wallabag.git] / tests / Wallabag / CoreBundle / Helper / CryptoProxyTest.php
... / ...
CommitLineData
1<?php
2
3namespace Tests\Wallabag\CoreBundle\Helper;
4
5use Monolog\Handler\TestHandler;
6use Monolog\Logger;
7use PHPUnit\Framework\TestCase;
8use Psr\Log\NullLogger;
9use Wallabag\CoreBundle\Helper\CryptoProxy;
10
11class CryptoProxyTest extends TestCase
12{
13 public function testCrypto()
14 {
15 $logHandler = new TestHandler();
16 $logger = new Logger('test', [$logHandler]);
17
18 $crypto = new CryptoProxy(sys_get_temp_dir() . '/' . uniqid('', true) . '.txt', $logger);
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 /**
31 * @expectedException \RuntimeException
32 * @expectedExceptionMessage Decrypt fail
33 *
34 * @return [type] [description]
35 */
36 public function testDecryptBadValue()
37 {
38 $crypto = new CryptoProxy(sys_get_temp_dir() . '/' . uniqid('', true) . '.txt', new NullLogger());
39 $crypto->decrypt('badvalue');
40 }
41}