Repository navigation
Expand file tree
/
Copy pathBase.php
More file actions
116 lines (99 loc) · 3.46 KB
/
Copy pathBase.php
File metadata and controls
116 lines (99 loc) · 3.46 KB
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
<?php
namespace Codeception\Command;
use Codeception\Configuration;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
class Base extends Command
{
public function addStyles($output)
{
$style = new OutputFormatterStyle('white', 'green', array('bold'));
$output->getFormatter()->setStyle('notice', $style);
}
protected function buildPath($basePath, $testName)
{
$basePath = rtrim($basePath, DIRECTORY_SEPARATOR);
$testName = str_replace(array('/','\\'),array(DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR), $testName);
$path = $basePath.DIRECTORY_SEPARATOR.$testName;
$path = pathinfo($path, PATHINFO_DIRNAME).DIRECTORY_SEPARATOR;
if (!file_exists($path)) {
// Second argument should be mode. Well, umask() doesn't seem to return any if not set. Config may fix this.
mkdir($path, 0775, true); // Third parameter commands to create directories recursively
}
return $path;
}
protected function getClassName($class)
{
$namespaces = $this->breakParts($class);
return array_pop($namespaces);
}
protected function breakParts($class)
{
$class = str_replace('/', '\\', $class);
$namespaces = explode('\\', $class);
if (count($namespaces)) {
$namespaces[0] = ltrim($namespaces[0], '\\');
}
if (!$namespaces[0]) {
array_shift($namespaces);
} // remove empty namespace caused of \\
return $namespaces;
}
protected function completeSuffix($filename, $suffix)
{
if (strpos(strrev($filename), strrev($suffix)) === 0) {
$filename .= '.php';
}
if (strpos(strrev($filename), strrev($suffix . '.php')) !== 0) {
$filename .= $suffix . '.php';
}
if (strpos(strrev($filename), strrev('.php')) !== 0) {
$filename .= '.php';
}
return $filename;
}
protected function removeSuffix($classname, $suffix)
{
$classname = preg_replace('~\.php$~', '', $classname);
return preg_replace("~$suffix$~", '', $classname);
}
protected function save($filename, $contents, $force = false, $flags = null)
{
if (file_exists($filename) && !$force) {
return false;
}
file_put_contents($filename, $contents, $flags);
return true;
}
protected function getSuiteConfig($suite, $conf)
{
$config = Configuration::config($conf);
return Configuration::suiteSettings($suite, $config);
}
protected function getGlobalConfig($conf)
{
return Configuration::config($conf);
}
protected function getSuites($conf)
{
Configuration::config($conf);
return Configuration::suites();
}
protected function introduceAutoloader($file, $suffix, $relativePath)
{
$line = sprintf(
'\Codeception\Util\Autoload::registerSuffix(\'%s\', __DIR__.DIRECTORY_SEPARATOR.\'%s\');',
$suffix,
$relativePath
);
if (!file_exists($file)) {
return $this->save($file, "<?php \n" . $line);
}
$contents = file_get_contents($file);
if (preg_match('~Autoload::registerSuffix\([\'"]' . $suffix . '[\'"]~', $contents)) {
return false;
}
$contents .= "\n" . $line;
return $this->save($file, $contents, true);
}
}