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

PublicKeyTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
B testPublicKey() 0 31 3
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