Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ jobs:
- php: '8.1'
- php: '8.2'
- php: '8.3'
- php: '8.4'
- php: '8.5'
fail-fast: false

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v6
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
Expand All @@ -31,7 +33,7 @@ jobs:
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache composer dependencies
uses: actions/cache@v1
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
Expand All @@ -42,3 +44,6 @@ jobs:
if [ "${{ matrix.mode }}" = "low-deps" ]; then composer update --prefer-lowest --prefer-stable -n; fi;
- name: Tests
run: vendor/bin/phpunit
- name: Coding standards
if: matrix.php == '7.4'
run: vendor/bin/php-cs-fixer fix --dry-run --diff --verbose
16 changes: 7 additions & 9 deletions .php_cs → .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,23 @@
$finder = PhpCsFixer\Finder::create()
->in(__DIR__ . '/src');

return PhpCsFixer\Config::create()
return (new PhpCsFixer\Config)
->setRiskyAllowed(true)
->setRules([
'@PSR2' => true,
'@PHP70Migration' => true,
'@PHP7x0Migration' => true,
'@Symfony' => true,
'array_syntax' => ['syntax' => 'short'],
'braces' => [
'allow_single_line_closure' => true,
'braces_position' => [
'allow_single_line_anonymous_functions' => true,
],
'concat_space' => [
'spacing' => 'one',
],
'heredoc_to_nowdoc' => true,
'is_null' => [
'use_yoda_style' => false,
],
'linebreak_after_opening_tag' => true,
'new_with_braces' => false,
'no_multiline_whitespace_before_semicolons' => true,
'new_with_parentheses' => false,
'multiline_whitespace_before_semicolons' => false,
'no_php4_constructor' => true,
'no_unreachable_default_argument_value' => true,
'no_useless_else' => true,
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
},
"require": {
"php": ">=7.4",
"symfony/console": "~3.0|~4.0|~5.0|~6.0|~7.0",
"symfony/console": "~3.0|~4.0|~5.0|~6.0|~7.0|~8.0",
"php-di/invoker": "~2.0",
"psr/container": "^1.0|^2.0"
},
"require-dev": {
"phpunit/phpunit": "^6.4|^7|^8|^9|^10",
"mnapoli/phpunit-easymock": "~1.0",
"friendsofphp/php-cs-fixer": "^2.12"
"friendsofphp/php-cs-fixer": "^3"
}
}
7 changes: 5 additions & 2 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ public function command($expression, $callable, array $aliases = [])

$command->defaults($this->defaultsViaReflection($command, $callable));

$this->add($command);
if (method_exists($this, 'addCommand')) {
$this->addCommand($command);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks any command that doesn't return an int.

You can tell because the author had to add return 0 all over the place.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you that's more helpful. @canvural would you be able to look into that?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix in #77

} else {
$this->add($command);
}

return $command;
}
Expand Down Expand Up @@ -300,7 +304,6 @@ private function createParameterResolver()
/**
* Check if the callable represents a static call to a non-static method.
*
* @param mixed $callable
* @return bool
*/
private function isStaticCallToNonStaticMethod($callable)
Expand Down
3 changes: 1 addition & 2 deletions src/HyphenatedInputResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Silly;

use Invoker\ParameterResolver\ParameterResolver;
use ReflectionFunctionAbstract;

