1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace RDV\Bundle\MigrationBundle\Tests\Functional\Fixture; |
4
|
|
|
|
5
|
|
|
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle; |
6
|
|
|
use RDV\Bundle\MigrationBundle\RdvMigrationBundle; |
7
|
|
|
use Symfony\Bundle\FrameworkBundle\FrameworkBundle; |
8
|
|
|
use Symfony\Bundle\TwigBundle\TwigBundle; |
9
|
|
|
use Symfony\Component\Config\Loader\LoaderInterface; |
10
|
|
|
use Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest; |
11
|
|
|
|
12
|
|
|
class Kernel extends KernelForTest |
13
|
|
|
{ |
14
|
|
|
/** @var array */ |
15
|
|
|
protected $registrableBundles = array(); |
16
|
|
|
|
17
|
|
|
/** @var \Closure */ |
18
|
|
|
protected $configCallback; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* {@inheritdoc} |
22
|
|
|
*/ |
23
|
|
|
public function getCacheDir() |
24
|
|
|
{ |
25
|
|
|
$this->cacheDir = sys_get_temp_dir() . '/kernel' . mt_rand(); |
|
|
|
|
26
|
|
|
mkdir($this->cacheDir, 0755, true); |
27
|
|
|
return $this->cacheDir; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* {@inheritdoc} |
32
|
|
|
*/ |
33
|
|
|
protected function getContainerClass() |
34
|
|
|
{ |
35
|
|
|
return parent::getContainerClass() . mt_rand(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* {@inheritdoc} |
40
|
|
|
*/ |
41
|
|
|
public function registerBundles() |
42
|
|
|
{ |
43
|
|
|
$bundles = [ |
44
|
|
|
new FrameworkBundle(), |
45
|
|
|
new TwigBundle(), |
46
|
|
|
new DoctrineBundle(), |
47
|
|
|
new RdvMigrationBundle(), |
48
|
|
|
]; |
49
|
|
|
|
50
|
|
|
return array_merge($bundles, $this->registrableBundles); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param array $bundles |
55
|
|
|
* @return $this |
56
|
|
|
*/ |
57
|
|
|
public function setRegistrableBundles($bundles) |
58
|
|
|
{ |
59
|
|
|
$this->registrableBundles = $bundles; |
60
|
|
|
|
61
|
|
|
return $this; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param \Closure $callback |
66
|
|
|
* @return $this |
67
|
|
|
*/ |
68
|
|
|
public function setConfigCallback(\Closure $callback) |
69
|
|
|
{ |
70
|
|
|
$this->configCallback = $callback; |
71
|
|
|
|
72
|
|
|
return $this; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* {@inheritdoc} |
77
|
|
|
*/ |
78
|
|
|
public function registerContainerConfiguration(LoaderInterface $loader) |
79
|
|
|
{ |
80
|
|
|
$loader->load(__DIR__ . '/config.yml'); |
81
|
|
|
if (is_callable($this->configCallback)) { |
82
|
|
|
$loader->load($this->configCallback); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function __destruct() |
87
|
|
|
{ |
88
|
|
|
array_map('unlink', glob($this->cacheDir . '/*')); |
89
|
|
|
rmdir($this->cacheDir); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: