|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\ORM\Tools\Console\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver; |
|
6
|
|
|
use Doctrine\ORM\Configuration; |
|
7
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
8
|
|
|
use Doctrine\ORM\Mapping\MappingException; |
|
9
|
|
|
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper; |
|
10
|
|
|
use Doctrine\Tests\Models\Cache\AttractionInfo; |
|
11
|
|
|
use Doctrine\Tests\Models\Cache\City; |
|
12
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
|
13
|
|
|
use Symfony\Component\Console\Helper\HelperSet; |
|
14
|
|
|
use Symfony\Component\Console\Application; |
|
15
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase; |
|
16
|
|
|
use Doctrine\ORM\Tools\Console\Command\InfoCommand; |
|
17
|
|
|
|
|
18
|
|
|
class InfoCommandTest extends OrmFunctionalTestCase |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var \Symfony\Component\Console\Application |
|
22
|
|
|
*/ |
|
23
|
|
|
private $application; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var \Doctrine\ORM\Tools\Console\Command\InfoCommand |
|
27
|
|
|
*/ |
|
28
|
|
|
private $command; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var \Symfony\Component\Console\Tester\CommandTester |
|
32
|
|
|
*/ |
|
33
|
|
|
private $tester; |
|
34
|
|
|
|
|
35
|
|
View Code Duplication |
protected function setUp() |
|
36
|
|
|
{ |
|
37
|
|
|
parent::setUp(); |
|
38
|
|
|
|
|
39
|
|
|
$this->application = new Application(); |
|
40
|
|
|
|
|
41
|
|
|
$this->application->setHelperSet(new HelperSet(['em' => new EntityManagerHelper($this->_em)])); |
|
42
|
|
|
$this->application->add(new InfoCommand()); |
|
43
|
|
|
|
|
44
|
|
|
$this->command = $this->application->find('orm:info'); |
|
45
|
|
|
$this->tester = new CommandTester($this->command); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function testListAllClasses() |
|
49
|
|
|
{ |
|
50
|
|
|
$this->tester->execute(['command' => $this->command->getName()]); |
|
51
|
|
|
|
|
52
|
|
|
self::assertContains(AttractionInfo::class, $this->tester->getDisplay()); |
|
53
|
|
|
self::assertContains(City::class, $this->tester->getDisplay()); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function testEmptyEntityClassNames() : void |
|
57
|
|
|
{ |
|
58
|
|
|
$mappingDriver = $this->createMock(MappingDriver::class); |
|
59
|
|
|
$configuration = $this->createMock(Configuration::class); |
|
60
|
|
|
$em = $this->createMock(EntityManagerInterface::class); |
|
61
|
|
|
|
|
62
|
|
|
$mappingDriver->method('getAllClassNames') |
|
|
|
|
|
|
63
|
|
|
->willReturn([]); |
|
64
|
|
|
|
|
65
|
|
|
$configuration->method('getMetadataDriverImpl') |
|
66
|
|
|
->willReturn($mappingDriver); |
|
67
|
|
|
|
|
68
|
|
|
$em->method('getConfiguration') |
|
69
|
|
|
->willReturn($configuration); |
|
70
|
|
|
|
|
71
|
|
|
$application = new Application(); |
|
72
|
|
|
$application->setHelperSet(new HelperSet(['em' => new EntityManagerHelper($em)])); |
|
73
|
|
|
$application->add(new InfoCommand()); |
|
74
|
|
|
|
|
75
|
|
|
$command = $application->find('orm:info'); |
|
76
|
|
|
$tester = new CommandTester($command); |
|
77
|
|
|
|
|
78
|
|
|
$tester->execute(['command' => $command->getName()]); |
|
79
|
|
|
|
|
80
|
|
|
self::assertContains( |
|
81
|
|
|
' ! [CAUTION] You do not have any mapped Doctrine ORM entities according to the current configuration', |
|
82
|
|
|
$tester->getDisplay() |
|
83
|
|
|
); |
|
84
|
|
|
|
|
85
|
|
|
self::assertContains( |
|
86
|
|
|
' ! If you have entities or mapping files you should check your mapping configuration for errors.', |
|
87
|
|
|
$tester->getDisplay() |
|
88
|
|
|
); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function testInvalidEntityClassMetadata() : void |
|
92
|
|
|
{ |
|
93
|
|
|
$mappingDriver = $this->createMock(MappingDriver::class); |
|
94
|
|
|
$configuration = $this->createMock(Configuration::class); |
|
95
|
|
|
$em = $this->createMock(EntityManagerInterface::class); |
|
96
|
|
|
|
|
97
|
|
|
$mappingDriver->method('getAllClassNames') |
|
98
|
|
|
->willReturn(['InvalidEntity']); |
|
99
|
|
|
|
|
100
|
|
|
$configuration->method('getMetadataDriverImpl') |
|
101
|
|
|
->willReturn($mappingDriver); |
|
102
|
|
|
|
|
103
|
|
|
$em->method('getConfiguration') |
|
104
|
|
|
->willReturn($configuration); |
|
105
|
|
|
|
|
106
|
|
|
$em->method('getClassMetadata') |
|
107
|
|
|
->with('InvalidEntity') |
|
108
|
|
|
->willThrowException(new MappingException('exception message')); |
|
109
|
|
|
|
|
110
|
|
|
$application = new Application(); |
|
111
|
|
|
$application->setHelperSet(new HelperSet(['em' => new EntityManagerHelper($em)])); |
|
112
|
|
|
$application->add(new InfoCommand()); |
|
113
|
|
|
|
|
114
|
|
|
$command = $application->find('orm:info'); |
|
115
|
|
|
$tester = new CommandTester($command); |
|
116
|
|
|
|
|
117
|
|
|
$tester->execute(['command' => $command->getName()]); |
|
118
|
|
|
|
|
119
|
|
|
self::assertContains('[FAIL] InvalidEntity', $tester->getDisplay()); |
|
120
|
|
|
self::assertContains('exception message', $tester->getDisplay()); |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.