|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Abacaphiliac\DoctrineORMDiagnosticsModuleTest; |
|
4
|
|
|
|
|
5
|
|
|
use Abacaphiliac\DoctrineORMDiagnosticsModule\AbstractCheckCommandFactory; |
|
6
|
|
|
use Abacaphiliac\DoctrineORMDiagnosticsModule\CheckCommand; |
|
7
|
|
|
use Symfony\Component\Console\Application; |
|
8
|
|
|
use Symfony\Component\Console\Command\Command; |
|
9
|
|
|
use Zend\ServiceManager\ServiceManager; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @covers \Abacaphiliac\DoctrineORMDiagnosticsModule\AbstractCheckCommandFactory |
|
13
|
|
|
*/ |
|
14
|
|
|
class AbstractCheckCommandFactoryTest extends \PHPUnit_Framework_TestCase |
|
15
|
|
|
{ |
|
16
|
|
|
/** @var ServiceManager */ |
|
17
|
|
|
private $serviceLocator; |
|
18
|
|
|
|
|
19
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject|AbstractCheckCommandFactory */ |
|
20
|
|
|
private $sut; |
|
21
|
|
|
|
|
22
|
|
|
protected function setUp() |
|
23
|
|
|
{ |
|
24
|
|
|
parent::setUp(); |
|
25
|
|
|
|
|
26
|
|
|
$this->serviceLocator = new ServiceManager(); |
|
27
|
|
|
|
|
28
|
|
|
$this->sut = $this->getMockForAbstractClass(AbstractCheckCommandFactory::class); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function testCreateService() |
|
32
|
|
|
{ |
|
33
|
|
|
$this->sut->method('getCommandServiceName')->willReturn('FooBar'); |
|
34
|
|
|
|
|
35
|
|
|
$this->serviceLocator->setService('doctrine.cli', new Application()); |
|
36
|
|
|
$this->serviceLocator->setService('FooBar', new Command('FooBar')); |
|
37
|
|
|
|
|
38
|
|
|
$actual = $this->sut->createService($this->serviceLocator); |
|
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
self::assertInstanceOf(CheckCommand::class, $actual); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @expectedException \UnexpectedValueException |
|
45
|
|
|
*/ |
|
46
|
|
|
public function testNotCreateServiceDueToInvalidCommandType() |
|
47
|
|
|
{ |
|
48
|
|
|
$this->sut->method('getCommandServiceName')->willReturn('FooBar'); |
|
49
|
|
|
|
|
50
|
|
|
$this->serviceLocator->setService('doctrine.cli', new Application()); |
|
51
|
|
|
$this->serviceLocator->setService('FooBar', new \stdClass()); |
|
52
|
|
|
|
|
53
|
|
|
$this->sut->createService($this->serviceLocator); |
|
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
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: