1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Zikula package. |
7
|
|
|
* |
8
|
|
|
* Copyright Zikula Foundation - https://ziku.la/ |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Zikula\CoreBundle\Tests\Helper; |
15
|
|
|
|
16
|
|
|
use PHPUnit\Framework\TestCase; |
|
|
|
|
17
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
18
|
|
|
use Zikula\Bundle\CoreBundle\Helper\LocalDotEnvHelper; |
19
|
|
|
|
20
|
|
|
class LocalDotEnvHelperTest extends TestCase |
21
|
|
|
{ |
22
|
|
|
private $projectDir; |
23
|
|
|
|
24
|
|
|
public function testWriteLocalEnvVars() |
25
|
|
|
{ |
26
|
|
|
$this->projectDir = dirname(__DIR__, 5) . '/var/cache/test/dotenvtest'; |
27
|
|
|
$fileSystem = new Filesystem(); |
28
|
|
|
$fileSystem->copy(__DIR__ . '/Fixture/.env.local', $this->projectDir . '/.env.local', true); |
29
|
|
|
$originalFileContents = trim($this->getFileContents()); |
30
|
|
|
$helper = new LocalDotEnvHelper($this->projectDir); |
31
|
|
|
|
32
|
|
|
$helper->writeLocalEnvVars([]); |
33
|
|
|
$this->assertEquals($originalFileContents, $this->getFileContents()); |
34
|
|
|
|
35
|
|
|
$helper->writeLocalEnvVars(['MY_NEW_VAR' => 'foo']); |
36
|
|
|
$expected = $originalFileContents . "\nMY_NEW_VAR=foo"; |
37
|
|
|
$this->assertEquals($expected, $this->getFileContents()); |
38
|
|
|
|
39
|
|
|
$helper->writeLocalEnvVars(['MY_NEW_VAR' => 'f#oo']); |
40
|
|
|
$expected = $originalFileContents . "\nMY_NEW_VAR=f%23oo"; |
41
|
|
|
$this->assertEquals($expected, $this->getFileContents()); |
42
|
|
|
|
43
|
|
|
$helper->writeLocalEnvVars(['MY_NEW_VAR' => '\'bar\'']); |
44
|
|
|
$expected = $originalFileContents . "\nMY_NEW_VAR='bar'"; |
45
|
|
|
$this->assertEquals($expected, $this->getFileContents()); |
46
|
|
|
|
47
|
|
|
$helper->writeLocalEnvVars(['MY_NEW_VAR' => 'foo', 'BAR' => 123], true); |
48
|
|
|
$expected = "MY_NEW_VAR=foo\nBAR=123"; |
49
|
|
|
$this->assertEquals($expected, $this->getFileContents()); |
50
|
|
|
|
51
|
|
|
$helper->writeLocalEnvVars(['MY_NEW_VAR' => '!f@oo', 'BAR' => '!1(2)3'], true); |
52
|
|
|
$expected = "MY_NEW_VAR=f@oo\nBAR=1(2)3"; |
53
|
|
|
$this->assertEquals($expected, $this->getFileContents()); |
54
|
|
|
|
55
|
|
|
$helper->writeLocalEnvVars(['MY_NEW_VAR' => '!\'f@oo\''], true); |
56
|
|
|
$expected = 'MY_NEW_VAR=\'f@oo\''; |
57
|
|
|
$this->assertEquals($expected, $this->getFileContents()); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
private function getFileContents(): string |
61
|
|
|
{ |
62
|
|
|
return file_get_contents($this->projectDir . '/.env.local'); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths