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\Listener; |
21
|
|
|
|
22
|
|
|
use Doctrine\DBAL\Connection; |
23
|
|
|
use Doctrine\ORM\EntityManager; |
24
|
|
|
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper; |
25
|
|
|
use DoctrineORMModule\CliConfigurator; |
26
|
|
|
use DoctrineORMModuleTest\ServiceManagerFactory; |
27
|
|
|
use PHPUnit\Framework\TestCase; |
28
|
|
|
use Symfony\Component\Console\Application; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @license MIT |
32
|
|
|
* @link http://www.doctrine-project.org/ |
33
|
|
|
* @author Nicolas Eeckeloo <[email protected]> |
34
|
|
|
*/ |
35
|
|
|
class CliConfiguratorTest extends TestCase |
36
|
|
|
{ |
37
|
|
|
/** |
38
|
|
|
* @var \Zend\ServiceManager\ServiceManager |
39
|
|
|
*/ |
40
|
|
|
protected $serviceManager; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var \Doctrine\ORM\EntityManager |
44
|
|
|
*/ |
45
|
|
|
protected $objectManager; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* {@inheritDoc} |
49
|
|
|
*/ |
50
|
|
|
public function setUp() |
51
|
|
|
{ |
52
|
|
|
$this->serviceManager = ServiceManagerFactory::getServiceManager(); |
53
|
|
|
$this->objectManager = $this->serviceManager->get('doctrine.entitymanager.orm_default'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testOrmDefaultIsUsedAsTheEntityManagerIfNoneIsProvided() |
57
|
|
|
{ |
58
|
|
|
$application = new Application(); |
59
|
|
|
|
60
|
|
|
$cliConfigurator = new CliConfigurator($this->serviceManager); |
61
|
|
|
$cliConfigurator->configure($application); |
62
|
|
|
|
63
|
|
|
/* @var $entityManagerHelper \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper */ |
64
|
|
|
$entityManagerHelper = $application->getHelperSet()->get('entityManager'); |
65
|
|
|
|
66
|
|
|
$this->assertInstanceOf(EntityManagerHelper::class, $entityManagerHelper); |
67
|
|
|
$this->assertSame($this->objectManager, $entityManagerHelper->getEntityManager()); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @backupGlobals enabled |
72
|
|
|
*/ |
73
|
|
|
public function testEntityManagerUsedCanBeSpecifiedInCommandLineArgument() |
74
|
|
|
{ |
75
|
|
|
$objectManagerName = 'doctrine.entitymanager.some_other_name'; |
76
|
|
|
|
77
|
|
|
$connection = $this->getMockBuilder(Connection::class) |
78
|
|
|
->disableOriginalConstructor() |
79
|
|
|
->getMock(); |
80
|
|
|
|
81
|
|
|
$entityManager = $this->getMockbuilder(EntityManager::class) |
82
|
|
|
->disableOriginalConstructor() |
83
|
|
|
->getMock(); |
84
|
|
|
|
85
|
|
|
$entityManager |
86
|
|
|
->expects($this->atLeastOnce()) |
87
|
|
|
->method('getConnection') |
88
|
|
|
->willReturn($connection); |
89
|
|
|
|
90
|
|
|
$this->serviceManager->setService($objectManagerName, $entityManager); |
91
|
|
|
|
92
|
|
|
$application = new Application(); |
93
|
|
|
|
94
|
|
|
$_SERVER['argv'][] = '--object-manager=' . $objectManagerName; |
95
|
|
|
|
96
|
|
|
$cliConfigurator = new CliConfigurator($this->serviceManager); |
97
|
|
|
$cliConfigurator->configure($application); |
98
|
|
|
|
99
|
|
|
/* @var $entityManagerHelper \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper */ |
100
|
|
|
$entityManagerHelper = $application->getHelperSet()->get('entityManager'); |
101
|
|
|
|
102
|
|
|
$this->assertInstanceOf(EntityManagerHelper::class, $entityManagerHelper); |
103
|
|
|
$this->assertSame($entityManager, $entityManagerHelper->getEntityManager()); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|