ObjectRepositoryTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 6
dl 0
loc 37
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A testCanRetrieveEntityFromObjectRepositoryStorage() 0 34 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DoctrineModuleTest\Authentication\Storage;
6
7
use DoctrineModule\Authentication\Storage\ObjectRepository as ObjectRepositoryStorage;
8
use DoctrineModuleTest\Authentication\Adapter\TestAsset\IdentityObject;
9
use Laminas\Authentication\Storage\NonPersistent as NonPersistentStorage;
10
use PHPUnit\Framework\TestCase as BaseTestCase;
11
12
/**
13
 * Tests for the ObjectRepository based authentication adapter
14
 *
15
 * @link    http://www.doctrine-project.org/
16
 */
17
class ObjectRepositoryTest extends BaseTestCase
18
{
19
    public function testCanRetrieveEntityFromObjectRepositoryStorage() : void
20
    {
21
        // Identifier is considered to be username here
22
        $entity = new IdentityObject();
23
        $entity->setUsername('a username');
24
        $entity->setPassword('a password');
25
26
        $objectRepository = $this->createMock('Doctrine\Persistence\ObjectRepository');
27
        $objectRepository->expects($this->exactly(1))
28
                         ->method('find')
29
                         ->with($this->equalTo('a username'))
30
                         ->will($this->returnValue($entity));
31
32
        $metadata = $this->createMock('Doctrine\Persistence\Mapping\ClassMetadata');
33
        $metadata->expects($this->exactly(1))
34
                 ->method('getIdentifierValues')
35
                 ->with($this->equalTo($entity))
36
                 ->will($this->returnValue($entity->getUsername()));
37
38
        $storage = new ObjectRepositoryStorage([
39
            'objectRepository' => $objectRepository,
40
            'classMetadata' => $metadata,
41
            'storage' => new NonPersistentStorage(),
42
        ]);
43
44
        $storage->write($entity);
45
        $this->assertFalse($storage->isEmpty());
46
47
        $result = $storage->read();
48
        $this->assertEquals($entity, $result);
49
50
        $key = $storage->readKeyOnly();
51
        $this->assertEquals('a username', $key);
52
    }
53
}
54