Skip to content

Commit 55c1787

Browse files
committed
Support changing environments
1 parent 0a5180b commit 55c1787

File tree

3 files changed

+39
-11
lines changed

3 files changed

+39
-11
lines changed

bin/console

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
#!/usr/bin/env php
22
<?php
33

4-
$kernel = include __DIR__.'/../bootstrap/kernel_bootstrap.php';
4+
$rootDir = realpath(__DIR__.'/../../../..');
5+
$vendorDir = realpath($rootDir.'/vendor');
6+
require_once $vendorDir.'/symfony-cmf/testing/bootstrap/bootstrap.php';
57

68
use Symfony\Bundle\FrameworkBundle\Console\Application;
79
use Symfony\Component\Console\Input\ArgvInput;
810

11+
$input = new ArgvInput();
12+
$env = $input->getParameterOption(array('--env', '-e'), 'phpcr');
13+
14+
// must be placed after setting $env, because it's used in bootstrapping the
15+
// kernel
16+
$kernel = include __DIR__.'/../bootstrap/kernel_bootstrap.php';
17+
918
$application = new Application($kernel);
10-
$application->run();
19+
$application->run($input);

bootstrap/kernel_bootstrap.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
2-
$rootDir = realpath(__DIR__.'/../../../..');
3-
$vendorDir = realpath($rootDir.'/vendor');
2+
43
$phpUnitFile = $rootDir.'/phpunit.xml.dist';
54

65
if (!file_exists($phpUnitFile)) {
@@ -22,7 +21,6 @@
2221
));
2322
}
2423

25-
require_once $vendorDir.'/symfony-cmf/testing/bootstrap/bootstrap.php';
2624
require_once $kernelFile;
2725

28-
return new AppKernel('test', true);
26+
return new AppKernel($env, true);

src/Symfony/Cmf/Component/Testing/Functional/BaseTestCase.php

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,24 @@ abstract class BaseTestCase extends WebTestCase
88
{
99
protected $db;
1010
protected $dbManagers = array();
11-
protected $container;
11+
protected $settings = array();
12+
protected $containers = array();
13+
14+
protected function configure(array $options)
15+
{
16+
$this->settings = $options;
17+
}
1218

1319
public function getContainer()
1420
{
15-
if (null === $this->container) {
16-
$client = $this->createClient();
17-
$this->container = $client->getContainer();
21+
$hash = md5(serialize($this->settings));
22+
23+
if (!isset($this->containers[$hash])) {
24+
$client = $this->createClient($this->settings);
25+
$this->containers[$hash] = $client->getContainer();
1826
}
1927

20-
return $this->container;
28+
return $this->containers[$hash];
2129
}
2230

2331
public function db($type)
@@ -49,4 +57,17 @@ public function getDbManager($type)
4957

5058
return $this->getDbManager($type);
5159
}
60+
61+
/**
62+
* {@inheritDoc}
63+
*/
64+
protected static function createKernel(array $options = array())
65+
{
66+
// default environment is 'phpcr'
67+
if (!isset($options['environment'])) {
68+
$options['environment'] = 'phpcr';
69+
}
70+
71+
parent::createKernel($options);
72+
}
5273
}

0 commit comments

Comments
 (0)