]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | namespace Tests\Wallabag\CoreBundle\Helper; | |
4 | ||
5 | use Monolog\Handler\TestHandler; | |
6 | use Monolog\Logger; | |
7 | use Psr\Log\NullLogger; | |
8 | use Wallabag\CoreBundle\Helper\CryptoProxy; | |
9 | ||
10 | class CryptoProxyTest extends \PHPUnit_Framework_TestCase | |
11 | { | |
12 | public function testCrypto() | |
13 | { | |
14 | $logHandler = new TestHandler(); | |
15 | $logger = new Logger('test', [$logHandler]); | |
16 | ||
17 | $crypto = new CryptoProxy(sys_get_temp_dir() . '/' . uniqid('', true) . '.txt', $logger); | |
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 | /** | |
30 | * @expectedException \RuntimeException | |
31 | * @expectedExceptionMessage Decrypt fail | |
32 | * | |
33 | * @return [type] [description] | |
34 | */ | |
35 | public function testDecryptBadValue() | |
36 | { | |
37 | $crypto = new CryptoProxy(sys_get_temp_dir() . '/' . uniqid('', true) . '.txt', new NullLogger()); | |
38 | $crypto->decrypt('badvalue'); | |
39 | } | |
40 | } |