Skip to content

Introduce a more convenient exception for unexpected calls #177

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 1 commit into from
Oct 30, 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
6 changes: 3 additions & 3 deletions tests/ErrorHandler/Container/NonResettableContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@

namespace Webmozarts\Console\Parallelization\ErrorHandler\Container;

use DomainException;
use Psr\Container\ContainerInterface;
use Webmozarts\Console\Parallelization\UnexpectedCall;

final class NonResettableContainer implements ContainerInterface
{
public function get(string $id): void
{
throw new DomainException('Unexpected call.');
throw UnexpectedCall::forMethod(__METHOD__);
}

public function has(string $id): bool
{
throw new DomainException('Unexpected call.');
throw UnexpectedCall::forMethod(__METHOD__);
}
}
8 changes: 4 additions & 4 deletions tests/ErrorHandler/Container/ResettableContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@

namespace Webmozarts\Console\Parallelization\ErrorHandler\Container;

use DomainException;
use Psr\Container\ContainerInterface;
use Symfony\Contracts\Service\ResetInterface;
use Webmozarts\Console\Parallelization\UnexpectedCall;

final class ResettableContainer implements ContainerInterface, ResetInterface
{
public function get(string $id): void
{
throw new DomainException('Unexpected call.');
throw UnexpectedCall::forMethod(__METHOD__);
}

public function has(string $id): bool
{
throw new DomainException('Unexpected call.');
throw UnexpectedCall::forMethod(__METHOD__);
}

public function reset(): void
{
throw new DomainException('Unexpected call.');
throw UnexpectedCall::forMethod(__METHOD__);
}
}
4 changes: 2 additions & 2 deletions tests/ErrorHandler/FakeErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@

namespace Webmozarts\Console\Parallelization\ErrorHandler;

use DomainException;
use Throwable;
use Webmozarts\Console\Parallelization\Logger\Logger;
use Webmozarts\Console\Parallelization\UnexpectedCall;

final class FakeErrorHandler implements ErrorHandler
{
public function handleError(string $item, Throwable $throwable, Logger $logger): int
{
throw new DomainException('Unexpected call.');
throw UnexpectedCall::forMethod(__METHOD__);
}
}
4 changes: 1 addition & 3 deletions tests/FakeCallable.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

namespace Webmozarts\Console\Parallelization;

use DomainException;

final class FakeCallable
{
private function __construct()
Expand All @@ -24,7 +22,7 @@ private function __construct()
public static function create(): callable
{
return static function (): void {
throw new DomainException('Unexpected call.');
throw UnexpectedCall::forMethod(__METHOD__);
};
}
}
34 changes: 17 additions & 17 deletions tests/Input/FakeInput74.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,89 +13,89 @@

namespace Webmozarts\Console\Parallelization\Input;

use DomainException;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputInterface;
use Webmozarts\Console\Parallelization\UnexpectedCall;

final class FakeInput74 implements InputInterface
{
public function __call($name, $arguments): void
{
throw new DomainException('Not implemented.');
throw UnexpectedCall::forMethod(__METHOD__);
}

public function getFirstArgument(): ?string
{
throw new DomainException('Not implemented.');
throw UnexpectedCall::forMethod(__METHOD__);
}

public function hasParameterOption($values, $onlyParams = false): bool
{
throw new DomainException('Not implemented.');
throw UnexpectedCall::forMethod(__METHOD__);
}

public function getParameterOption($values, $default = false, $onlyParams = false): void
{
throw new DomainException('Not implemented.');
throw UnexpectedCall::forMethod(__METHOD__);
}

public function bind(InputDefinition $definition): void
{
throw new DomainException('Not implemented.');
throw UnexpectedCall::forMethod(__METHOD__);
}

public function validate(): void
{
throw new DomainException('Not implemented.');
throw UnexpectedCall::forMethod(__METHOD__);
}

public function getArguments(): array
{
throw new DomainException('Not implemented.');
throw UnexpectedCall::forMethod(__METHOD__);
}

public function getArgument($name): void
{
throw new DomainException('Not implemented.');
throw UnexpectedCall::forMethod(__METHOD__);
}

public function setArgument($name, $value): void
{
throw new DomainException('Not implemented.');
throw UnexpectedCall::forMethod(__METHOD__);
}

public function hasArgument($name): bool
{
throw new DomainException('Not implemented.');
throw UnexpectedCall::forMethod(__METHOD__);
}

public function getOptions(): array
{
throw new DomainException('Not implemented.');
throw UnexpectedCall::forMethod(__METHOD__);
}

public function getOption($name): void
{
throw new DomainException('Not implemented.');
throw UnexpectedCall::forMethod(__METHOD__);
}

public function setOption($name, $value): void
{
throw new DomainException('Not implemented.');
throw UnexpectedCall::forMethod(__METHOD__);
}

public function hasOption($name): bool
{
throw new DomainException('Not implemented.');
throw UnexpectedCall::forMethod(__METHOD__);
}

public function isInteractive(): bool
{
throw new DomainException('Not implemented.');
throw UnexpectedCall::forMethod(__METHOD__);
}

public function setInteractive($interactive): void
{
throw new DomainException('Not implemented.');
throw UnexpectedCall::forMethod(__METHOD__);
}
}
34 changes: 17 additions & 17 deletions tests/Input/FakeInput81.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,89 +13,89 @@

