Completed
Pull Request — master (#6)
by Tomáš
03:49
created

CompleteTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 2
c 4
b 0
f 0
lcom 0
cbo 4
dl 0
loc 36
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
A testSomeServiceAutowire() 0 12 1
1
<?php
2
3
namespace Symplify\DefaultAutowire\Tests;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use PHPUnit_Framework_TestCase;
7
use Symfony\Component\DependencyInjection\Container;
8
use Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher;
9
use Symfony\Component\EventDispatcher\EventDispatcher;
10
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
11
use Symplify\DefaultAutowire\Tests\Resources\Repository\SomeRepository;
12
use Symplify\DefaultAutowire\Tests\Source\SomeAutowiredService;
13
use Symplify\DefaultAutowire\Tests\Source\SomeService;
14
15
final class CompleteTest extends PHPUnit_Framework_TestCase
16
{
17
    /**
18
     * @var Container
19
     */
20
    private $container;
21
22
    protected function setUp()
23
    {
24
        $kernel = new AppKernel('test_env', true);
25
        $kernel->boot();
26
27
        $this->container = $kernel->getContainer();
0 ignored issues
show
Documentation Bug introduced by
It seems like $kernel->getContainer() can also be of type object<Symfony\Component...ion\ContainerInterface>. However, the property $container is declared as type object<Symfony\Component...ncyInjection\Container>. 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...
28
    }
29
30
    public function testSomeServiceAutowire()
31
    {
32
        /** @var SomeAutowiredService $someAutowiredService */
33
        $someAutowiredService = $this->container->get('some_autowired_service');
34
35
        $this->assertInstanceOf(SomeAutowiredService::class, $someAutowiredService);
36
        $this->assertInstanceOf(SomeService::class, $someAutowiredService->getSomeService());
37
38
        $this->assertInstanceOf(EventDispatcherInterface::class, $someAutowiredService->getEventDispatcher());
39
        $this->assertInstanceOf(EventDispatcher::class, $someAutowiredService->getEventDispatcher());
40
        $this->assertNotInstanceOf(TraceableEventDispatcher::class, $someAutowiredService->getEventDispatcher());
41
    }
42
43
//    public function testRepositoryAutowire()
0 ignored issues
show
Unused Code Comprehensibility introduced by
51% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
44
//    {
45
//        /** @var SomeRepository $someRepository */
46
//        $someRepository = $this->container->get('some_repository');
47
//        $this->assertInstanceOf(SomeRepository::class, $someRepository);
48
//        $this->assertInstanceOf(EntityManagerInterface::class, $someRepository->getEntityManager());
49
//    }
50
}
51