3 namespace Tests\Wallabag\CoreBundle\Helper
;
5 use Monolog\Handler\TestHandler
;
7 use PHPUnit\Framework\TestCase
;
8 use Psr\Log\NullLogger
;
9 use Wallabag\CoreBundle\Helper\CryptoProxy
;
11 class CryptoProxyTest
extends TestCase
13 public function testCrypto()
15 $logHandler = new TestHandler();
16 $logger = new Logger('test', [$logHandler]);
18 $crypto = new CryptoProxy(sys_get_temp_dir() . '/' . uniqid('', true) . '.txt', $logger);
19 $crypted = $crypto->crypt('test');
20 $decrypted = $crypto->decrypt($crypted);
22 $this->assertSame('test', $decrypted);
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']);
31 * @expectedException \RuntimeException
32 * @expectedExceptionMessage Decrypt fail
34 * @return [type] [description]
36 public function testDecryptBadValue()
38 $crypto = new CryptoProxy(sys_get_temp_dir() . '/' . uniqid('', true) . '.txt', new NullLogger());
39 $crypto->decrypt('badvalue');