1 | <?php |
||
25 | abstract class TestCase extends PHPUnitTestCase |
||
26 | { |
||
27 | /** |
||
28 | * Creates a Phile-core with bootstrap configuration for testing |
||
29 | * |
||
30 | * @param Event $event |
||
31 | * @param Config $config |
||
32 | * @return Phile configured core |
||
33 | */ |
||
34 | 30 | protected function createPhileCore(Event $event = null, Config $config = null) |
|
35 | { |
||
36 | //# setup Config |
||
37 | 30 | $config = $config ?: new Config; |
|
38 | 30 | if (!$config->has('encryptionKey')) { |
|
39 | 29 | $config->set('encryptionKey', 'testing'); |
|
40 | } |
||
41 | 30 | $testConfig = $config->toArray(); |
|
42 | |||
43 | //# setup container |
||
44 | 30 | Utility::load($config->get('config_dir') . '/container.php'); |
|
45 | |||
46 | 30 | $container = Container::getInstance(); |
|
47 | 30 | if ($event) { |
|
48 | 1 | $container->set('Phile_EventBus', $event); |
|
49 | } |
||
50 | |||
51 | //# setup bootstrap |
||
52 | 30 | $core = $container->get('Phile_App'); |
|
53 | 30 | $core->addBootstrap(function ($eventBus, $config) use ($testConfig) { |
|
54 | 29 | $configDir = $config->get('config_dir'); |
|
55 | 29 | Bootstrap::loadConfiguration($configDir . 'defaults.php', $config); |
|
56 | 29 | $config->merge($testConfig); |
|
57 | |||
58 | 29 | defined('CONTENT_DIR') || define('CONTENT_DIR', $config->get('content_dir')); |
|
59 | 29 | defined('CONTENT_EXT') || define('CONTENT_EXT', $config->get('content_ext')); |
|
60 | |||
61 | 29 | Event::setInstance($eventBus); |
|
|
|||
62 | |||
63 | 29 | Bootstrap::loadPlugins($eventBus, $config); |
|
64 | |||
65 | 29 | Registry::set('templateVars', []); |
|
66 | 30 | }); |
|
67 | |||
68 | //# setup middleware |
||
69 | 30 | $core->addMiddleware(function ($middleware, $eventBus, $config) use ($core) { |
|
70 | 6 | $eventBus->trigger('phile.core.middleware.add', ['middleware' => $middleware]); |
|
71 | 6 | $middleware->add($core); |
|
72 | 30 | }); |
|
73 | |||
74 | //# additional test setup |
||
75 | // clears out warnings of inefficient/multiple calls |
||
76 | 30 | \phpFastCache\CacheManager::clearInstances(); |
|
77 | |||
78 | 30 | return $core; |
|
79 | } |
||
80 | |||
81 | /** |
||
82 | * Run Phile and create response |
||
83 | */ |
||
84 | 6 | protected function createPhileResponse(Phile $app, ServerRequestInterface $request): ResponseInterface |
|
89 | |||
90 | /** |
||
91 | * Creates ServerRequest |
||
92 | * |
||
93 | * @param array $server $_SERVER environment |
||
94 | * @return ServerRequestInterface |
||
95 | */ |
||
96 | 17 | protected function createServerRequestFromArray(array $server = null): ServerRequestInterface |
|
104 | } |
||
105 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.