Completed
Push — master ( e0017c...6b1304 )
by Tom
14s queued 11s
created

Service/Authentication/StorageFactoryTest.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
0 ignored issues
show
The method expects cannot be called on $serviceManager (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
59
            ->expects($this->at(0))
60
            ->method('get')
61
            ->with('config')
62
            ->will($this->returnValue($config));
63
        $serviceManager
0 ignored issues
show
The method expects cannot be called on $serviceManager (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
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