Skip to content

Commit

Permalink
Merge branch '2.x' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomaduro committed Jan 15, 2024
2 parents d457999 + bad835a commit 1e50b3c
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
composer.lock
/phpunit.xml
.phpunit.result.cache
.idea
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Release Notes

## [Unreleased](https://github.com/laravel/envoy/compare/v2.8.6...2.x)
## [Unreleased](https://github.com/laravel/envoy/compare/v2.8.7...2.x)

## [v2.8.7](https://github.com/laravel/envoy/compare/v2.8.6...v2.8.7) - 2024-01-09

* [2.x] Compile `[@servers](https://github.com/servers)` When Array is in Multiple Lines by [@devajmeireles](https://github.com/devajmeireles) in https://github.com/laravel/envoy/pull/270
* [2.x] Bugfix: Allowing `[@setup](https://github.com/setup)` Variables into `[@servers](https://github.com/servers)` by [@devajmeireles](https://github.com/devajmeireles) in https://github.com/laravel/envoy/pull/272

## [v2.8.6](https://github.com/laravel/envoy/compare/v2.8.5...v2.8.6) - 2023-01-10

Expand Down
2 changes: 1 addition & 1 deletion bin/envoy
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if (file_exists(__DIR__.'/../vendor/autoload.php')) {
require __DIR__.'/../../../autoload.php';
}

$app = new Symfony\Component\Console\Application('Laravel Envoy', '2.8.6');
$app = new Symfony\Component\Console\Application('Laravel Envoy', '2.8.7');

$app->add(new Laravel\Envoy\Console\RunCommand);
$app->add(new Laravel\Envoy\Console\SshCommand);
Expand Down
4 changes: 4 additions & 0 deletions src/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@ public function compileInclude($value)
*/
protected function compileServers($value)
{
$value = preg_replace_callback('/@servers\(\[(.*?)\]\)/s', function ($matches) {
return '@servers(['.trim(preg_replace('/\s+/', ' ', $matches[1])).'])';
}, $value);

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

return preg_replace($pattern, '$1<?php $__container->servers$2; ?>', $value);
Expand Down
65 changes: 65 additions & 0 deletions tests/CompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,69 @@ public function test_compile_before_statement()

$this->assertSame(1, preg_match('/\$__container->before\(.*?\}\);/s', $result, $matches));
}

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

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

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

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

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

$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']); ?>");
}

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 1e50b3c

Please sign in to comment.