Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function resolve()
}
if (is_numeric($default = $this->parameters[$name])) {
$this->parameters[$name] = (string) $default;
} elseif (!is_string($default)) {
} elseif (null !== $default && !is_string($default)) {
throw new RuntimeException(sprintf('The default value of env parameter "%s" must be string or null, %s given.', $env, gettype($default)));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,21 +113,30 @@ public function testMergeWithDifferentIdentifiersForPlaceholders()
public function testResolveEnvCastsIntToString()
{
$bag = new EnvPlaceholderParameterBag();
$bag->get('env(INT)');
$bag->set('env(INT)', 2);
$bag->get('env(INT_VAR)');
$bag->set('env(Int_Var)', 2);
$bag->resolve();
$this->assertSame('2', $bag->all()['env(int)']);
$this->assertSame('2', $bag->all()['env(int_var)']);
}

public function testResolveEnvAllowsNull()
{
$bag = new EnvPlaceholderParameterBag();
$bag->get('env(NULL_VAR)');
$bag->set('env(Null_Var)', null);
$bag->resolve();
$this->assertNull($bag->all()['env(null_var)']);
}

/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
* @expectedExceptionMessage The default value of env parameter "ARRAY" must be string or null, array given.
* @expectedExceptionMessage The default value of env parameter "ARRAY_VAR" must be string or null, array given.
*/
public function testResolveThrowsOnBadDefaultValue()
{
$bag = new EnvPlaceholderParameterBag();
$bag->get('env(ARRAY)');
$bag->set('env(ARRAY)', array());
$bag->get('env(ARRAY_VAR)');
$bag->set('env(Array_Var)', array());
$bag->resolve();
}
}