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

StorageFactoryTest::testWillInstantiateFromFQCN()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 9.424
c 0
b 0
f 0
cc 1
nc 1
nop 0
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
Bug introduced by
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);
0 ignored issues
show
Bug introduced by
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...
43
    }
44
45
    public function testCanInstantiateStorageFromServiceLocator() : void
46
    {
47
        $factory        = new StorageFactory('testFactory');
48
        $serviceManager = $this->createMock('Laminas\ServiceManager\ServiceManager');
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $serviceManager is correct as $this->createMock('Lamin...nager\\ServiceManager') (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...
49
        $storage        = $this->createMock('Laminas\Authentication\Storage\StorageInterface');
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $storage is correct as $this->createMock('Lamin...age\\StorageInterface') (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...
50
        $config         = [
51
            'doctrine' => [
52
                'authentication' => [
53
                    'testFactory' => ['storage' => 'some_storage'],
54
                ],
55
            ],
56
        ];
57
58
        $serviceManager
0 ignored issues
show
Bug introduced by
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
Bug introduced by
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));
0 ignored issues
show
Bug introduced by
The method returnValue() 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...
63
        $serviceManager
0 ignored issues
show
Bug introduced by
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
Bug introduced by
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));
0 ignored issues
show
Bug introduced by
The method returnValue() 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...
68
69
        $this->assertInstanceOf(
0 ignored issues
show
Bug introduced by
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)
0 ignored issues
show
Documentation introduced by
$serviceManager is of type null, but the function expects a object<Laminas\ServiceMa...erviceLocatorInterface>.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
72
        );
73
    }
74
}
75