Skip to content

Commit 95c6cf2

Browse files
[2.x] Bugfix: Allowing @setup Variables into @servers (#272)
* code & test * changing assert of new test * using Str instead of str helper * fixing tests * remove the usage of Str
1 parent e64f6fb commit 95c6cf2

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

src/Compiler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ public function compileInclude($value)
272272
protected function compileServers($value)
273273
{
274274
$value = preg_replace_callback('/@servers\(\[(.*?)\]\)/s', function ($matches) {
275-
return '@servers(['.preg_replace('/\s+/', '', $matches[1]).'])';
275+
return '@servers(['.trim(preg_replace('/\s+/', ' ', $matches[1])).'])';
276276
}, $value);
277277

278278
$pattern = $this->createMatcher('servers');

tests/CompilerTest.php

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function test_it_compiles_server_statement()
4343
$compiler = new Compiler();
4444
$result = $compiler->compile($str);
4545

46-
$this->assertSame($result, "<?php \$__container->servers(['foo'=>'bar']); ?>");
46+
$this->assertSame($result, "<?php \$__container->servers(['foo' => 'bar']); ?>");
4747

4848
$str = <<<'EOL'
4949
@servers([
@@ -57,7 +57,7 @@ public function test_it_compiles_server_statement()
5757
$compiler = new Compiler();
5858
$result = $compiler->compile($str);
5959

60-
$this->assertSame($result, "<?php \$__container->servers(['foo'=>['bar','baz','bah']]); ?>");
60+
$this->assertSame($result, "<?php \$__container->servers(['foo' => [ 'bar', 'baz', 'bah' ]]); ?>");
6161

6262
$str = <<<'EOL'
6363
@servers([
@@ -68,14 +68,33 @@ public function test_it_compiles_server_statement()
6868
$compiler = new Compiler();
6969
$result = $compiler->compile($str);
7070

71-
$this->assertSame($result, "<?php \$__container->servers(['foo'=>['bar'],'bar'=>['baz']]); ?>");
71+
$this->assertSame($result, "<?php \$__container->servers(['foo' => ['bar'], 'bar' => ['baz']]); ?>");
7272

7373
$str = <<<'EOL'
7474
@servers(['foo' => 'bar'])
7575
EOL;
7676
$compiler = new Compiler();
7777
$result = $compiler->compile($str);
7878

79-
$this->assertSame($result, "<?php \$__container->servers(['foo'=>'bar']); ?>");
79+
$this->assertSame($result, "<?php \$__container->servers(['foo' => 'bar']); ?>");
80+
}
81+
82+
public function test_it_compiles_server_statement_with_setup()
83+
{
84+
$str = <<<'EOL'
85+
@setup
86+
$user = 'foo';
87+
$server = 'bar';
88+
$port = 22;
89+
@endsetup
90+
91+
@servers([
92+
'foo' => "{$user}@{$server} -p {$port}"
93+
])
94+
EOL;
95+
$compiler = new Compiler();
96+
$result = $compiler->compile($str);
97+
98+
$this->assertStringContainsString('{$user}@{$server} -p {$port}', $result);
8099
}
81100
}

0 commit comments

Comments
 (0)