1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace codecept\Doctrine; |
5
|
|
|
|
6
|
|
|
use codecept\FunctionalTester; |
7
|
|
|
use codecept\Helper\ZendExpressive3; |
8
|
|
|
use Doctrine\DBAL\Driver\Connection; |
9
|
|
|
use SlayerBirden\DataFlowServer\Doctrine\Persistence\EntityManagerRegistry; |
10
|
|
|
|
11
|
|
|
class SimpleRegistryTestCest |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var ZendExpressive3 |
15
|
|
|
*/ |
16
|
|
|
private $expressive; |
17
|
|
|
/** |
18
|
|
|
* @var EntityManagerRegistry |
19
|
|
|
*/ |
20
|
|
|
private $registry; |
21
|
|
|
|
22
|
|
|
public function _inject(ZendExpressive3 $expressive) |
23
|
|
|
{ |
24
|
|
|
$this->expressive = $expressive; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function _before(FunctionalTester $I) |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
$this->registry = $this->expressive->container->get(EntityManagerRegistry::class); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testReset(FunctionalTester $I) |
|
|
|
|
33
|
|
|
{ |
34
|
|
|
$manager = $this->registry->getManager(); |
35
|
|
|
$I->assertTrue($manager->isOpen()); |
36
|
|
|
|
37
|
|
|
$manager->close(); // close manager |
38
|
|
|
$I->assertFalse($manager->isOpen()); |
39
|
|
|
|
40
|
|
|
$newManager = $this->registry->getManager(); |
41
|
|
|
$I->assertTrue($newManager->isOpen()); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testGetConnection(FunctionalTester $I) |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
$connection = $this->registry->getConnection(); |
47
|
|
|
$I->assertInstanceOf(Connection::class, $connection); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testGetConnections(FunctionalTester $I) |
|
|
|
|
51
|
|
|
{ |
52
|
|
|
$connections = $this->registry->getConnections(); |
53
|
|
|
$I->assertNotEmpty($connections); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testGetManagers(FunctionalTester $I) |
|
|
|
|
57
|
|
|
{ |
58
|
|
|
$managers = $this->registry->getManagers(); |
59
|
|
|
$I->assertNotEmpty($managers); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testGetManagerWrongName(FunctionalTester $I) |
|
|
|
|
63
|
|
|
{ |
64
|
|
|
$I->expectException( |
65
|
|
|
new \InvalidArgumentException('Could not find Doctrine manager with name bar123'), |
66
|
|
|
function () { |
67
|
|
|
$this->registry->getManager('bar123'); |
68
|
|
|
} |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.