Skip to content

Rename logger methods #170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 27, 2022
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
12 changes: 6 additions & 6 deletions src/Logger/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ public function logConfiguration(
/**
* @param 0|positive-int|null $numberOfItems
*/
public function startProgress(?int $numberOfItems): void;
public function logStart(?int $numberOfItems): void;

/**
* @param positive-int|0 $steps
*/
public function advance(int $steps = 1): void;
public function logAdvance(int $steps = 1): void;

/**
* @param string $itemName Name of the item; Already in the singular or plural form.
*/
public function finish(string $itemName): void;
public function logFinish(string $itemName): void;

public function logItemProcessingFailed(string $item, Throwable $throwable): void;

Expand All @@ -56,9 +56,9 @@ public function logItemProcessingFailed(string $item, Throwable $throwable): voi
* with the Symfony command name which is just an element of
* the command.
*/
public function logCommandStarted(string $commandName): void;
public function logChildProcessStarted(string $commandName): void;

public function logCommandFinished(): void;
public function logChildProcessFinished(): void;

/**
* Logs the "unexpected" child output. By unexpected is meant that the main
Expand All @@ -67,5 +67,5 @@ public function logCommandFinished(): void;
*
* @param string $buffer Child process output.
*/
public function logUnexpectedOutput(string $buffer, string $progressSymbol): void;
public function logUnexpectedChildProcessOutput(string $buffer, string $progressSymbol): void;
}
12 changes: 6 additions & 6 deletions src/Logger/NullLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ public function logConfiguration(
// Do nothing.
}

public function startProgress(?int $numberOfItems): void
public function logStart(?int $numberOfItems): void
{
// Do nothing.
}

public function advance(int $steps = 1): void
public function logAdvance(int $steps = 1): void
{
// Do nothing.
}

public function finish(string $itemName): void
public function logFinish(string $itemName): void
{
// Do nothing.
}
Expand All @@ -48,17 +48,17 @@ public function logItemProcessingFailed(string $item, Throwable $throwable): voi
// Do nothing.
}

public function logCommandStarted(string $commandName): void
public function logChildProcessStarted(string $commandName): void
{
// Do nothing.
}

public function logCommandFinished(): void
public function logChildProcessFinished(): void
{
// Do nothing.
}

public function logUnexpectedOutput(string $buffer, string $progressSymbol): void
public function logUnexpectedChildProcessOutput(string $buffer, string $progressSymbol): void
{
// Do nothing.
}
Expand Down
12 changes: 6 additions & 6 deletions src/Logger/StandardLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function logConfiguration(
$this->output->writeln('');
}

public function startProgress(?int $numberOfItems): void
public function logStart(?int $numberOfItems): void
{
Assert::false(
isset($this->progressBar),
Expand All @@ -98,7 +98,7 @@ public function startProgress(?int $numberOfItems): void
);
}

public function advance(int $steps = 1): void
public function logAdvance(int $steps = 1): void
{
Assert::true(
isset($this->progressBar),
Expand All @@ -108,7 +108,7 @@ public function advance(int $steps = 1): void
$this->progressBar->advance($steps);
}

public function finish(string $itemName): void
public function logFinish(string $itemName): void
{
Assert::true(
isset($this->progressBar),
Expand Down Expand Up @@ -138,17 +138,17 @@ public function logItemProcessingFailed(string $item, Throwable $throwable): voi
));
}

public function logCommandStarted(string $commandName): void
public function logChildProcessStarted(string $commandName): void
{
$this->logger->debug('Command started: '.$commandName);
}

public function logCommandFinished(): void
public function logChildProcessFinished(): void
{
$this->logger->debug('Command finished');
}

