1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace DoctrineModuleTest\Service\Authentication; |
6
|
|
|
|
7
|
|
|
use DoctrineModule\Service\Authentication\StorageFactory; |
8
|
|
|
use Laminas\ServiceManager\ServiceManager; |
9
|
|
|
use PHPUnit\Framework\TestCase as BaseTestCase; |
10
|
|
|
|
11
|
|
|
class StorageFactoryTest extends BaseTestCase |
12
|
|
|
{ |
13
|
|
|
public function testWillInstantiateFromFQCN() : void |
14
|
|
|
{ |
15
|
|
|
$name = 'testFactory'; |
16
|
|
|
$factory = new StorageFactory($name); |
17
|
|
|
|
18
|
|
|
$objectManager = $this->createMock('Doctrine\Persistence\ObjectManager'); |
19
|
|
|
|
20
|
|
|
$serviceManager = new ServiceManager(); |
21
|
|
|
$serviceManager->setInvokableClass( |
22
|
|
|
'DoctrineModule\Authentication\Storage\Session', |
23
|
|
|
'Laminas\Authentication\Storage\Session' |
24
|
|
|
); |
25
|
|
|
$serviceManager->setService( |
26
|
|
|
'config', |
27
|
|
|
[ |
28
|
|
|
'doctrine' => [ |
29
|
|
|
'authentication' => [ |
30
|
|
|
$name => [ |
31
|
|
|
'objectManager' => $objectManager, |
32
|
|
|
'identityClass' => 'DoctrineModuleTest\Authentication\Adapter\TestAsset\IdentityObject', |
33
|
|
|
'identityProperty' => 'username', |
34
|
|
|
'credentialProperty' => 'password', |
35
|
|
|
], |
36
|
|
|
], |
37
|
|
|
], |
38
|
|
|
] |
39
|
|
|
); |
40
|
|
|
|
41
|
|
|
$adapter = $factory->createService($serviceManager); |
42
|
|
|
$this->assertInstanceOf('DoctrineModule\Authentication\Storage\ObjectRepository', $adapter); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testCanInstantiateStorageFromServiceLocator() : void |
46
|
|
|
{ |
47
|
|
|
$factory = new StorageFactory('testFactory'); |
48
|
|
|
$serviceManager = $this->createMock('Laminas\ServiceManager\ServiceManager'); |
49
|
|
|
$storage = $this->createMock('Laminas\Authentication\Storage\StorageInterface'); |
50
|
|
|
$config = [ |
51
|
|
|
'doctrine' => [ |
52
|
|
|
'authentication' => [ |
53
|
|
|
'testFactory' => ['storage' => 'some_storage'], |
54
|
|
|
], |
55
|
|
|
], |
56
|
|
|
]; |
57
|
|
|
|
58
|
|
|
$serviceManager |
59
|
|
|
->expects($this->at(0)) |
60
|
|
|
->method('get') |
61
|
|
|
->with('config') |
62
|
|
|
->will($this->returnValue($config)); |
63
|
|
|
$serviceManager |
64
|
|
|
->expects($this->at(1)) |
65
|
|
|
->method('get') |
66
|
|
|
->with('some_storage') |
67
|
|
|
->will($this->returnValue($storage)); |
68
|
|
|
|
69
|
|
|
$this->assertInstanceOf( |
70
|
|
|
'DoctrineModule\Authentication\Storage\ObjectRepository', |
71
|
|
|
$factory->createService($serviceManager) |
|
|
|
|
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: