Passed
Push — issue#767 ( 902b86...e6d68a )
by Guilherme
05:21
created

PublicKeyTest::testPublicKey()   B

Complexity

Conditions 3
Paths 1

Size

Total Lines 31
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 21
nc 1
nop 0
dl 0
loc 31
rs 8.8571
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the login-cidadao project or it's bundles.
4
 *
5
 * (c) Guilherme Donato <guilhermednt on github>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace LoginCidadao\OpenIDBundle\Tests\Storage;
12
13
use Gaufrette\Exception\FileNotFound;
14
use Gaufrette\File;
15
use Gaufrette\Filesystem;
16
use LoginCidadao\OpenIDBundle\Storage\PublicKey;
17
18
class PublicKeyTest extends \PHPUnit_Framework_TestCase
19
{
20
    public function testPublicKey()
21
    {
22
        $filename = 'key.pem';
23
24
        $file = null;
25
26
        /** @var Filesystem|\PHPUnit_Framework_MockObject_MockObject $filesystem */
27
        $filesystem = $this->getMockBuilder('Gaufrette\Filesystem')->disableOriginalConstructor()->getMock();
28
        $filesystem->expects($this->atLeastOnce())
29
            ->method('get')->with($filename, $this->isType('bool'))
30
            ->willReturnCallback(function ($key, $create = false) use ($filename, $filesystem, &$file) {
31
                $this->assertSame($filename, $key);
32
                if ($file !== null) {
33
                    return $file;
34
                } elseif ($create === false) {
35
                    throw new FileNotFound($filename);
36
                } else {
37
                    $file = new File($key, $filesystem);
38
39
                    return $file;
40
                }
41
            });
42
43
        $publicKey = new PublicKey();
44
        $publicKey->setFilesystem($filesystem, $filename);
45
        $pubKey = $publicKey->getPublicKey('clientId');
46
        $privKey = $publicKey->getPrivateKey('clientId');
47
48
        $this->assertNotNull($pubKey);
49
        $this->assertNotNull($privKey);
50
        $this->assertSame('RS256', $publicKey->getEncryptionAlgorithm('clientId'));
51
    }
52
}
53