Completed
Push — develop ( d1baa7...5a0a71 )
by Peter
11:28
created

functions.php ➔ catchOutput()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 4
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 6
rs 9.4285
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