forked from liip/LiipTestFixturesBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigPhpcrTest.php
More file actions
124 lines (100 loc) · 3.45 KB
/
ConfigPhpcrTest.php
File metadata and controls
124 lines (100 loc) · 3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
declare(strict_types=1);
/*
* This file is part of the Liip/TestFixturesBundle
*
* (c) Lukas Kahwe Smith <smith@pooteeweet.org>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Liip\Acme\Tests\Test;
use Doctrine\Bundle\PHPCRBundle\DoctrinePHPCRBundle;
use Doctrine\DBAL\Logging\Connection as DBALLoggingConnection;
use Doctrine\ORM\Tools\SchemaTool;
use Liip\Acme\Tests\AppConfigPhpcr\AppConfigPhpcrKernel;
use Liip\Acme\Tests\Traits\ContainerProvider;
use Liip\TestFixturesBundle\Services\DatabaseToolCollection;
use Liip\TestFixturesBundle\Services\DatabaseTools\AbstractDatabaseTool;
use Liip\TestFixturesBundle\Services\DatabaseTools\PHPCRDatabaseTool;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
/**
* Test PHPCR.
*
* Use Tests/AppConfigPhpcr/AppConfigMysqlKernel.php instead of
* Tests/App/AppKernel.php.
* So it must be loaded in a separate process.
*
* @runTestsInSeparateProcesses
*
* @preserveGlobalState disabled
*
* @internal
*/
class ConfigPhpcrTest extends FixturesTestCase
{
use ContainerProvider;
/** @var AbstractDatabaseTool */
protected $databaseTool;
protected function setUp(): void
{
if (!class_exists(DoctrinePHPCRBundle::class)) {
$this->markTestSkipped('Need doctrine/phpcr-bundle package.');
}
if (class_exists(DBALLoggingConnection::class)) {
$this->markTestSkipped('Jackalope won\'t work if Doctrine\DBAL\Logging\Connection is provided by Doctrine.');
}
parent::setUp();
self::bootKernel([
'environment' => 'phpcr',
]);
$entityManager = $this->getTestContainer()->get('doctrine')->getManager();
$this->databaseTool = $this->getTestContainer()->get(DatabaseToolCollection::class)->get('default', 'doctrine_phpcr');
$this->assertInstanceOf(PHPCRDatabaseTool::class, $this->databaseTool);
$metadata = $entityManager->getMetadataFactory()->getAllMetadata();
$schemaTool = new SchemaTool($entityManager);
$schemaTool->dropDatabase();
if (!empty($metadata)) {
$schemaTool->createSchema($metadata);
}
$this->initRepository();
}
public function testLoadFixturesPhPCr(): void
{
$fixtures = $this->databaseTool->loadFixtures([
'Liip\Acme\Tests\AppConfigPhpcr\DataFixtures\PHPCR\LoadTaskData',
]);
$this->assertInstanceOf(
'Doctrine\Bundle\PHPCRBundle\DataFixtures\PHPCRExecutor',
$fixtures
);
$repository = $fixtures->getReferenceRepository();
$this->assertInstanceOf(
'Doctrine\Common\DataFixtures\ProxyReferenceRepository',
$repository
);
}
protected static function getKernelClass(): string
{
return AppConfigPhpcrKernel::class;
}
/**
* Define the PHPCR root, used in fixtures.
*/
private function initRepository(): void
{
$kernel = static::$kernel;
$application = new Application($kernel);
$command = $application->find('doctrine:phpcr:repository:init');
$commandTester = new CommandTester($command);
$commandTester->execute(
['command' => $command->getName()]
);
}
protected function tearDown(): void
{
parent::tearDown();
unset($this->databaseTool);
}
}