public function logUnexpectedOutput(string $buffer, string $progressSymbol): void
public function logUnexpectedChildProcessOutput(string $buffer, string $progressSymbol): void
{
$this->output->writeln('');
$this->output->writeln(sprintf(
Expand Down
10 changes: 5 additions & 5 deletions src/ParallelExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ private function executeMainProcess(
$shouldSpawnChildProcesses,
);

$logger->startProgress($numberOfItems);
$logger->logStart($numberOfItems);

if ($shouldSpawnChildProcesses) {
$exitCode = $this
Expand All @@ -248,11 +248,11 @@ private function executeMainProcess(
$input,
$output,
$logger,
static fn () => $logger->advance(),
static fn () => $logger->logAdvance(),
);
}

$logger->finish($itemName);
$logger->logFinish($itemName);

($this->runAfterLastCommand)($input, $output);

Expand Down Expand Up @@ -372,10 +372,10 @@ private function processChildOutput(

// Display unexpected output
if ($charactersCount !== mb_strlen($buffer)) {
$logger->logUnexpectedOutput($buffer, $progressSymbol);
$logger->logUnexpectedChildProcessOutput($buffer, $progressSymbol);
}

$logger->advance($charactersCount);
$logger->logAdvance($charactersCount);
}

private static function validateBatchSize(int $batchSize): void
Expand Down
4 changes: 2 additions & 2 deletions src/Process/SymfonyProcessLauncher.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private function startProcess(InputStream $inputStream): void
$this->callback,
);

$this->logger->logCommandStarted($process->getCommandLine());
$this->logger->logChildProcessStarted($process->getCommandLine());

$this->runningProcesses[] = $process;
}
Expand Down Expand Up @@ -192,7 +192,7 @@ private function freeTerminatedProcesses(): int
*/
private function freeProcess(int $index, Process $process): int
{
$this->logger->logCommandFinished();
$this->logger->logChildProcessFinished();

unset($this->runningProcesses[$index]);

Expand Down
12 changes: 6 additions & 6 deletions tests/Logger/DummyLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,23 @@ public function logConfiguration(
];
}

public function startProgress(?int $numberOfItems): void
public function logStart(?int $numberOfItems): void
{
$this->records[] = [
__FUNCTION__,
func_get_args(),
];
}

public function advance(int $steps = 1): void
public function logAdvance(int $steps = 1): void
{
$this->records[] = [
__FUNCTION__,
func_get_args(),
];
}

public function finish(string $itemName): void
public function logFinish(string $itemName): void
{
$this->records[] = [
__FUNCTION__,
Expand All @@ -66,23 +66,23 @@ public function logItemProcessingFailed(string $item, Throwable $throwable): voi
];
}

public function logCommandStarted(string $commandName): void
public function logChildProcessStarted(string $commandName): void
{
$this->records[] = [
__FUNCTION__,
func_get_args(),
];
}

public function logCommandFinished(): void
public function logChildProcessFinished(): void
{
$this->records[] = [
__FUNCTION__,
func_get_args(),
];
}

public function logUnexpectedOutput(string $buffer, string $progressSymbol): void
public function logUnexpectedChildProcessOutput(string $buffer, string $progressSymbol): void
{
$this->records[] = [
__FUNCTION__,
Expand Down
12 changes: 6 additions & 6 deletions tests/Logger/FakeLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ public function logConfiguration(
throw new DomainException('Unexpected call.');
}

public function startProgress(?int $numberOfItems): void
public function logStart(?int $numberOfItems): void
{
throw new DomainException('Unexpected call.');
}

public function advance(int $steps = 1): void
public function logAdvance(int $steps = 1): void
{
throw new DomainException('Unexpected call.');
}

public function finish(string $itemName): void
public function logFinish(string $itemName): void
{
throw new DomainException('Unexpected call.');
}
Expand All @@ -49,17 +49,17 @@ public function logItemProcessingFailed(string $item, Throwable $throwable): voi
throw new DomainException('Unexpected call.');
}

public function logCommandStarted(string $commandName): void
public function logChildProcessStarted(string $commandName): void
{
throw new DomainException('Unexpected call.');
}

public function logCommandFinished(): void
public function logChildProcessFinished(): void
{
throw new DomainException('Unexpected call.');
}

public function logUnexpectedOutput(string $buffer, string $progressSymbol): void
public function logUnexpectedChildProcessOutput(string $buffer, string $progressSymbol): void
{
throw new DomainException('Unexpected call.');
}
Expand Down
38 changes: 19 additions & 19 deletions tests/Logger/StandardLoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ private static function withChildConfigurationProvider(): iterable

public function test_it_can_log_the_start_of_the_processing(): void
{
$this->logger->startProgress(10);
$this->logger->logStart(10);

$expected = <<<'TXT'
0/10 [>---------------------------] 0%
Expand All @@ -353,20 +353,20 @@ public function test_it_can_log_the_start_of_the_processing(): void

public function test_it_cannot_start_an_already_started_process(): void
{
$this->logger->startProgress(10);
$this->logger->logStart(10);

$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Cannot start the progress: already started.');

$this->logger->startProgress(10);
$this->logger->logStart(10);
}

public function test_it_can_log_the_progress_of_the_processing(): void
{
$this->logger->startProgress(10);
$this->logger->logStart(10);
$this->output->fetch();

$this->logger->advance();
$this->logger->logAdvance();

$expected = <<<'TXT'

Expand All @@ -381,15 +381,15 @@ public function test_it_cannot_advance_a_non_started_process(): void
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Expected the progress to be started.');

$this->logger->advance();
$this->logger->logAdvance();
}

public function test_it_can_log_the_progress_of_the_processing_of_multiple_items(): void
{
$this->logger->startProgress(10);
$this->logger->logStart(10);
$this->output->fetch();

$this->logger->advance(4);
$this->logger->logAdvance(4);

$expected = <<<'TXT'

Expand All @@ -401,10 +401,10 @@ public function test_it_can_log_the_progress_of_the_processing_of_multiple_items

public function test_it_can_log_the_end_of_the_processing(): void
{
$this->logger->startProgress(10);
$this->logger->logStart(10);
$this->output->fetch();

$this->logger->finish('tokens');
$this->logger->logFinish('tokens');

$expected = <<<'TXT'

Expand All @@ -422,16 +422,16 @@ public function test_it_cannot_end_the_processing_of_a_non_started_process(): vo
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Expected the progress to be started.');

$this->logger->finish('tokens');
$this->logger->logFinish('tokens');
}

public function test_it_can_log_the_unexpected_output_of_a_child_process(): void
{
$this->logger->startProgress(10);
$this->logger->advance(4);
$this->logger->logStart(10);
$this->logger->logAdvance(4);
$this->output->fetch();

$this->logger->logUnexpectedOutput(
$this->logger->logUnexpectedChildProcessOutput(
'An error occurred.',
self::ADVANCEMENT_CHARACTER,
);
Expand All @@ -449,11 +449,11 @@ public function test_it_can_log_the_unexpected_output_of_a_child_process(): void

public function test_it_removes_the_progress_character_of_the_unexpected_output_of_a_child_process(): void
{
$this->logger->startProgress(10);
$this->logger->advance(4);
$this->logger->logStart(10);
$this->logger->logAdvance(4);
$this->output->fetch();

$this->logger->logUnexpectedOutput(
$this->logger->logUnexpectedChildProcessOutput(
'An error'.self::ADVANCEMENT_CHARACTER.' occurred.',
self::ADVANCEMENT_CHARACTER,
);
Expand All @@ -473,7 +473,7 @@ public function test_it_can_log_the_start_of_a_command(): void
{
$this->output->setVerbosity(OutputInterface::VERBOSITY_DEBUG);

$this->logger->logCommandStarted('/path/to/bin/console foo:bar --child');
$this->logger->logChildProcessStarted('/path/to/bin/console foo:bar --child');

$expected = <<<'TXT'
[debug] Command started: /path/to/bin/console foo:bar --child
Expand All @@ -487,7 +487,7 @@ public function test_it_can_log_the_end_of_a_command(): void
{
$this->output->setVerbosity(OutputInterface::VERBOSITY_DEBUG);

$this->logger->logCommandFinished();
$this->logger->logChildProcessFinished();

$expected = <<<'TXT'
[debug] Command finished
Expand Down
Loading