[DI] Add CSV env var processor tests
This commit is contained in:
parent
fbfdebc487
commit
82f341864c
@ -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