1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
* |
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
16
|
|
|
* and is licensed under the MIT license. For more information, see |
17
|
|
|
* <http://www.doctrine-project.org>. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace DoctrineORMModuleTest; |
21
|
|
|
|
22
|
|
|
use PHPUnit_Framework_TestCase; |
23
|
|
|
use DoctrineORMModuleTest\Util\ServiceManagerFactory; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Tests used to verify that command line functionality is active |
27
|
|
|
* |
28
|
|
|
* @license MIT |
29
|
|
|
* @link http://www.doctrine-project.org/ |
30
|
|
|
* @author Marco Pivetta <[email protected]> |
31
|
|
|
*/ |
32
|
|
|
class CliTest extends PHPUnit_Framework_TestCase |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* @var \Symfony\Component\Console\Application |
36
|
|
|
*/ |
37
|
|
|
protected $cli; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var \Doctrine\ORM\EntityManager |
41
|
|
|
*/ |
42
|
|
|
protected $entityManager; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* {@inheritDoc} |
46
|
|
|
*/ |
47
|
|
|
public function setUp() |
48
|
|
|
{ |
49
|
|
|
$serviceManager = ServiceManagerFactory::getServiceManager(); |
50
|
|
|
/* @var $sharedEventManager \Zend\EventManager\SharedEventManagerInterface */ |
51
|
|
|
$sharedEventManager = $serviceManager->get('SharedEventManager'); |
52
|
|
|
/* @var $application \Zend\Mvc\Application */ |
53
|
|
|
$application = $serviceManager->get('Application'); |
54
|
|
|
$invocations = 0; |
55
|
|
|
|
56
|
|
|
$sharedEventManager->attach( |
57
|
|
|
'doctrine', |
58
|
|
|
'loadCli.post', |
59
|
|
|
function () use (&$invocations) { |
60
|
|
|
$invocations += 1; |
61
|
|
|
} |
62
|
|
|
); |
63
|
|
|
|
64
|
|
|
$application->bootstrap(); |
65
|
|
|
$this->entityManager = $serviceManager->get('doctrine.entitymanager.orm_default'); |
|
|
|
|
66
|
|
|
$this->cli = $serviceManager->get('doctrine.cli'); |
|
|
|
|
67
|
|
|
$this->assertSame(1, $invocations); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function testValidHelpers() |
71
|
|
|
{ |
72
|
|
|
$helperSet = $this->cli->getHelperSet(); |
73
|
|
|
|
74
|
|
|
/* @var $emHelper \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper */ |
75
|
|
|
$emHelper = $helperSet->get('em'); |
76
|
|
|
$this->assertInstanceOf('Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper', $emHelper); |
77
|
|
|
$this->assertSame($this->entityManager, $emHelper->getEntityManager()); |
78
|
|
|
|
79
|
|
|
/* @var $dbHelper \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper */ |
80
|
|
|
$dbHelper = $helperSet->get('db'); |
81
|
|
|
$this->assertInstanceOf('Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper', $dbHelper); |
82
|
|
|
$this->assertSame($this->entityManager->getConnection(), $dbHelper->getConnection()); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function testValidCommands() |
86
|
|
|
{ |
87
|
|
|
$this->assertInstanceOf('Doctrine\DBAL\Tools\Console\Command\ImportCommand', $this->cli->get('dbal:import')); |
88
|
|
|
$this->assertInstanceOf('Doctrine\DBAL\Tools\Console\Command\RunSqlCommand', $this->cli->get('dbal:run-sql')); |
89
|
|
|
$this->assertInstanceOf( |
90
|
|
|
'Doctrine\ORM\Tools\Console\Command\ClearCache\MetadataCommand', |
91
|
|
|
$this->cli->get('orm:clear-cache:metadata') |
92
|
|
|
); |
93
|
|
|
$this->assertInstanceOf( |
94
|
|
|
'Doctrine\ORM\Tools\Console\Command\ClearCache\QueryCommand', |
95
|
|
|
$this->cli->get('orm:clear-cache:query') |
96
|
|
|
); |
97
|
|
|
$this->assertInstanceOf( |
98
|
|
|
'Doctrine\ORM\Tools\Console\Command\ClearCache\ResultCommand', |
99
|
|
|
$this->cli->get('orm:clear-cache:result') |
100
|
|
|
); |
101
|
|
|
$this->assertInstanceOf( |
102
|
|
|
'Doctrine\ORM\Tools\Console\Command\GenerateProxiesCommand', |
103
|
|
|
$this->cli->get('orm:generate-proxies') |
104
|
|
|
); |
105
|
|
|
$this->assertInstanceOf( |
106
|
|
|
'Doctrine\ORM\Tools\Console\Command\EnsureProductionSettingsCommand', |
107
|
|
|
$this->cli->get('orm:ensure-production-settings') |
108
|
|
|
); |
109
|
|
|
$this->assertInstanceOf( |
110
|
|
|
'Doctrine\ORM\Tools\Console\Command\InfoCommand', |
111
|
|
|
$this->cli->get('orm:info') |
112
|
|
|
); |
113
|
|
|
$this->assertInstanceOf( |
114
|
|
|
'Doctrine\ORM\Tools\Console\Command\SchemaTool\CreateCommand', |
115
|
|
|
$this->cli->get('orm:schema-tool:create') |
116
|
|
|
); |
117
|
|
|
$this->assertInstanceOf( |
118
|
|
|
'Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand', |
119
|
|
|
$this->cli->get('orm:schema-tool:update') |
120
|
|
|
); |
121
|
|
|
$this->assertInstanceOf( |
122
|
|
|
'Doctrine\ORM\Tools\Console\Command\SchemaTool\DropCommand', |
123
|
|
|
$this->cli->get('orm:schema-tool:drop') |
124
|
|
|
); |
125
|
|
|
$this->assertInstanceOf( |
126
|
|
|
'Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand', |
127
|
|
|
$this->cli->get('orm:validate-schema') |
128
|
|
|
); |
129
|
|
|
$this->assertInstanceOf( |
130
|
|
|
'Doctrine\ORM\Tools\Console\Command\RunDqlCommand', |
131
|
|
|
$this->cli->get('orm:run-dql') |
132
|
|
|
); |
133
|
|
|
$this->assertInstanceOf( |
134
|
|
|
'Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand', |
135
|
|
|
$this->cli->get('migrations:generate') |
136
|
|
|
); |
137
|
|
|
$this->assertInstanceOf( |
138
|
|
|
'Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand', |
139
|
|
|
$this->cli->get('migrations:diff') |
140
|
|
|
); |
141
|
|
|
$this->assertInstanceOf( |
142
|
|
|
'Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand', |
143
|
|
|
$this->cli->get('migrations:execute') |
144
|
|
|
); |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.