1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Visithor package. |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
* |
9
|
|
|
* Feel free to edit as you please, and have fun. |
10
|
|
|
* |
11
|
|
|
* @author Marc Morera <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Visithor\Bundle\Environment; |
15
|
|
|
|
16
|
|
|
use Symfony\Bundle\FrameworkBundle\Console\Application; |
17
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
18
|
|
|
use Symfony\Component\HttpKernel\KernelInterface; |
19
|
|
|
|
20
|
|
|
use Visithor\Bundle\Environment\Interfaces\EnvironmentBuilderInterface; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Class SymfonyEnvironmentBuilder |
24
|
|
|
*/ |
25
|
|
|
class SymfonyEnvironmentBuilder implements EnvironmentBuilderInterface |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var Application |
29
|
|
|
* |
30
|
|
|
* Application |
31
|
|
|
*/ |
32
|
|
|
protected $application; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Set up environment |
36
|
|
|
* |
37
|
|
|
* @param KernelInterface $kernel Kernel |
38
|
|
|
* |
39
|
|
|
* @return $this Self object |
40
|
|
|
*/ |
41
|
|
|
public function setUp(KernelInterface $kernel) |
42
|
|
|
{ |
43
|
|
|
$this->application = new Application($kernel); |
44
|
|
|
$this->application->setAutoExit(false); |
45
|
|
|
|
46
|
|
|
$this |
47
|
|
|
->executeCommand('doctrine:database:drop', [ |
48
|
|
|
'--force' => true, |
49
|
|
|
]) |
50
|
|
|
->executeCommand('doctrine:database:create') |
51
|
|
|
->executeCommand('doctrine:schema:create'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Tear down environment |
56
|
|
|
* |
57
|
|
|
* @param KernelInterface $kernel Kernel |
58
|
|
|
* |
59
|
|
|
* @return $this Self object |
60
|
|
|
*/ |
61
|
|
|
public function tearDown(KernelInterface $kernel) |
62
|
|
|
{ |
63
|
|
|
$this |
64
|
|
|
->executeCommand('doctrine:database:drop', [ |
65
|
|
|
'--force' => true, |
66
|
|
|
]); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Get authenticated user |
71
|
|
|
* |
72
|
|
|
* @param string $role Role |
73
|
|
|
* |
74
|
|
|
* @return mixed User for authentication |
75
|
|
|
*/ |
76
|
|
|
public function getAuthenticationUser($role) |
77
|
|
|
{ |
78
|
|
|
return 'admin'; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Execute a command |
83
|
|
|
* |
84
|
|
|
* @param string $command Command |
85
|
|
|
* @param array $parameters Parameters |
86
|
|
|
* |
87
|
|
|
* @return $this Self object |
88
|
|
|
*/ |
89
|
|
|
protected function executeCommand( |
90
|
|
|
$command, |
91
|
|
|
array $parameters = [] |
92
|
|
|
) { |
93
|
|
|
$environment = $this |
94
|
|
|
->application |
95
|
|
|
->getKernel() |
96
|
|
|
->getEnvironment(); |
97
|
|
|
|
98
|
|
|
$this |
99
|
|
|
->application |
100
|
|
|
->run(new ArrayInput(array_merge( |
101
|
|
|
[ |
102
|
|
|
'command' => $command, |
103
|
|
|
'--no-interaction' => true, |
104
|
|
|
'--env' => $environment, |
105
|
|
|
'--quiet' => true, |
106
|
|
|
], $parameters |
107
|
|
|
))); |
108
|
|
|
|
109
|
|
|
return $this; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|