Skip to content

Commit

Permalink
symfony/console >= 5 support, phpunit 9
Browse files Browse the repository at this point in the history
  • Loading branch information
ostrolucky committed Jun 10, 2020
1 parent 0488f7a commit 751b8c9
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 32 deletions.
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
"amphp/socket": "^1",
"jean85/pretty-package-versions": "^1.1",
"psr/log": "^1.1",
"symfony/console": "^4.1@beta|^5.0",
"symfony/console": ">=4.1",
"symfony/polyfill-php72": "^1.7"
},
"require-dev": {
"amphp/http-client": "^4.0.0-rc7",
"amphp/parallel": "^1.0.1",
"amphp/process": "^1.0.3",
"phpunit/php-code-coverage": "^6.1|^7.0",
"phpunit/phpcov": "^5.0|^6.0",
"phpunit/phpunit": "^7.5|^8.0"
"phpunit/php-code-coverage": ">=6.1",
"phpunit/phpcov": ">=5.0",
"phpunit/phpunit": ">=7.5"
},
"config": {
"sort-packages": true
Expand Down
2 changes: 1 addition & 1 deletion src/Bufferer/AbstractBufferer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ abstract class AbstractBufferer
*/
public $filePath;
/**
* @var InputStream|null
* @var null|InputStream
*/
public $inputStream;

Expand Down
4 changes: 2 additions & 2 deletions src/Bufferer/PipeBufferer.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class PipeBufferer extends AbstractBufferer
*/
private $buffering = true;
/**
* @var Deferred|null
* @var null|Deferred
*/
private $deferred;
/**
Expand Down Expand Up @@ -83,7 +83,7 @@ public function __construct(

public function __invoke(): Promise
{
$generator = function (): \Generator {
$generator = function(): \Generator {
$this->logger->debug("Saving stdin to $this->filePath");

while (null !== $chunk = yield $this->inputStream->read()) {
Expand Down
6 changes: 3 additions & 3 deletions src/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

namespace Ostrolucky\Stdinho;

use function Amp\asyncCoroutine;
use Amp\ByteStream\ResourceInputStream;
use Amp\ByteStream\ResourceOutputStream;
use Amp\Deferred;
use Amp\Loop;
use Amp\Promise;
use function Amp\Socket\listen;
use Amp\Socket\Server;
use Ostrolucky\Stdinho\Bufferer\AbstractBufferer;
use Ostrolucky\Stdinho\Bufferer\PipeBufferer;
Expand All @@ -21,8 +23,6 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\OutputInterface;
use function Amp\asyncCoroutine;
use function Amp\Socket\listen;

class Command extends \Symfony\Component\Console\Command\Command
{
Expand Down Expand Up @@ -125,7 +125,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
"<info>Connection opened at http://{$server->getAddress()}\nPress CTRL+C to exit.</info>\n"
);

Loop::run(function () use ($newConnDefer, &$connectionsLimit, $server, $logger, $output, $bufferer) {
Loop::run(function() use ($newConnDefer, &$connectionsLimit, $server, $logger, $output, $bufferer) {
asyncCoroutine($bufferer)();

while ($connectionsLimit-- && ($socket = yield $server->accept())) {
Expand Down
12 changes: 6 additions & 6 deletions src/ProgressBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@
'portal',
'[%host%] Downloaded: %current_volume% | %speed% | %elapsed%/%estimated% |%aborted% %percent%%'
);
SymfonyProgressBar::setPlaceholderFormatterDefinition('current_volume', function (SymfonyProgressBar $bar) {
SymfonyProgressBar::setPlaceholderFormatterDefinition('current_volume', function(SymfonyProgressBar $bar) {
return Helper::formatMemory($bar->getProgress());
});
SymfonyProgressBar::setPlaceholderFormatterDefinition('elapsed_label', function (SymfonyProgressBar $bar) {
SymfonyProgressBar::setPlaceholderFormatterDefinition('elapsed_label', function(SymfonyProgressBar $bar) {
return $bar->getMaxSteps() >= $bar->getProgress() ? '<info>Finished</info> in' : 'Elapsed';
});
SymfonyProgressBar::setPlaceholderFormatterDefinition('speed', function (SymfonyProgressBar $bar) {
SymfonyProgressBar::setPlaceholderFormatterDefinition('speed', function(SymfonyProgressBar $bar) {
return Helper::formatMemory($bar->getProgress() / max(1, time() - $bar->getStartTime())).'/s';
});
SymfonyProgressBar::setPlaceholderFormatterDefinition('max_volume', function (SymfonyProgressBar $bar) {
SymfonyProgressBar::setPlaceholderFormatterDefinition('max_volume', function(SymfonyProgressBar $bar) {
return Helper::formatMemory($bar->getMaxSteps());
});
SymfonyProgressBar::setPlaceholderFormatterDefinition('host', function (SymfonyProgressBar $bar) {
SymfonyProgressBar::setPlaceholderFormatterDefinition('host', function(SymfonyProgressBar $bar) {
return $bar->host;
});
SymfonyProgressBar::setPlaceholderFormatterDefinition('aborted', function (SymfonyProgressBar $bar) {
SymfonyProgressBar::setPlaceholderFormatterDefinition('aborted', function(SymfonyProgressBar $bar) {
return empty($bar->aborted) ? '' : ' aborted at';
});

Expand Down
10 changes: 5 additions & 5 deletions tests/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
use Amp\Http\Client\Response;
use Amp\Loop;
use Amp\Process\Process;
use PHPUnit\Framework\TestCase;
use function Amp\Promise\timeout;
use function Amp\Promise\wait;
use PHPUnit\Framework\TestCase;

class FunctionalTest extends TestCase
{
Expand All @@ -37,12 +37,12 @@ public static function setUpBeforeClass(): void

protected function setUp(): void
{
Loop::run(function (): void {
$isCoverageEnabled = array_filter($_SERVER['argv'], function (string $arg) {
Loop::run(function(): void {
$isCoverageEnabled = array_filter($_SERVER['argv'], function(string $arg) {
return strpos($arg, '--coverage') === 0;
});
$executable = $isCoverageEnabled ? 'coverage-enabling-bin-wrapper.php' : '../bin/stdinho';
$this->command = 'php '.__DIR__."/$executable --connections-limit=1 localhost:1338 ";
$this->command = "php '".__DIR__."/$executable' --connections-limit=1 localhost:1338 ";
$this->httpClient = HttpClientBuilder::buildDefault();
});
}
Expand All @@ -61,7 +61,7 @@ protected function tearDown(): void
*/
public function testStdinIsWrittenToSocketASAP(string $cliArguments): void
{
Loop::run(function () use ($cliArguments) {
Loop::run(function() use ($cliArguments) {
yield from $this->bootServer($cliArguments);

yield $this->process->getStdin()->write('foo');
Expand Down
18 changes: 10 additions & 8 deletions tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Ostrolucky\Stdinho\Tests;

use function Amp\asyncCoroutine;
use Amp\ByteStream\InputStream;
use Amp\ByteStream\OutputStream;
use Amp\Deferred;
Expand All @@ -21,7 +22,6 @@
use Symfony\Component\Console\Formatter\OutputFormatterInterface;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\ConsoleSectionOutput;
use function Amp\asyncCoroutine;

class IntegrationTest extends TestCase
{
Expand All @@ -32,6 +32,7 @@ public function testBufferOverflow(): void
$responderInputStream = $this->createMock(InputStream::class);
$consoleOutput = $this->createMock(ConsoleOutput::class);
$section = $this->createMock(ConsoleSectionOutput::class);
$outputFormatter = $this->createMock(OutputFormatterInterface::class);
$resource = fopen('php://memory', 'rw');
$server = new Server($resource);
$logger = new TestLogger();
Expand All @@ -42,7 +43,8 @@ public function testBufferOverflow(): void
$socket = $this->createMock(Socket::class);

$consoleOutput->method('section')->willReturn($section);
$section->method('getFormatter')->willReturn($this->createMock(OutputFormatterInterface::class));
$outputFormatter->method('isDecorated')->willReturn(false);
$section->method('getFormatter')->willReturn($outputFormatter);
$socket->method('read')->willReturn(new Success(''));
$socket->method('getRemoteAddress')->willReturn(new SocketAddress(''));

Expand All @@ -54,30 +56,30 @@ public function testBufferOverflow(): void
);

$buffererOutput
->expects($this->exactly(1))
->expects(static::exactly(1))
->method('write')
->willReturn(new Success())
;

$responderInputStream
->expects($this->exactly(2))
->expects(static::exactly(2))
->method('read')
->willReturn(new Success($foo), new Success())
;

$socket
->expects($this->exactly(4))
->expects(static::exactly(4))
->method('write')
->withConsecutive([Assert::stringContains('HTTP/1.1 200 OK')], [$foo], [$bar], [$baz])
->willReturn(new Success())
;

Loop::run(function () use ($socket, $bufferer, $responder): void {
Loop::run(function() use ($socket, $bufferer, $responder): void {
asyncCoroutine($bufferer)();
asyncCoroutine($responder)($socket);
});

self::assertTrue($logger->hasWarningThatContains('Max buffer size reached'));
self::assertFalse(is_resource($resource));
static::assertTrue($logger->hasWarningThatContains('Max buffer size reached'));
static::assertFalse(is_resource($resource));
}
}
8 changes: 5 additions & 3 deletions tests/ResponderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Amp\ByteStream\ResourceOutputStream;
use Amp\Coroutine;
use Amp\Deferred;
use function Amp\Promise\wait;
use Amp\Socket\Socket;
use Amp\Socket\SocketAddress;
use Amp\Success;
Expand All @@ -18,7 +19,6 @@
use Symfony\Component\Console\Formatter\OutputFormatterInterface;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\ConsoleSectionOutput;
use function Amp\Promise\wait;

class ResponderTest extends TestCase
{
Expand All @@ -32,9 +32,11 @@ public function testResponderHandlesClientAbruptDisconnect(): void
$this->createMock(InputStream::class),
new Deferred()
);
$outputFormatter = $this->createMock(OutputFormatterInterface::class);
$outputFormatter->method('isDecorated')->willReturn(false);

$output->method('section')->willReturn($sectionOutput = $this->createMock(ConsoleSectionOutput::class));
$sectionOutput->method('getFormatter')->willReturn($this->createMock(OutputFormatterInterface::class));
$sectionOutput->method('getFormatter')->willReturn($outputFormatter);
$writer = new ResourceOutputStream($resource = fopen('php://memory', 'rwb'));
$socket = $this->createMock(Socket::class);

Expand All @@ -48,6 +50,6 @@ public function testResponderHandlesClientAbruptDisconnect(): void

wait(new Coroutine($responder->__invoke($socket)));

self::assertTrue($logger->hasDebugThatContains('aborted download'));
static::assertTrue($logger->hasDebugThatContains('aborted download'));
}
}

0 comments on commit 751b8c9

Please sign in to comment.