1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Axstrad Library. |
4
|
|
|
* |
5
|
|
|
* Copyright (c) 2015 Dan Kempster |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
* |
10
|
|
|
* Feel free to edit as you please, and have fun. |
11
|
|
|
* |
12
|
|
|
* @author Dan Kempster <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
namespace Axstrad\Bundle\UseCaseTestBundle\Test; |
15
|
|
|
|
16
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
17
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolverInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Axstrad\Bundle\UseCaseTestBundle\Test\UseCaseTestTrait |
21
|
|
|
*/ |
22
|
|
|
trait UseCaseTestTrait |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
*/ |
26
|
6 |
|
protected static function getKernelClass() |
27
|
|
|
{ |
28
|
6 |
|
return 'Axstrad\Bundle\UseCaseTestBundle\Kernel\MultiUseCaseKernel'; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Creates a Kernel. |
33
|
|
|
* |
34
|
|
|
* Available options: |
35
|
|
|
* |
36
|
|
|
* * environment |
37
|
|
|
* * debug |
38
|
|
|
* * root_dir |
39
|
|
|
* |
40
|
|
|
* @param array $options An array of options |
41
|
|
|
* |
42
|
|
|
* @return \Symfony\Component\HttpKernel\Kernel A Kernel instance |
43
|
|
|
*/ |
44
|
9 |
|
protected static function createKernel(array $options = array()) |
45
|
|
|
{ |
46
|
9 |
|
static::$class = static::getKernelClass(); |
47
|
|
|
|
48
|
|
|
// ## Resolve the options |
49
|
9 |
|
$resolver = new OptionsResolver; |
50
|
|
|
|
51
|
|
|
// Use the Kernel's configureOptions method first |
52
|
9 |
|
call_user_func(static::$class.'::configureOptions', $resolver); |
53
|
|
|
// Now use out own |
54
|
9 |
|
static::configureKernelOptions($resolver); |
55
|
|
|
|
56
|
|
|
// Resikve the options and split out the Kernel only options. |
57
|
9 |
|
$options = $resolver->resolve($options); |
58
|
9 |
|
$kernelOptions = array_diff_key($options, array_flip(array('environment', 'debug'))); |
59
|
|
|
|
60
|
|
|
// ## Create the Kernel |
61
|
9 |
|
return new static::$class( |
62
|
9 |
|
$options['environment'], |
63
|
9 |
|
$options['debug'], |
64
|
|
|
$kernelOptions |
65
|
9 |
|
); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Define this method to configure the OptionsResolver. |
70
|
|
|
* |
71
|
|
|
* @param OptionsResolverInterface $resolver |
72
|
|
|
* @return void |
73
|
|
|
*/ |
74
|
9 |
|
public static function configureKernelOptions(OptionsResolverInterface $resolver) |
75
|
|
|
{ |
76
|
|
|
$resolver |
77
|
9 |
|
->setRequired(array( |
78
|
9 |
|
'tmp_dir', |
79
|
9 |
|
)) |
80
|
9 |
|
->setDefaults(array( |
81
|
9 |
|
'environment' => 'test', |
82
|
9 |
|
'debug' => true, |
83
|
9 |
|
'use_case' => static::$useCase, |
84
|
9 |
|
'tmp_dir' => static::getPhpUnitXmlDir().DIRECTORY_SEPARATOR.implode(DIRECTORY_SEPARATOR, array('build', 'tmp')), |
85
|
9 |
|
)) |
86
|
9 |
|
->setAllowedTypes(array( |
87
|
9 |
|
'debug' => 'bool', |
88
|
9 |
|
)) |
89
|
|
|
; |
90
|
9 |
|
} |
91
|
|
|
} |
92
|
|
|
|