Skip to content

Commit

Permalink
Merge pull request #118 from gsteel/symfony-7
Browse files Browse the repository at this point in the history
Allow installation with Symfony v7 components, Remove support for Symfony v5 components
  • Loading branch information
gsteel committed Jan 2, 2024
2 parents cc81867 + f24f34f commit f3db392
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 82 deletions.
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@
"php": "~8.1.0 || ~8.2.0 || ~8.3.0",
"composer-runtime-api": "^2.0.0",
"psr/container": "^1.0 || ^2.0",
"symfony/console": "^5.3.7 || ^6.0",
"symfony/event-dispatcher": "^5.0 || ^6.0",
"symfony/console": "^6.0 || ^7.0",
"symfony/event-dispatcher": "^6.0 || ^7.0",
"symfony/polyfill-php80": "^1.17",
"webmozart/assert": "^1.10"
},
"require-dev": {
"laminas/laminas-coding-standard": "~2.5.0",
"laminas/laminas-mvc": "^3.6.1",
"laminas/laminas-mvc": "^3.7.0",
"laminas/laminas-servicemanager": "^3.22.1",
"mikey179/vfsstream": "2.0.x-dev",
"phpunit/phpunit": "^10.4.2",
"phpunit/phpunit": "^10.5.5",
"psalm/plugin-phpunit": "^0.18.4",
"vimeo/psalm": "^5.15"
"vimeo/psalm": "^5.18"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 19 additions & 15 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="./vendor/autoload.php"
colors="true">
<coverage/>
<testsuites>
<testsuite name="laminas-cli">
<directory>./test/</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
<exclude>
<file>./src/autoload.php</file>
</exclude>
</source>
colors="true"
displayDetailsOnSkippedTests="true"
displayDetailsOnIncompleteTests="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
>
<coverage/>
<testsuites>
<testsuite name="laminas-cli">
<directory>./test/</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
8 changes: 8 additions & 0 deletions src/Input/AbstractParamAwareInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,12 @@ static function (mixed $value) use ($originalValidator) {

return $originalValidator;
}

/**
* Returns a stringified representation of the args passed to the command.
*/
public function __toString(): string
{
return $this->input->__toString();
}
}
13 changes: 3 additions & 10 deletions src/Input/ParamAwareInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,13 @@ public function hasParameterOption($values, bool $onlyParams = false): bool
/**
* @param string|array $values
* @param string|bool|int|float|array|null $default
* @return mixed
*/
public function getParameterOption($values, $default = false, bool $onlyParams = false)
public function getParameterOption($values, $default = false, bool $onlyParams = false): mixed
{
return $this->input->getParameterOption($values, $default, $onlyParams);
}

/**
* @return mixed
*/
public function getArgument(string $name)
public function getArgument(string $name): mixed
{
return $this->input->getArgument($name);
}
Expand All @@ -52,10 +48,7 @@ public function setArgument(string $name, $value): void
$this->input->setArgument($name, $value);
}

/**
* @return mixed
*/
public function getOption(string $name)
public function getOption(string $name): mixed
{
return $this->input->getOption($name);
}
Expand Down
12 changes: 2 additions & 10 deletions test/Command/ParamAwareCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Laminas\Cli\Input\BoolParam;
use Laminas\Cli\Input\ParamAwareInputInterface;
use LaminasTest\Cli\TestAsset\ParamAwareCommandStub74;
use LaminasTest\Cli\TestAsset\ParamAwareCommandStub80;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
Expand All @@ -15,13 +14,9 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

use function version_compare;

use const PHP_VERSION;

class ParamAwareCommandTest extends TestCase
{
private ParamAwareCommandStub74|ParamAwareCommandStub80 $command;
private ParamAwareCommandStub80 $command;

/** @psalm-var QuestionHelper&MockObject */
private QuestionHelper|MockObject $questionHelper;
Expand All @@ -40,10 +35,7 @@ public function setUp(): void
)
->willReturn($this->questionHelper);

