|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
|
4
|
|
|
use Symfony\Bundle\FrameworkBundle\Console\Application; |
|
5
|
|
|
use Symfony\Component\Console\Output\BufferedOutput; |
|
6
|
|
|
|
|
7
|
|
|
abstract class CommandTest extends WebTestCase |
|
|
|
|
|
|
8
|
|
|
{ |
|
9
|
|
|
protected $dslDir; |
|
10
|
|
|
protected $targetBundle = 'EzPublishCoreBundle'; // it is always present :-) |
|
11
|
|
|
protected $leftovers = array(); |
|
12
|
|
|
|
|
13
|
|
|
protected $container; |
|
14
|
|
|
protected $app; |
|
15
|
|
|
protected $output; |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
public function __construct($name = null, array $data = array(), $dataName = '') |
|
19
|
|
|
{ |
|
20
|
|
|
parent::__construct($name, $data, $dataName); |
|
21
|
|
|
// seems like this can not be used outside of the constructor... |
|
22
|
|
|
$this->dslDir = __DIR__ . '/../dsl'; |
|
23
|
|
|
} |
|
24
|
|
|
protected function setUp() |
|
25
|
|
|
{ |
|
26
|
|
|
$this->container = $this->getContainer(); |
|
27
|
|
|
|
|
28
|
|
|
$this->app = new Application(static::$kernel); |
|
29
|
|
|
$this->app->setAutoExit(false); |
|
30
|
|
|
$this->output = new BufferedOutput(); |
|
31
|
|
|
$this->leftovers = array(); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
protected function tearDown() |
|
35
|
|
|
{ |
|
36
|
|
|
foreach($this->leftovers as $file) { |
|
37
|
|
|
unlink($file); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
// clean buffer, just in case... |
|
41
|
|
|
$this->output->fetch(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
protected function getContainer() |
|
|
|
|
|
|
45
|
|
|
{ |
|
46
|
|
|
if (null !== static::$kernel) { |
|
47
|
|
|
static::$kernel->shutdown(); |
|
48
|
|
|
} |
|
49
|
|
|
// run in our own test environment. Sf by default uses the 'test' one. We let phpunit.xml set it... |
|
50
|
|
|
$options = array( |
|
51
|
|
|
'environment' => $_SERVER['SYMFONY_ENV'] |
|
52
|
|
|
); |
|
53
|
|
|
static::$kernel = static::createKernel($options); |
|
54
|
|
|
static::$kernel->boot(); |
|
55
|
|
|
return static::$kernel->getContainer(); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.