Skip to content

Commit

Permalink
[2.x] Bugfix: Allowing @setup Variables into @servers (#272)
Browse files Browse the repository at this point in the history
* code & test

* changing assert of new test

* using Str instead of str helper

* fixing tests

* remove the usage of Str
  • Loading branch information
devajmeireles authored Jan 6, 2024
1 parent e64f6fb commit 95c6cf2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public function compileInclude($value)
protected function compileServers($value)
{
$value = preg_replace_callback('/@servers\(\[(.*?)\]\)/s', function ($matches) {
return '@servers(['.preg_replace('/\s+/', '', $matches[1]).'])';
return '@servers(['.trim(preg_replace('/\s+/', ' ', $matches[1])).'])';
}, $value);

$pattern = $this->createMatcher('servers');
Expand Down
27 changes: 23 additions & 4 deletions tests/CompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function test_it_compiles_server_statement()
$compiler = new Compiler();
$result = $compiler->compile($str);

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

$str = <<<'EOL'
@servers([
Expand All @@ -57,7 +57,7 @@ public function test_it_compiles_server_statement()
$compiler = new Compiler();
$result = $compiler->compile($str);

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

$str = <<<'EOL'
@servers([
Expand All @@ -68,14 +68,33 @@ public function test_it_compiles_server_statement()
$compiler = new Compiler();
$result = $compiler->compile($str);

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

$str = <<<'EOL'
@servers(['foo' => 'bar'])
EOL;
$compiler = new Compiler();
$result = $compiler->compile($str);

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

public function test_it_compiles_server_statement_with_setup()
{
$str = <<<'EOL'
@setup
$user = 'foo';
$server = 'bar';
$port = 22;
@endsetup
@servers([
'foo' => "{$user}@{$server} -p {$port}"
])
EOL;
$compiler = new Compiler();
$result = $compiler->compile($str);

$this->assertStringContainsString('{$user}@{$server} -p {$port}', $result);
}
}

0 comments on commit 95c6cf2

Please sign in to comment.