]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | namespace Tests\Wallabag\CoreBundle\Helper; | |
4 | ||
5 | use Monolog\Handler\TestHandler; | |
6 | use Monolog\Logger; | |
7 | use PHPUnit\Framework\TestCase; | |
8 | use Psr\Log\NullLogger; | |
9 | use Wallabag\CoreBundle\Helper\CryptoProxy; | |
10 | ||
11 | class 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 | } |