forked from kenjis/ci-phpunit-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstaller.php
117 lines (104 loc) · 3.28 KB
/
Installer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
/**
* Part of CI PHPUnit Test
*
* @author Kenji Suzuki <https://github.com/kenjis>
* @license MIT License
* @copyright 2015 Kenji Suzuki
* @link https://github.com/kenjis/ci-phpunit-test
*/
class Installer
{
const TEST_FOLDER = 'application/tests';
public static function install()
{
self::recursiveCopy(
'vendor/kenjis/ci-phpunit-test/application/tests',
static::TEST_FOLDER
);
self::fixPath();
}
/**
* Fix paths in Bootstrap.php
*/
private static function fixPath()
{
$file = static::TEST_FOLDER . '/Bootstrap.php';
$contents = file_get_contents($file);
if (! file_exists('system')) {
if (file_exists('vendor/codeigniter/framework/system')) {
$contents = str_replace(
'$system_path = \'../../system\';',
'$system_path = \'../../vendor/codeigniter/framework/system\';',
$contents
);
} else {
throw new Exception('Can\'t find "system" folder.');
}
}
if (! file_exists('index.php')) {
if (file_exists('public/index.php')) {
$contents = str_replace(
"define('FCPATH', realpath(dirname(__FILE__).'/../..').'/');",
"define('FCPATH', realpath(dirname(__FILE__).'/../../public').'/');",
$contents
);
} else {
throw new Exception('Can\'t find "index.php".');
}
}
file_put_contents($file, $contents);
}
public static function update()
{
self::recursiveUnlink('application/tests/_ci_phpunit_test');
self::recursiveCopy(
'vendor/kenjis/ci-phpunit-test/application/tests/_ci_phpunit_test',
'application/tests/_ci_phpunit_test'
);
}
/**
* Recursive Copy
*
* @param string $src
* @param string $dst
*/
private static function recursiveCopy($src, $dst)
{
@mkdir($dst, 0755);
$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($src, \RecursiveDirectoryIterator::SKIP_DOTS),
\RecursiveIteratorIterator::SELF_FIRST
);
foreach ($iterator as $file) {
if ($file->isDir()) {
@mkdir($dst . '/' . $iterator->getSubPathName());
} else {
$success = copy($file, $dst . '/' . $iterator->getSubPathName());
if ($success) {
echo 'copied: ' . $dst . '/' . $iterator->getSubPathName() . PHP_EOL;
}
}
}
}
/**
* Recursive Unlink
*
* @param string $dir
*/
private static function recursiveUnlink($dir)
{
$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS),
\RecursiveIteratorIterator::CHILD_FIRST
);
foreach ($iterator as $file) {
if ($file->isDir()) {
rmdir($file);
} else {
unlink($file);
}
}
rmdir($dir);
}
}