bug #33744 [DI] Add CSV env var processor tests / support PHP 7.4 (ro0NL)
This PR was merged into the 4.3 branch.
Discussion
----------
[DI] Add CSV env var processor tests / support PHP 7.4
| Q | A
| ------------- | ---
| Branch? | 4.3
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | Fix #... <!-- prefix each issue number with "Fix #", if any -->
| License | MIT
| Doc PR | symfony/symfony-docs#... <!-- required for new features -->
Similar as #32051
Commits
-------
82f341864c
[DI] Add CSV env var processor tests
This commit is contained in:
commit
1fea53330d
@ -236,7 +236,7 @@ class EnvVarProcessor implements EnvVarProcessorInterface
|
||||
}
|
||||
|
||||
if ('csv' === $prefix) {
|
||||
return str_getcsv($env);
|
||||
return str_getcsv($env, ',', '"', \PHP_VERSION_ID >= 70400 ? '' : '\\');
|
||||
}
|
||||
|
||||
if ('trim' === $prefix) {
|
||||
|
@ -478,4 +478,37 @@ class EnvVarProcessorTest extends TestCase
|
||||
|
||||
$this->assertEquals('foo', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider validCsv
|
||||
*/
|
||||
public function testGetEnvCsv($value, $processed)
|
||||
{
|
||||
$processor = new EnvVarProcessor(new Container());
|
||||
|
||||
$result = $processor->getEnv('csv', 'foo', function ($name) use ($value) {
|
||||
$this->assertSame('foo', $name);
|
||||
|
||||
return $value;
|
||||
});
|
||||
|
||||
$this->assertSame($processed, $result);
|
||||
}
|
||||
|
||||
public function validCsv()
|
||||
{
|
||||
$complex = <<<'CSV'
|
||||
,"""","foo""","\""",\,foo\
|
||||
CSV;
|
||||
|
||||
return [
|
||||
['', [null]],
|
||||
[',', ['', '']],
|
||||
['1', ['1']],
|
||||
['1,2," 3 "', ['1', '2', ' 3 ']],
|
||||
['\\,\\\\', ['\\', '\\\\']],
|
||||
[$complex, \PHP_VERSION_ID >= 70400 ? ['', '"', 'foo"', '\\"', '\\', 'foo\\'] : ['', '"', 'foo"', '\\"",\\,foo\\']],
|
||||
[null, null],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user