/**
* Tries to maps hyphenated parameters to a similarly-named,
Expand All @@ -15,7 +14,7 @@
class HyphenatedInputResolver implements ParameterResolver
{
public function getParameters(
ReflectionFunctionAbstract $reflection,
\ReflectionFunctionAbstract $reflection,
array $providedParameters,
array $resolvedParameters
): array {
Expand Down
6 changes: 6 additions & 0 deletions tests/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public function runs_a_command()
{
$this->application->command('foo', function (OutputInterface $output) {
$output->write('hello');

return 0;
});

$output = new SpyOutput();
Expand All @@ -83,6 +85,8 @@ public function runs_a_command_with_arguments()
}

$output->write($text);

return 0;
});

$output = new SpyOutput();
Expand All @@ -108,6 +112,8 @@ public function runs_a_command_without_output()
{
$this->application->command('foo', function (OutputInterface $output) {
$output->write('hello');

return 0;
});

$code = $this->application->runCommand('foo');
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixture/SpyOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class SpyOutput extends Output implements OutputInterface
{
public $output;

protected function doWrite($message, $newline)
protected function doWrite(string $message, bool $newline): void
{
$this->output .= $message . ($newline ? "\n" : '');
}
Expand Down
58 changes: 56 additions & 2 deletions tests/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public function it_should_run_a_simple_command()
{
$this->application->command('greet', function (Out $output) {
$output->write('hello');

return 0;
});
$this->assertOutputIs('greet', 'hello');
}
Expand All @@ -60,6 +62,8 @@ public function it_should_inject_the_output_and_input_by_name()
{
$this->application->command('greet name', function ($output, $input) {
$output->write('hello ' . $input->getArgument('name'));

return 0;
});
$this->assertOutputIs('greet john', 'hello john');
}
Expand All @@ -76,6 +80,8 @@ public function it_should_inject_the_output_and_input_by_name_even_if_a_service_
$this->application->useContainer($container, false, true);
$this->application->command('greet name', function ($output, $input) {
$output->write('hello ' . $input->getArgument('name'));

return 0;
});
$this->assertOutputIs('greet john', 'hello john');
}
Expand All @@ -87,6 +93,8 @@ public function it_should_inject_the_output_and_input_by_type_hint_on_interfaces
{
$this->application->command('greet name', function (Out $out, InputInterface $in) {
$out->write('hello ' . $in->getArgument('name'));

return 0;
});
$this->assertOutputIs('greet john', 'hello john');
}
Expand All @@ -98,6 +106,8 @@ public function it_should_inject_the_output_and_input_by_type_hint_on_classes()
{
$this->application->command('greet name', function (Output $out, Input $in) {
$out->write('hello ' . $in->getArgument('name'));

return 0;
});
$this->assertOutputIs('greet john', 'hello john');
}
Expand All @@ -114,6 +124,8 @@ public function it_should_inject_the_output_and_input_by_type_hint_even_if_a_ser
$this->application->useContainer($container, false, true);
$this->application->command('greet name', function (Out $out, InputInterface $in) {
$out->write('hello ' . $in->getArgument('name'));

return 0;
});
$this->assertOutputIs('greet john', 'hello john');
}
Expand All @@ -125,6 +137,8 @@ public function it_should_inject_the_symfony_style_object()
{
$this->application->command('greet', function (SymfonyStyle $io) {
$io->write('hello');

return 0;
});
$this->assertOutputIs('greet', 'hello');
}
Expand All @@ -136,6 +150,8 @@ public function it_should_run_a_command_with_an_argument()
{
$this->application->command('greet name', function ($name, Out $output) {
$output->write('hello ' . $name);

return 0;
});
$this->assertOutputIs('greet john', 'hello john');
}
Expand All @@ -147,6 +163,8 @@ public function it_should_run_a_command_with_an_optional_argument()
{
$this->application->command('greet [name]', function ($name, Out $output) {
$output->write('hello ' . $name);

return 0;
});
$this->assertOutputIs('greet', 'hello ');
$this->assertOutputIs('greet john', 'hello john');
Expand All @@ -159,6 +177,8 @@ public function it_should_run_a_command_with_a_flag()
{
$this->application->command('greet [-y|--yell]', function ($yell, Out $output) {
$output->write(var_export($yell, true));

return 0;
});
$this->assertOutputIs('greet', 'false');
$this->assertOutputIs('greet -y', 'true');
Expand All @@ -172,6 +192,8 @@ public function it_should_run_a_command_with_an_option()
{
$this->application->command('greet [-i|--iterations=]', function ($iterations, Out $output) {
$output->write($iterations === null ? 'null' : $iterations);

return 0;
});
$this->assertOutputIs('greet', 'null');
$this->assertOutputIs('greet -i 123', '123');
Expand All @@ -185,6 +207,8 @@ public function it_should_run_a_command_with_multiple_options()
{
$this->application->command('greet [-d|--dir=]*', function ($dir, Out $output) {
$output->write('[' . implode(', ', $dir) . ']');

return 0;
});
$this->assertOutputIs('greet', '[]');
$this->assertOutputIs('greet -d foo', '[foo]');
Expand All @@ -199,6 +223,8 @@ public function it_should_match_hyphenated_arguments_to_lowercase_parameters()
{
$this->application->command('greet first-name', function ($firstname, Out $output) {
$output->write('hello ' . $firstname);

return 0;
});
$this->assertOutputIs('greet john', 'hello john');
}
Expand All @@ -210,6 +236,8 @@ public function it_should_match_hyphenated_arguments_to_mixedcase_parameters()
{
$this->application->command('greet first-name', function ($firstName, Out $output) {
$output->write('hello ' . $firstName);

return 0;
});
$this->assertOutputIs('greet john', 'hello john');
}
Expand All @@ -221,6 +249,8 @@ public function it_should_match_hyphenated_option_to_lowercase_parameters()
{
$this->application->command('greet [--yell-louder]', function ($yelllouder, Out $output) {
$output->write(var_export($yelllouder, true));

return 0;
});
$this->assertOutputIs('greet', 'false');
$this->assertOutputIs('greet --yell-louder', 'true');
Expand All @@ -233,6 +263,8 @@ public function it_should_match_hyphenated_option_to_mixed_case_parameters()
{
$this->application->command('greet [--yell-louder]', function ($yellLouder, Out $output) {
$output->write(var_export($yellLouder, true));

return 0;
});
$this->assertOutputIs('greet', 'false');
$this->assertOutputIs('greet --yell-louder', 'true');
Expand All @@ -246,6 +278,8 @@ public function it_can_resolve_a_callable_string_from_a_container()
$container = new ArrayContainer([
'command.greet' => function (Out $output) {
$output->write('hello');

return 0;
}
]);
$this->application->useContainer($container);
Expand Down Expand Up @@ -285,6 +319,8 @@ public function it_can_inject_using_type_hints()

$this->application->command('greet', function (Out $output, stdClass $param) {
$output->write($param->foo);

return 0;
});

$this->assertOutputIs('greet', 'hello');
Expand All @@ -304,6 +340,8 @@ public function it_can_inject_using_parameter_names()

$this->application->command('greet', function (Out $output, $param) {
$output->write($param->foo);

return 0;
});

$this->assertOutputIs('greet', 'hello');
Expand All @@ -321,6 +359,8 @@ public function it_should_inject_command_parameters_in_priority_over_dependency_

$this->application->command('greet param', function (Out $output, $param) {
$output->write($param);

return 0;
});

$this->assertOutputIs('greet john', 'john');
Expand All @@ -344,6 +384,8 @@ public function it_should_inject_using_type_hint_in_priority_if_both_are_configu

$this->application->command('greet', function (Out $output, stdClass $param) {
$output->write($param->foo);

return 0;
});

$this->assertOutputIs('greet', 'hello');
Expand All @@ -359,6 +401,8 @@ public function it_should_run_a_command_in_the_scope_of_the_application()
$whatIsThis = null;
$this->application->command('foo', function () use (&$whatIsThis) {
$whatIsThis = $this;

return 0;
});

$this->assertOutputIs('foo', '');
Expand All @@ -372,10 +416,14 @@ public function it_should_run_a_subcommand()
{
$this->application->command('foo', function (Out $output) {
$output->write('hello');

return 0;
});
$this->application->command('bar', function (Out $output) {
$this->runCommand('foo', $output);
$code = $this->runCommand('foo', $output);
$output->write(' world');

return $code;
});

$this->assertOutputIs('bar', 'hello world');
Expand All @@ -388,7 +436,9 @@ public function it_should_throw_if_a_parameter_cannot_be_resolved()
{
$this->expectExceptionMessage('Impossible to call the \'greet\' command: Unable to invoke the callable because no value was given for parameter 1 ($foo)');
$this->expectException(RuntimeException::class);
$this->application->command('greet', function (stdClass $foo) {});
$this->application->command('greet', function (stdClass $foo) {
return 0;
});
$this->assertOutputIs('greet', '');
}

Expand Down Expand Up @@ -421,6 +471,8 @@ public function it_can_run_as_a_single_command_application()
{
$this->application->command('run', function (Out $output) {
$output->write('hello');

return 0;
});
$this->application->setDefaultCommand('run');
$this->assertOutputIs('', 'hello');
Expand All @@ -440,5 +492,7 @@ private function assertOutputIs($command, $expected)
public function foo(Out $output)
{
$output->write('hello');

return 0;
}
}
Loading