$stubClass = version_compare(PHP_VERSION, '8.0.0', '>=')
? ParamAwareCommandStub80::class
: ParamAwareCommandStub74::class;
$this->command = new $stubClass($helperSet);
$this->command = new ParamAwareCommandStub80($helperSet);
}

public function testAddParamProxiesToAddOption(): void
Expand Down
44 changes: 34 additions & 10 deletions test/Input/ParamAwareInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
use Laminas\Cli\Input\StringParam;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use ReflectionMethod;
use Symfony\Component\Console\Formatter\NullOutputFormatter;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\StreamableInputInterface;
Expand Down Expand Up @@ -147,11 +149,15 @@ public function testProxiesToDecoratedInput(
array $arguments,
mixed $expectedOutput
): void {
$this->decoratedInput
->expects($this->atLeastOnce())
$invokation = $this->decoratedInput
->expects(self::atLeastOnce())
->method($method)
->with(...$arguments)
->willReturn($expectedOutput);
->with(...$arguments);

$reflectionMethod = new ReflectionMethod(InputInterface::class, $method);
if ((string) $reflectionMethod->getReturnType() !== 'void') {
$invokation->willReturn($expectedOutput);
}

$input = new $this->class(
$this->decoratedInput,
Expand All @@ -160,7 +166,7 @@ public function testProxiesToDecoratedInput(
$this->params
);

$this->assertSame($expectedOutput, $input->$method(...$arguments));
self::assertSame($expectedOutput, $input->$method(...$arguments));
}

public function testProxiesToDecoratedInputWithInputDefinition(): void
Expand All @@ -171,10 +177,9 @@ public function testProxiesToDecoratedInputWithInputDefinition(): void
$expectedOutput = null;

$this->decoratedInput
->expects($this->atLeastOnce())
->expects(self::atLeastOnce())
->method($method)
->with(...$arguments)
->willReturn($expectedOutput);
->with(...$arguments);

$input = new $this->class(
$this->decoratedInput,
Expand Down Expand Up @@ -214,8 +219,7 @@ public function testCanSetStreamOnDecoratedStreamableInput(): void
$decoratedInput
->expects($this->atLeastOnce())
->method('setStream')
->with($this->identicalTo(STDIN))
->willReturn(null);
->with($this->identicalTo(STDIN));

$input = new $this->class(
$decoratedInput,
Expand Down Expand Up @@ -633,4 +637,24 @@ public function testGetParamAllowsEmptyValuesForParamsWithValidationIfParamIsNot

$this->assertNull($input->getParam('non-required'));
}

public function testThatCastingToAStringProxiesToTheUnderlyingInputImplementation(): void
{
/**
* Mocking a concrete class here because `__toString` is not part of the InputInterface contract
*/
$decoratedInput = $this->createMock(ArrayInput::class);
$decoratedInput->expects(self::atLeastOnce())
->method('__toString')
->willReturn('something');

$input = new $this->class(
$decoratedInput,
$this->output,
$this->helper,
$this->params,
);

self::assertSame('something', $input->__toString());
}
}
23 changes: 0 additions & 23 deletions test/TestAsset/ParamAwareCommandStub74.php

This file was deleted.

14 changes: 6 additions & 8 deletions test/TestAsset/ParamAwareCommandStub80.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@

namespace LaminasTest\Cli\TestAsset;

use Closure;

class ParamAwareCommandStub80 extends AbstractParamAwareCommandStub
{
/**
* @param string|array|null $shortcut
* @param null|mixed $default Defaults to null.
* @return $this
*/
public function addOption(
string $name,
$shortcut = null,
?int $mode = null,
string|array|null $shortcut = null,
int|null $mode = null,
string $description = '',
$default = null
mixed $default = null,
array|Closure $suggestedValues = []
): static {
return $this->doAddOption($name, $shortcut, $mode, $description, $default);
}
Expand Down

0 comments on commit f3db392

Please sign in to comment.