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

Authentication/Storage/ObjectRepositoryTest.php (2 issues)

Labels
Severity

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\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');
0 ignored issues
show
Are you sure the assignment to $objectRepository is correct as $this->createMock('Doctr...nce\\ObjectRepository') (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...
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');
0 ignored issues
show
Are you sure the assignment to $metadata is correct as $this->createMock('Doctr...apping\\ClassMetadata') (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...
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