Skip to content

Commit cbbee44

Browse files
committed
Update for travis
1 parent ab92452 commit cbbee44

14 files changed

+53
-58
lines changed

.travis.yml

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
language: php
2-
dist: trusty
3-
sudo: false
42

53
php:
6-
- 7.0
7-
- 7.1
8-
- 7.2
9-
- hhvm
4+
- 5.3
5+
- 5.4
6+
- 5.5
7+
- 5.6
8+
- hhvm
109

11-
matrix:
12-
include:
13-
- php: 7.0
14-
dist: trusty
10+
before_script:
11+
- travis_retry composer self-update
12+
- travis_retry composer install --no-interaction --prefer-source --dev
13+
14+
script:
15+
- vendor/bin/phpunit --coverage-clover=coverage.xml
1516

16-
install: travis_retry composer install --no-interaction --prefer-source
1717

18-
script: vendor/bin/phpunit

Tests/EnveditorTest.php

-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ protected function setUp()
1919
{
2020
$this->tmpPathEnv = sys_get_temp_dir() . self::DS . 'EnveditorTestEnv.env';
2121

22-
echo 'PATH: '.$this->tmpPathEnv.PHP_EOL;
23-
2422
if (!touch($this->tmpPathEnv)) {
2523
throw new \RuntimeException(sprintf('A test failed. Could not write a file to "%s" path', $this->tmpPathEnv));
2624
}

Tests/EnvparserTest.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function testEnvSpecial()
114114
$envfile = $this->getFileTest('special.env');
115115

116116
$envparser = new Envparser($envfile);
117-
$envparserLoader = $envparser->load();
117+
$envparser->load();
118118

119119
$envparser->run();
120120

@@ -133,7 +133,7 @@ public function testAssertException()
133133
$envfile = $this->getFileTest('exception.env');
134134

135135
$envparser = new Envparser($envfile);
136-
$envparserLoader = $envparser->load();
136+
$envparser->load();
137137

138138
$envparser->run();
139139

@@ -145,7 +145,7 @@ public function testEnvExportsSetenv()
145145
$envfile = $this->getFileTest('export_setenv.env');
146146

147147
$envparser = new Envparser($envfile);
148-
$envparserLoader = $envparser->load();
148+
$envparser->load();
149149

150150
$envparser->run();
151151

@@ -168,7 +168,7 @@ public function testAssertExceptionVariable()
168168
$envfile = $this->getFileTest('invalidvar.env');
169169

170170
$envparser = new Envparser($envfile);
171-
$envparserLoader = $envparser->load();
171+
$envparser->load();
172172

173173
$envparser->run();
174174

@@ -180,7 +180,7 @@ public function testEnvExportsServerVariables()
180180
$envfile = $this->getFileTest('export_setenv.env');
181181

182182
$envparser = new Envparser($envfile);
183-
$envparserLoader = $envparser->load();
183+
$envparser->load();
184184

185185
$envparser->run();
186186

@@ -200,7 +200,7 @@ public function testEnvExportsEnvVariables()
200200
$envfile = $this->getFileTest('export_setenv.env');
201201

202202
$envparser = new Envparser($envfile);
203-
$envparserLoader = $envparser->load();
203+
$envparser->load();
204204

205205
$envparser->run();
206206

Tests/bootstrap.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111
/**
1212
* Autoloader
1313
*/
14-
require __DIR__.'../../../../../vendor/autoload.php';
14+
// require __DIR__.'../../../../../vendor/autoload.php';
15+
require __DIR__ .'/../../../vendor/autoload.php';

src/Abstractparser/Envabstract.php

+4-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Codervio\Envmanager\Abstractparser;
44

55
use Codervio\Envmanager\Parser\ParserCollector;
6-
use Exception;
76

87
abstract class Envabstract
98
{
@@ -18,7 +17,7 @@ protected function parseEncoding($data)
1817
}
1918

2019
if (!in_array($this->fileEncoding, mb_list_encodings())) {
21-
throw new Exception(sprintf('Encoding "%s" not found. Check supported encoding using mb_list_encoding() function or use mostly UTF-8 encoding type', $this->fileEncoding));
20+
throw new \Exception(sprintf('Encoding "%s" not found. Check supported encoding using mb_list_encoding() function or use mostly UTF-8 encoding type', $this->fileEncoding));
2221
}
2322

2423
return mb_convert_encoding($data, $this->fileEncoding, 'auto');
@@ -64,8 +63,7 @@ protected function processEnvironment($values)
6463

6564
if (function_exists('apache_getenv')) {
6665
if (!apache_getenv($envkey, false)) {
67-
/** @scrutinizer ignore-unhandled */
68-
@apache_setenv($envkey, $envvalue, false);
66+
/** @scrutinizer ignore-unhandled */ @apache_setenv($envkey, $envvalue, false);
6967
}
7068
}
7169

@@ -78,8 +76,7 @@ protected function processEnvironment($values)
7876

7977
$_SERVER[$envkey] = $envvalue;
8078
if (function_exists('apache_setenv')) {
81-
/** @scrutinizer ignore-unhandled */
82-
@apache_setenv($envkey, $envvalue, false);
79+
/** @scrutinizer ignore-unhandled */ @apache_setenv($envkey, $envvalue, false);
8380
}
8481

8582
}
@@ -94,7 +91,7 @@ protected function parseLines() : ParserCollector
9491
}
9592

9693
if (empty($this->parser->arr->getArrayCopy())) {
97-
return null;
94+
return $this->parsercollector;
9895
}
9996

