1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use org\bovigo\vfs\vfsStream; |
4
|
|
|
use org\bovigo\vfs\vfsStreamWrapper; |
5
|
|
|
use WebinoBase\Filesystem\Path\BaseModulePath; |
6
|
|
|
use WebinoDev\Test\TestCase; |
7
|
|
|
use Zend\Mvc\Application; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Create a PHPUnit test case |
11
|
|
|
* |
12
|
|
|
* For mocking and legacy PHPUnit tests. |
13
|
|
|
* |
14
|
|
|
* @return TestCase |
15
|
|
|
*/ |
16
|
|
|
function createTestCase() |
17
|
|
|
{ |
18
|
|
|
return new TestCase; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Application factory |
23
|
|
|
*/ |
24
|
|
|
function createApp() { |
25
|
|
|
|
26
|
|
|
// WebinoBase module support |
27
|
|
|
if (class_exists(BaseModulePath::class)) { |
28
|
|
|
/** @noinspection PhpIncludeInspection */ |
29
|
|
|
require (new BaseModulePath) . '/inc/app.php'; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
// common initialization |
33
|
|
|
/** @noinspection PhpIncludeInspection */ |
34
|
|
|
return Application::init(require 'config/application.config.php'); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Create a virtual filesystem |
39
|
|
|
* |
40
|
|
|
* @param array $structure |
41
|
|
|
*/ |
42
|
|
|
function createVfs(array $structure) |
43
|
|
|
{ |
44
|
|
|
vfsStreamWrapper::register(); |
45
|
|
|
vfsStreamWrapper::setRoot(vfsStream::setup('root', null, $structure)); |
46
|
|
|
set_include_path(vfsStream::url('root')); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Create a temporary directory |
51
|
|
|
* |
52
|
|
|
* @return string |
53
|
|
|
*/ |
54
|
|
|
function createTmpDir() |
55
|
|
|
{ |
56
|
|
|
$dir = __DIR__ . '/tmp/' . getmypid(); |
57
|
|
|
// @ - directory may already exist |
58
|
|
|
@mkdir(dirname($dir)); |
59
|
|
|
Tester\Helpers::purge($dir); |
60
|
|
|
return $dir; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Return output buffer contents |
65
|
|
|
* |
66
|
|
|
* @param callable $callback |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
|
|
function catchOutput(callable $callback) |
70
|
|
|
{ |
71
|
|
|
ob_start(); |
72
|
|
|
call_user_func($callback); |
73
|
|
|
return trim(ob_get_clean()); |
74
|
|
|
} |
75
|
|
|
|