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)); |
|
|
|
|
43
|
|
|
|
44
|
|
|
$entityName = Entity::class; |
45
|
|
|
|
46
|
|
|
$manager = new RepositoryManager($registryMock, $mainManager); |
|
|
|
|
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)); |
|
|
|
|
65
|
|
|
|
66
|
|
|
$entityName = Entity::class; |
67
|
|
|
|
68
|
|
|
$manager = new RepositoryManager($registryMock, $mainManager); |
|
|
|
|
69
|
|
|
$manager->addEntity($entityName, 'index/type'); |
70
|
|
|
$repository = $manager->getRepository('FOSElasticaBundle:Entity'); |
71
|
|
|
$this->assertInstanceOf(Repository::class, $repository); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
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: