Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow arrays parameters #216

Merged
merged 1 commit into from Jun 12, 2015
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -50,7 +50,11 @@ public function process(ProcessableInterface $processable, array $variables)
));
}

return $this->parameters->get($key);
if (is_array($value = $this->parameters->get($key))) {
return var_export($value, true);
}

return $value;
}, $value);
}
}
32 changes: 32 additions & 0 deletions tests/Nelmio/Alice/Fixtures/LoaderTest.php
Expand Up @@ -1502,6 +1502,38 @@ public function testParametersAreReplaced()
$this->assertEquals('user_alice', $user1->username);
}

public function testArrayParametersAreReplaced()
{
$res = $this->loadData([
self::USER => [
'user{1..5}' => [
'username' => '<randomElement(<{usernames}>)>',
],
],
], [
'parameters' => [
'usernames' => $usernames = ['Alice', 'Bob', 'Ogi'],
]
]);

$this->assertCount(5, $res);
foreach ($this->loader->getReferences() as $user) {
$this->assertInstanceOf(self::USER, $user);
$this->assertContains($user->username, $usernames);
}
}

public function testYamlArrayParametersAreProperlyInterpreted()
{
$res = $this->createLoader()->load(__DIR__ . '/../support/fixtures/array_parameters.yml');

$this->assertCount(5, $res);
foreach ($this->loader->getReferences() as $user) {
$this->assertInstanceOf(self::USER, $user);
$this->assertContains($user->username, ['Alice', 'Bob', 'Ogi']);
}
}

public function testBackslashes()
{
$loader = new Loader();
Expand Down
6 changes: 6 additions & 0 deletions tests/Nelmio/Alice/support/fixtures/array_parameters.yml
@@ -0,0 +1,6 @@
parameters:
usernames: ['Alice', 'Bob', 'Ogi']

Nelmio\Alice\support\models\User:
user{1..5}:
username: <randomElement(<{usernames}>)>