1
|
|
|
<?php |
2
|
|
|
namespace OnurbTest\Bundle\YumlBundle\Command; |
3
|
|
|
|
4
|
|
|
use Onurb\Bundle\YumlBundle\Command\YumlCommand; |
5
|
|
|
use Symfony\Component\Console\Application; |
6
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
7
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
8
|
|
|
|
9
|
|
|
class YumlCommandTest extends \PHPUnit_Framework_TestCase |
10
|
|
|
{ |
11
|
|
|
const YUML_LINK = 'https://yuml.me/15a98c92.png'; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @var Application |
15
|
|
|
*/ |
16
|
|
|
private $application; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var YumlCommand |
20
|
|
|
*/ |
21
|
|
|
private $command; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var ContainerInterface |
25
|
|
|
*/ |
26
|
|
|
private $container; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var CommandTester |
30
|
|
|
*/ |
31
|
|
|
private $commandTester; |
32
|
|
|
|
33
|
|
|
public function setUp() |
34
|
|
|
{ |
35
|
|
|
parent::setUp(); |
36
|
|
|
$this->application = new Application(); |
37
|
|
|
$this->application->add(new YumlCommand()); |
38
|
|
|
$this->command = $this->application->find('yuml:mappings'); |
39
|
|
|
|
40
|
|
|
$this->commandTester = new CommandTester($this->command); |
41
|
|
|
|
42
|
|
|
$yumlClient = $this->getMock('Onurb\\Bundle\\YumlBundle\\Yuml\\YumlClientInterface'); |
43
|
|
|
|
44
|
|
|
$yumlClient->expects($this->once()) |
45
|
|
|
->method('makeDslText') |
46
|
|
|
->will($this->returnValue('[Simple.Entity|+a;b;c]')); |
47
|
|
|
|
48
|
|
|
$yumlClient->expects($this->once()) |
49
|
|
|
->method('getGraphUrl') |
50
|
|
|
->will($this->returnValue(self::YUML_LINK)); |
51
|
|
|
|
52
|
|
|
$this->container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface'); |
53
|
|
|
|
54
|
|
|
$this->container->expects($this->once())->method('get') |
55
|
|
|
->with($this->matches('onurb.doctrine_yuml.client')) |
56
|
|
|
->will($this->returnValue($yumlClient)); |
57
|
|
|
|
58
|
|
|
$this->command->setContainer($this->container); |
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @covers \Onurb\Bundle\YumlBundle\Command\YumlCommand |
63
|
|
|
*/ |
64
|
|
|
public function testExecute() |
65
|
|
|
{ |
66
|
|
|
$this->commandTester->execute(array('command' => $this->command->getName())); |
67
|
|
|
$this->assertRegExp('/.../', $this->commandTester->getDisplay()); |
68
|
|
|
$this->assertSame('Downloaded', explode(' ', $this->commandTester->getDisplay())[0]); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: