Completed
Push — 5.6 ( c5fe0b...561087 )
by Jeroen
19:25 queued 04:42
created

OAuthUserFinderTest::setup()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Kunstmaan\AdminBundle\Tests\Helper\Security\Oauth;
4
5
use DateTime;
6
use Doctrine\ORM\EntityManager;
7
use Doctrine\ORM\EntityRepository;
8
use Kunstmaan\AdminBundle\Entity\User;
9
use Kunstmaan\AdminBundle\Helper\Security\OAuth\OAuthUserFinder;
10
use PHPUnit\Framework\MockObject\MockObject;
11
use PHPUnit\Framework\TestCase;
12
13
class OAuthUserFinderTest extends TestCase
14
{
15
    /**
16
     * @var OAuthUserFinder
17
     */
18
    private $object;
19
20
    /**
21
     * @var EntityManager
22
     */
23
    private $em;
24
25
    /**
26
     * @return MockObject
27
     */
28
    private function getEm()
29
    {
30
        if (!isset($this->em)) {
31
            $this->em = $this->createMock(EntityManager::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\Doctr...M\EntityManager::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Doctrine\ORM\EntityManager> of property $em.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
32
        }
33
34
        return $this->em;
35
    }
36
37
    public function setup()
38
    {
39
        $em = $this->getEm();
40
        $object = new OAuthUserFinder($em, User::class);
0 ignored issues
show
Documentation introduced by
$em is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\ORM\EntityManagerInterface>.

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...
41
        $this->object = $object;
42
    }
43
44
    public function testFindUserByGoogleSignInData()
45
    {
46
        $object = $this->object;
47
        $repo = $this->createMock(EntityRepository::class);
48
        $repo->expects($this->exactly(3))->method('findOneBy')->will($this->onConsecutiveCalls(new DateTime(), new DateTime(), new User()));
49
        $this->getEm()->expects($this->exactly(3))->method('getRepository')->willReturn($repo);
50
        $user = $object->findUserByGoogleSignInData('[email protected]', 12345679);
51
        $this->assertInstanceOf(User::class, $user);
52
    }
53
}
54