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

Service/Authentication/StorageFactoryTest.php (6 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');
0 ignored issues
show
Are you sure the assignment to $objectManager is correct as $this->createMock('Doctr...stence\\ObjectManager') (which targets PHPUnit\Framework\TestCase::createMock()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
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))
0 ignored issues
show
The method at() does not seem to exist on object<DoctrineModuleTes...ion\StorageFactoryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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))
0 ignored issues
show
The method at() does not seem to exist on object<DoctrineModuleTes...ion\StorageFactoryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
65
            ->method('get')
66
            ->with('some_storage')
67
            ->will($this->returnValue($storage));
68
69
        $this->assertInstanceOf(
0 ignored issues
show
The method assertInstanceOf() does not seem to exist on object<DoctrineModuleTes...ion\StorageFactoryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
70
            'DoctrineModule\Authentication\Storage\ObjectRepository',
71
            $factory->createService($serviceManager)
72
        );
73
    }
74
}
75