Skip to content

Commit ed844eb

Browse files
committed
[DI] Add CSV env var processor tests
1 parent e85c74d commit ed844eb

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

EnvVarProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public function getEnv($prefix, $name, \Closure $getEnv)
236236
}
237237

238238
if ('csv' === $prefix) {
239-
return str_getcsv($env);
239+
return str_getcsv($env, ',', '"', \PHP_VERSION_ID >= 70400 ? '' : '\\');
240240
}
241241

242242
if ('trim' === $prefix) {

Tests/EnvVarProcessorTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,4 +478,37 @@ public function testRequireFile()
478478

479479
$this->assertEquals('foo', $result);
480480
}
481+
482+
/**
483+
* @dataProvider validCsv
484+
*/
485+
public function testGetEnvCsv($value, $processed)
486+
{
487+
$processor = new EnvVarProcessor(new Container());
488+
489+
$result = $processor->getEnv('csv', 'foo', function ($name) use ($value) {
490+
$this->assertSame('foo', $name);
491+
492+
return $value;
493+
});
494+
495+
$this->assertSame($processed, $result);
496+
}
497+
498+
public function validCsv()
499+
{
500+
$complex = <<<'CSV'
501+
,"""","foo""","\""",\,foo\
502+
CSV;
503+
504+
return [
505+
['', [null]],
506+
[',', ['', '']],
507+
['1', ['1']],
508+
['1,2," 3 "', ['1', '2', ' 3 ']],
509+
['\\,\\\\', ['\\', '\\\\']],
510+
[$complex, \PHP_VERSION_ID >= 70400 ? ['', '"', 'foo"', '\\"', '\\', 'foo\\'] : ['', '"', 'foo"', '\\"",\\,foo\\']],
511+
[null, null],
512+
];
513+
}
481514
}

0 commit comments

Comments
 (0)