Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[DI] Fix accepting null as default env param value#20512

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:masterfromnicolas-grekas:env-no-null
Nov 15, 2016
Merged
Show file tree
Hide file tree
Changes fromall 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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();
}
}

[8]ページ先頭

©2009-2025 Movatter.jp