1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of phpDocumentor. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
* |
8
|
|
|
* @copyright 2010-2016 Mike van Riel<[email protected]> |
9
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
10
|
|
|
* @link http://phpdoc.org |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace phpDocumentor\Application\ReadModel; |
14
|
|
|
|
15
|
|
|
use Interop\Container\ContainerInterface; |
16
|
|
|
use Mockery as m; |
17
|
|
|
use phpDocumentor\DomainModel\ReadModel\Type; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @coversDefaultClass phpDocumentor\Application\ReadModel\FromContainerFactory |
21
|
|
|
* @covers ::<private> |
22
|
|
|
*/ |
23
|
|
|
final class FromContainerFactoryTest extends \PHPUnit_Framework_TestCase |
24
|
|
|
{ |
25
|
|
|
/** @var ContainerInterface|m\MockInterface */ |
26
|
|
|
private $container; |
27
|
|
|
|
28
|
|
|
/** @var FromContainerFactory */ |
29
|
|
|
private $factory; |
30
|
|
|
|
31
|
|
|
protected function setUp() |
32
|
|
|
{ |
33
|
|
|
$this->container = m::mock(ContainerInterface::class); |
34
|
|
|
$this->factory = new FromContainerFactory($this->container, [ 'alias' => 'phpDocumentor2' ]); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @test |
39
|
|
|
* @covers ::__construct |
40
|
|
|
* @covers ::create |
41
|
|
|
*/ |
42
|
|
|
public function itShouldCreateANewReadModelByRetrievingItFromTheContainer() |
43
|
|
|
{ |
44
|
|
|
$expectedReadModelName = 'phpDocumentor2'; |
45
|
|
|
$expected = 'readModel'; |
46
|
|
|
$this->container->shouldReceive('get')->once() |
|
|
|
|
47
|
|
|
->with($expectedReadModelName)->andReturn($expected); |
48
|
|
|
|
49
|
|
|
$this->assertSame($expected, $this->factory->create(new Type($expectedReadModelName))); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @test |
54
|
|
|
* @covers ::__construct |
55
|
|
|
* @covers ::create |
56
|
|
|
*/ |
57
|
|
|
public function itShouldCreateANewReadModelByRetrievingItFromTheContainerBasedOnAnAlias() |
58
|
|
|
{ |
59
|
|
|
$expectedReadModelName = 'phpDocumentor2'; |
60
|
|
|
$expected = 'readModel'; |
61
|
|
|
$this->container->shouldReceive('get')->once() |
|
|
|
|
62
|
|
|
->with($expectedReadModelName)->andReturn($expected); |
63
|
|
|
|
64
|
|
|
$this->assertSame($expected, $this->factory->create(new Type('alias'))); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: