Failed Conditions
Push — master ( 9eeb29...881d26 )
by Florent
16:44
created

ClientRepositoryTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 33
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A addClientToDatabase() 0 9 1
A tearDown() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2018 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace OAuth2Framework\ServerBundle\Tests\Functional\ClientRegistration;
15
16
use OAuth2Framework\ServerBundle\Tests\Functional\DatabaseTestCase;
17
use OAuth2Framework\ServerBundle\Tests\TestBundle\Entity\Client;
18
19
/**
20
 * @group ServerBundle
21
 * @group Functional
22
 * @group ClientRepository
23
 */
24
class ClientRepositoryTest extends DatabaseTestCase
25
{
26
    /**
27
     * @var \Doctrine\ORM\EntityManagerInterface
28
     */
29
    private static $entityManager;
30
31
    protected function setUp()
32
    {
33
        parent::setUp();
34
        self::$entityManager = self::$registryManager->getManagerForClass(Client::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like self::$registryManager->...e\Entity\Client::class) can also be of type object<Doctrine\Common\Persistence\ObjectManager>. However, the property $entityManager is declared as type object<Doctrine\ORM\EntityManagerInterface>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
35
    }
36
37
    /**
38
     * @test
39
     */
40
    public function addClientToDatabase()
41
    {
42
        $clients = self::$entityManager
43
            ->getRepository(Client::class)
44
            ->findAll()
45
        ;
46
47
        static::assertCount(5, $clients);
48
    }
49
50
    protected function tearDown()
51
    {
52
        self::$entityManager->close();
53
        self::$entityManager = null;
54
        parent::tearDown();
55
    }
56
}
57