1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link https://github.com/old-town/workflow-zf2-dispatch |
4
|
|
|
* @author Malofeykin Andrey <[email protected]> |
5
|
|
|
*/ |
6
|
|
|
namespace OldTown\Workflow\ZF2\Dispatch\PhpUnit\Test; |
7
|
|
|
|
8
|
|
|
use Zend\Loader\AutoloaderFactory; |
9
|
|
|
use Zend\Loader\StandardAutoloader; |
10
|
|
|
use RuntimeException; |
11
|
|
|
|
12
|
|
|
error_reporting(E_ALL | E_STRICT); |
13
|
|
|
chdir(__DIR__); |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class Bootstrap |
17
|
|
|
* |
18
|
|
|
* @package OldTown\Workflow\ZF2\Dispatch\PhpUnit\Test |
19
|
|
|
*/ |
20
|
|
|
class Bootstrap |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Настройка тестов |
24
|
|
|
* |
25
|
|
|
* @throws \RuntimeException |
26
|
|
|
*/ |
27
|
|
|
public static function init() |
28
|
|
|
{ |
29
|
|
|
static::initAutoloader(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Инициализация автозагрузчика |
35
|
|
|
* |
36
|
|
|
* @return void |
37
|
|
|
* |
38
|
|
|
* @throws RuntimeException |
39
|
|
|
*/ |
40
|
|
|
protected static function initAutoloader() |
41
|
|
|
{ |
42
|
|
|
$vendorPath = static::findParentPath('vendor'); |
43
|
|
|
if (is_readable($vendorPath . '/autoload.php')) { |
44
|
|
|
|
45
|
|
|
/** @noinspection PhpIncludeInspection */ |
46
|
|
|
include $vendorPath . '/autoload.php'; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
if (!class_exists(AutoloaderFactory::class)) { |
50
|
|
|
$errMsg = 'Ошибка инициации автолоадеров'; |
51
|
|
|
throw new RuntimeException($errMsg); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
try { |
55
|
|
|
AutoloaderFactory::factory([ |
56
|
|
|
StandardAutoloader::class => [ |
57
|
|
|
'autoregister_zf' => true, |
58
|
|
|
'namespaces' => [ |
59
|
|
|
'OldTown\\Workflow\\ZF2\\Dispatch' => __DIR__ . '/../../src/', |
60
|
|
|
__NAMESPACE__ => __DIR__ . '/tests/', |
61
|
|
|
'OldTown\\Workflow\\ZF2\\Dispatch\\PhpUnit\\TestData' => __DIR__ . '/_files', |
62
|
|
|
] |
63
|
|
|
] |
64
|
|
|
]); |
65
|
|
|
} catch (\Exception $e) { |
66
|
|
|
$errMsg = 'Ошибка инициации автолоадеров'; |
67
|
|
|
throw new RuntimeException($errMsg, $e->getCode(), $e); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param $path |
73
|
|
|
* |
74
|
|
|
* @return bool|string |
75
|
|
|
*/ |
76
|
|
|
protected static function findParentPath($path) |
77
|
|
|
{ |
78
|
|
|
$dir = __DIR__; |
79
|
|
|
$previousDir = '.'; |
80
|
|
|
while (!is_dir($dir . '/' . $path)) { |
81
|
|
|
$dir = dirname($dir); |
82
|
|
|
if ($previousDir === $dir) { |
83
|
|
|
return false; |
84
|
|
|
} |
85
|
|
|
$previousDir = $dir; |
86
|
|
|
} |
87
|
|
|
return $dir . '/' . $path; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
Bootstrap::init(); |
92
|
|
|
|