-
Notifications
You must be signed in to change notification settings - Fork 205
/
TestContainerFactory.php
52 lines (43 loc) · 1.69 KB
/
TestContainerFactory.php
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
<?php declare(strict_types=1);
/**
* Copyright © OXID eSales AG. All rights reserved.
* See LICENSE file for license details.
*/
namespace OxidEsales\EshopCommunity\Tests\Integration\Internal;
use OxidEsales\EshopCommunity\Internal\Application\ContainerBuilder;
use OxidEsales\Facts\Facts;
use Symfony\Component\DependencyInjection\ContainerBuilder as SymfonyContainerBuilder;
/**
* @internal
*/
class TestContainerFactory
{
public function create(): SymfonyContainerBuilder
{
$containerBuilder = new ContainerBuilder(new Facts());
$container = $containerBuilder->getContainer();
$container = $this->setAllServicesAsPublic($container);
$container = $this->setTestProjectConfigurationFile($container);
return $container;
}
private function setAllServicesAsPublic(SymfonyContainerBuilder $container): SymfonyContainerBuilder
{
foreach ($container->getDefinitions() as $definition) {
$definition->setPublic(true);
}
return $container;
}
private function setTestProjectConfigurationFile(SymfonyContainerBuilder $container): SymfonyContainerBuilder
{
$projectConfigurationYmlStorageDefinition = $container->getDefinition('oxid_esales.module.configuration.project_configuration_yaml_file_storage');
$projectConfigurationYmlStorageDefinition->setArgument(
'$filePath',
tempnam(sys_get_temp_dir() . '/test_project_configuration', 'test_')
);
$container->setDefinition(
'oxid_esales.module.configuration.project_configuration_yaml_file_storage',
$projectConfigurationYmlStorageDefinition
);
return $container;
}
}