Skip to content

Commit

Permalink
Boolean options should not go through the self::escape function. (d…
Browse files Browse the repository at this point in the history
…eployphp#2402)

* Boolean options should not go through the `self::escape` function.

> Deployer\Support\Stringify::escape(): Argument deployphp#1 ($token) must be of type string, bool given

Fixes deployphp#2392.

* Update StringifyTest.php

* Update StringifyTest.php

Co-authored-by: Anton Medvedev <[email protected]>
  • Loading branch information
2 people authored and ostrolucky committed Mar 6, 2021
1 parent 1669ffb commit a821268
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
- Lots, and lots of long-standing bugs.
- Fixed incorrect plugin:list parsing (remove duplicate version column). Invoke nested sw:plugin:refresh task instead of redefining it, so that it actually runs.
- Shopware activates/runs migration in order (respects dependencies in composer.json). [#2423] [#2425]
- Boolean options should not go through the `self::escape` function. [#2392]
- Check if shared file exists before touching it (and fail because no write permission). [#2393]


Expand Down Expand Up @@ -603,6 +604,7 @@
[#2425]: https://github.com/deployphp/deployer/pull/2425
[#2423]: https://github.com/deployphp/deployer/issues/2423
[#2393]: https://github.com/deployphp/deployer/pull/2393
[#2392]: https://github.com/deployphp/deployer/issues/2392
[#2197]: https://github.com/deployphp/deployer/issues/2197
[#1994]: https://github.com/deployphp/deployer/issues/1994
[#1990]: https://github.com/deployphp/deployer/issues/1990
Expand Down
2 changes: 1 addition & 1 deletion src/Selector/Selector.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static function apply(?array $conditions, Host $host): bool
}

/**
* @param string|array $a
* @param string|string[] $a
*/
private static function compare(string $op, $a, ?string $b): bool
{
Expand Down
5 changes: 5 additions & 0 deletions src/Support/Stringify.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public static function options(InputInterface $input, OutputInterface $output):
$option = [$option];
}
foreach ($option as $value) {
if(is_bool($value)){
$options[] = "--$name ";
continue;
}

$options[] = "--$name " . self::escape($value);
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/Task/GroupTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace Deployer\Task;

use function Deployer\invoke;

class GroupTask extends Task
{
/**
Expand All @@ -27,6 +29,9 @@ public function __construct(string $name, array $group)

public function run(Context $context): void
{
foreach ($this->group as $item) {
invoke($item);
}
}

/**
Expand Down
3 changes: 2 additions & 1 deletion test/src/Support/StringifyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ public function testOptions()
new Option('start-from', null, Option::VALUE_REQUIRED, 'Start execution from this task'),
new Option('log', null, Option::VALUE_REQUIRED, 'Write log to a file'),
new Option('profile', null, Option::VALUE_REQUIRED, 'Write profile to a file',),
new Option('ansi', null, Option::VALUE_OPTIONAL, 'Force ANSI output',),
]);

self::assertEquals("--option 'env=prod' --limit 1 -vvv", Stringify::options(
new ArgvInput(['deploy', '-o', 'env=prod', '-l1'], $definition),
new ArgvInput(['deploy', '-o', 'env=prod', '--ansi', '-l1'], $definition),
new ConsoleOutput(Output::VERBOSITY_DEBUG, false)
));
}
Expand Down
22 changes: 22 additions & 0 deletions test/src/Task/TaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@

use Deployer\Host\Host;
use PHPUnit\Framework\TestCase;
use function Deployer\invoke;
use function Deployer\task;

class TaskTest extends TestCase
{
protected function tearDown(): void
{
StubTask::$runned = 0;
}

public function testTask()
{
$mock = self::getMockBuilder('stdClass')
Expand Down Expand Up @@ -76,6 +83,21 @@ public function testInit()
$task3->run($context);
self::assertEquals(1, StubTask::$runned);
}

public function testGroupInvoke(): void
{
$spy = new StubTask();

task('foo', $spy);
task('bar', $spy);
task('group', ['foo', 'bar']);

(new Task('group:invoke', function () {
invoke('group');
}))->run(new Context(new Host('localhost')));

$this->assertSame(2, StubTask::$runned);
}
}

/**
Expand Down

0 comments on commit a821268

Please sign in to comment.