namespace Webmozarts\Console\Parallelization\Input;

use DomainException;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputInterface;
use Webmozarts\Console\Parallelization\UnexpectedCall;

final class FakeInput81 implements InputInterface
{
public function __call($name, $arguments): void
{
throw new DomainException('Not implemented.');
throw UnexpectedCall::forMethod(__METHOD__);
}

public function getFirstArgument(): ?string
{
throw new DomainException('Not implemented.');
throw UnexpectedCall::forMethod(__METHOD__);
}

public function hasParameterOption($values, bool $onlyParams = false): bool
{
throw new DomainException('Not implemented.');
throw UnexpectedCall::forMethod(__METHOD__);
}

public function getParameterOption(string|array $values, string|bool|int|float|array|null $default = false, bool $onlyParams = false): void
{
throw new DomainException('Not implemented.');
throw UnexpectedCall::forMethod(__METHOD__);
}

public function bind(InputDefinition $definition): void
{
throw new DomainException('Not implemented.');
throw UnexpectedCall::forMethod(__METHOD__);
}

public function validate(): void
{
throw new DomainException('Not implemented.');
throw UnexpectedCall::forMethod(__METHOD__);
}

public function getArguments(): array
{
throw new DomainException('Not implemented.');
throw UnexpectedCall::forMethod(__METHOD__);
}

public function getArgument(string $name): void
{
throw new DomainException('Not implemented.');
throw UnexpectedCall::forMethod(__METHOD__);
}

public function setArgument(string $name, $value): void
{
throw new DomainException('Not implemented.');
throw UnexpectedCall::forMethod(__METHOD__);
}

public function hasArgument(string $name): bool
{
throw new DomainException('Not implemented.');
throw UnexpectedCall::forMethod(__METHOD__);
}

public function getOptions(): array
{
throw new DomainException('Not implemented.');
throw UnexpectedCall::forMethod(__METHOD__);
}

public function getOption(string $name): void
{
throw new DomainException('Not implemented.');
throw UnexpectedCall::forMethod(__METHOD__);
}

public function setOption(string $name, $value): void
{
throw new DomainException('Not implemented.');
throw UnexpectedCall::forMethod(__METHOD__);
}

public function hasOption(string $name): bool
{
throw new DomainException('Not implemented.');
throw UnexpectedCall::forMethod(__METHOD__);
}

public function isInteractive(): bool
{
throw new DomainException('Not implemented.');
throw UnexpectedCall::forMethod(__METHOD__);
}

public function setInteractive(bool $interactive): void
{
throw new DomainException('Not implemented.');
throw UnexpectedCall::forMethod(__METHOD__);
}
}
18 changes: 9 additions & 9 deletions tests/Logger/FakeLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

namespace Webmozarts\Console\Parallelization\Logger;

use DomainException;
use Throwable;
use Webmozarts\Console\Parallelization\Configuration;
use Webmozarts\Console\Parallelization\UnexpectedCall;

final class FakeLogger implements Logger
{
Expand All @@ -26,37 +26,37 @@ public function logConfiguration(
string $itemName,
bool $shouldSpawnChildProcesses
): void {
throw new DomainException('Unexpected call.');
throw UnexpectedCall::forMethod(__METHOD__);
}

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

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

public function logFinish(string $itemName): void
{
throw new DomainException('Unexpected call.');
throw UnexpectedCall::forMethod(__METHOD__);
}

public function logItemProcessingFailed(string $item, Throwable $throwable): void
{
throw new DomainException('Unexpected call.');
throw UnexpectedCall::forMethod(__METHOD__);
}

public function logChildProcessStarted(int $index, int $pid, string $commandName): void
{
throw new DomainException('Unexpected call.');
throw UnexpectedCall::forMethod(__METHOD__);
}

public function logChildProcessFinished(int $index): void
{
throw new DomainException('Unexpected call.');
throw UnexpectedCall::forMethod(__METHOD__);
}

public function logUnexpectedChildProcessOutput(
Expand All @@ -66,6 +66,6 @@ public function logUnexpectedChildProcessOutput(
string $buffer,
string $progressSymbol
): void {
throw new DomainException('Unexpected call.');
throw UnexpectedCall::forMethod(__METHOD__);
}
}
Loading