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
|
|
|
|