Completed
Push — master ( 0f71cc...99d0b0 )
by Karel
15:42
created

testThatGetRepositoryCallsMainRepositoryManager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 17
rs 9.4285
cc 1
eloc 12
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the FOSElasticaBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\ElasticaBundle\Tests\Doctrine;
13
14
use Doctrine\Common\Persistence\ManagerRegistry;
15
use FOS\ElasticaBundle\Doctrine\RepositoryManager;
16
use FOS\ElasticaBundle\Finder\TransformedFinder;
17
use FOS\ElasticaBundle\Manager\RepositoryManagerInterface;
18
use FOS\ElasticaBundle\Repository;
19
use PHPUnit\Framework\TestCase;
20
21
class CustomRepository
22
{
23
}
24
25
class Entity
26
{
27
}
28
29
/**
30
 * @author Richard Miller <[email protected]>
31
 */
32
class RepositoryManagerTest extends TestCase
33
{
34
    public function testThatGetRepositoryCallsMainRepositoryManager()
35
    {
36
        $finderMock = $this->createMock(TransformedFinder::class);
37
        $registryMock = $this->createMock(ManagerRegistry::class);
38
        $mainManager = $this->createMock(RepositoryManagerInterface::class);
39
40
        $mainManager->method('getRepository')
41
            ->with($this->equalTo('index/type'))
42
            ->willReturn(new Repository($finderMock));
0 ignored issues
show
Documentation introduced by
$finderMock is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<FOS\ElasticaBundl...ginatedFinderInterface>.

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...
43
44
        $entityName = Entity::class;
45
46
        $manager = new RepositoryManager($registryMock, $mainManager);
0 ignored issues
show
Documentation introduced by
$registryMock is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\Common\P...stence\ManagerRegistry>.

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...
Documentation introduced by
$mainManager is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<FOS\ElasticaBundl...sitoryManagerInterface>.

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...
47
        $manager->addEntity($entityName, 'index/type');
48
        $repository = $manager->getRepository($entityName);
49
        $this->assertInstanceOf(Repository::class, $repository);
50
    }
51
52
    public function testGetRepositoryShouldResolveEntityShortName()
53
    {
54
        $finderMock = $this->createMock(TransformedFinder::class);
55
        $registryMock = $this->createMock(ManagerRegistry::class);
56
        $mainManager = $this->createMock(RepositoryManagerInterface::class);
57
58
        $registryMock->method('getAliasNamespace')
59
            ->with($this->equalTo('FOSElasticaBundle'))
60
            ->willReturn('FOS\ElasticaBundle\Tests\Doctrine');
61
62
        $mainManager->method('getRepository')
63
            ->with($this->equalTo('index/type'))
64
            ->willReturn(new Repository($finderMock));
0 ignored issues
show
Documentation introduced by
$finderMock is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<FOS\ElasticaBundl...ginatedFinderInterface>.

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...
65
66
        $entityName = Entity::class;
67
68
        $manager = new RepositoryManager($registryMock, $mainManager);
0 ignored issues
show
Documentation introduced by
$registryMock is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\Common\P...stence\ManagerRegistry>.

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...
Documentation introduced by
$mainManager is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<FOS\ElasticaBundl...sitoryManagerInterface>.

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...
69
        $manager->addEntity($entityName, 'index/type');
70
        $repository = $manager->getRepository('FOSElasticaBundle:Entity');
71
        $this->assertInstanceOf(Repository::class, $repository);
72
    }
73
}
74