10097
foreach ($this->parser->arr->getArrayCopy() as $key => $line) {

src/Editor/EnvWriter.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class EnvWriter
1313

1414
protected $forceclear = false;
1515

16+
private $formatter;
17+
1618
public function __construct()
1719
{
1820
$this->arr = new ArrayStore();
@@ -30,6 +32,10 @@ public function set($buffer)
3032

3133
public function clearBuffer()
3234
{
35+
if (empty($this->arr->getArrayCopy())) {
36+
return;
37+
}
38+
3339
if (is_array($this->arr->getArrayCopy())) {
3440
foreach ($this->arr->getArrayCopy() as $index => $value) {
3541
$this->arr->offsetUnset($index);
@@ -77,9 +83,7 @@ public function put($key, $value = null, $comment = null, $export = false)
7783
{
7884
$packArray = compact('key', 'value', 'comment', 'export');
7985

80-
$result = $this->formatter->setKeys($packArray);
81-
82-
$this->arr->offsetSet($key, $result);
86+
$this->arr->offsetSet($key, $this->formatter->setKeys($packArray));
8387
}
8488

8589
public function appendComment($comment)

src/Envparser.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class Envparser extends Envabstract
3434
protected $override = false;
3535

3636
protected $systemparser = array();
37+
protected $keyresolver;
38+
protected $parser;
3739

3840
private $result;
3941

@@ -107,7 +109,7 @@ public function checkSuperGlobalsSet()
107109
if (ini_get('variables_order') === '' || strpos(ini_get('variables_order'), 'G')) {
108110
return true;
109111
} else {
110-
throw new RuntimeException('Warning: Set and create globals for $_ENV is disabled. To enable globally, for console run: \'php -d variables_order=EGPCS php.php\' or set in php.ini directive: variables_order=EGPCS');
112+
throw new \RuntimeException('Warning: Set and create globals for $_ENV is disabled. To enable globally, for console run: \'php -d variables_order=EGPCS php.php\' or set in php.ini directive: variables_order=EGPCS');
111113
}
112114
}
113115

src/Loader/Loader.php

+3-8
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ public function __construct($path, $extension)
1818
$this->extension = $extension;
1919
}
2020

21-
private function checkExtension()
22-
{
23-
//todo
24-
}
25-
2621
public function getLoadStatus()
2722
{
2823
return !empty($this->filepath);
@@ -41,14 +36,14 @@ public function run()
4136

4237
$path = glob($this->filepath);
4338

44-
if (!is_array($path)) {
39+
if (empty($path) || !$path) {
4540
$this->isloaded = false;
4641
return false;
4742
}
4843

49-
foreach ($path as $file)
44+
foreach ($path as $filemain)
5045
{
51-
$fileInfo = pathinfo($file);
46+
$fileInfo = pathinfo($filemain);
5247

5348
$pathInfo = $fileInfo['dirname'].DIRECTORY_SEPARATOR.$fileInfo['basename'];
5449

src/Parser/Parser.php

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public function explodeLines($data)
3434
$this->cleanLine($key, $val);
3535

3636
}
37+
} else {
38+
return;
3739
}
3840
}
3941

src/Parser/ValueParser.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class ValueParser
66
{
77
public function parse($input, $strict)
88
{
9-
$input = $this->parseEmpty($input, $strict);
9+
$input = $this->parseEmpty($input);
1010
$input = $this->parseFloat($input);
1111
$input = $this->parseNumeric($input);
1212
$input = $this->parseBool($input, $strict);

src/Prerequisities.php

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Codervio\Envmanager;
44

5+
use RuntimeException;
6+
57
class Prerequisities
68
{
79
public function __construct()

src/Resolver/ValueResolver.php

-15
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ public function execute($value, $strict)
3030
*/
3131
$value = trim($value);
3232

33-
/**
34-
* Check 'abc' or "abc"
35-
*/
36-
//$result = $this->checkInvalidSign($result);
37-
3833
/**
3934
* Trim empty '' or ""
4035
*/
@@ -117,16 +112,6 @@ private function trimNewLines($result)
117112
return str_replace(array(self::UNIX_NL, self::DOS_NL, self::MAC_NL), '', $result);
118113
}
119114

120-
private function checkInvalidSign($value)
121-
{
122-
if (preg_match(self::INVALID_PREG, $value)) {
123-
124-
throw new ValueException(sprintf("Invalid format type: %s", $value));
125-
}
126-
127-
return $value;
128-
}
129-
130115
private function trimClosers($input)
131116
{
132117
$input = preg_replace('/^\'|\'$/', '', $input);

src/Resolver/ValueResolverInterface.php

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
interface ValueResolverInterface
66
{
7-
const INVALID_PREG = '/(^(\')+[a-z]+$)|(^[a-z]+(\')$)|(^(\")+[a-z]+$)|(^[a-z]+(\")$)/u';
87
const CLOSERS = '/^[\'"](.*)[\'"]/i';
98
const CLOSURE_MATCH = '/\"(.*)\s+(.*)\"/i';
109

src/Resolver/VariableResolver.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,21 @@ public function parseSystemEnvironmentVariables($value)
2323
$origin = $match[0];
2424
$nameVar = $match[1];
2525

26-
if (getenv($nameVar)) {
26+
if (!getenv($nameVar)) {
27+
// skip
28+
}
29+
30+
if ($arr = is_array(getenv($nameVar))) {
31+
foreach ($arr as $envValue) {
32+
$value = str_replace($origin, $envValue, $value);
33+
}
2734

35+
} elseif (getenv($nameVar)) {
2836
$value = str_replace($origin, getenv($nameVar), $value);
2937

38+
} else {
39+
return $value;
40+
3041
}
3142
}
3243

0 commit comments

Comments
 (0)