Skip to content

Commit 0b63e1d

Browse files
authored
Introduce a more convenient exception for unexpected calls (#177)
1 parent 68953cc commit 0b63e1d

12 files changed

+171
-143
lines changed

tests/ErrorHandler/Container/NonResettableContainer.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@
1313

1414
namespace Webmozarts\Console\Parallelization\ErrorHandler\Container;
1515

16-
use DomainException;
1716
use Psr\Container\ContainerInterface;
17+
use Webmozarts\Console\Parallelization\UnexpectedCall;
1818

1919
final class NonResettableContainer implements ContainerInterface
2020
{
2121
public function get(string $id): void
2222
{
23-
throw new DomainException('Unexpected call.');
23+
throw UnexpectedCall::forMethod(__METHOD__);
2424
}
2525

2626
public function has(string $id): bool
2727
{
28-
throw new DomainException('Unexpected call.');
28+
throw UnexpectedCall::forMethod(__METHOD__);
2929
}
3030
}

tests/ErrorHandler/Container/ResettableContainer.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,24 @@
1313

1414
namespace Webmozarts\Console\Parallelization\ErrorHandler\Container;
1515

16-
use DomainException;
1716
use Psr\Container\ContainerInterface;
1817
use Symfony\Contracts\Service\ResetInterface;
18+
use Webmozarts\Console\Parallelization\UnexpectedCall;
1919

2020
final class ResettableContainer implements ContainerInterface, ResetInterface
2121
{
2222
public function get(string $id): void
2323
{
24-
throw new DomainException('Unexpected call.');
24+
throw UnexpectedCall::forMethod(__METHOD__);
2525
}
2626

2727
public function has(string $id): bool
2828
{
29-
throw new DomainException('Unexpected call.');
29+
throw UnexpectedCall::forMethod(__METHOD__);
3030
}
3131

3232
public function reset(): void
3333
{
34-
throw new DomainException('Unexpected call.');
34+
throw UnexpectedCall::forMethod(__METHOD__);
3535
}
3636
}

tests/ErrorHandler/FakeErrorHandler.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313

1414
namespace Webmozarts\Console\Parallelization\ErrorHandler;
1515

16-
use DomainException;
1716
use Throwable;
1817
use Webmozarts\Console\Parallelization\Logger\Logger;
18+
use Webmozarts\Console\Parallelization\UnexpectedCall;
1919

2020
final class FakeErrorHandler implements ErrorHandler
2121
{
2222
public function handleError(string $item, Throwable $throwable, Logger $logger): int
2323
{
24-
throw new DomainException('Unexpected call.');
24+
throw UnexpectedCall::forMethod(__METHOD__);
2525
}
2626
}

tests/FakeCallable.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
namespace Webmozarts\Console\Parallelization;
1515

16-
use DomainException;
17-
1816
final class FakeCallable
1917
{
2018
private function __construct()
@@ -24,7 +22,7 @@ private function __construct()
2422
public static function create(): callable
2523
{
2624
return static function (): void {
27-
throw new DomainException('Unexpected call.');
25+
throw UnexpectedCall::forMethod(__METHOD__);
2826
};
2927
}
3028
}

tests/Input/FakeInput74.php

+17-17
Original file line numberDiff line numberDiff line change
@@ -13,89 +13,89 @@
1313

1414
namespace Webmozarts\Console\Parallelization\Input;
1515

16-
use DomainException;
1716
use Symfony\Component\Console\Input\InputDefinition;
1817
use Symfony\Component\Console\Input\InputInterface;
18+
use Webmozarts\Console\Parallelization\UnexpectedCall;
1919

2020
final class FakeInput74 implements InputInterface
2121
{
2222
public function __call($name, $arguments): void
2323
{
24-
throw new DomainException('Not implemented.');
24+
throw UnexpectedCall::forMethod(__METHOD__);
2525
}
2626

2727
public function getFirstArgument(): ?string
2828
{
29-
throw new DomainException('Not implemented.');
29+
throw UnexpectedCall::forMethod(__METHOD__);
3030
}
3131

3232
public function hasParameterOption($values, $onlyParams = false): bool
3333
{
34-
throw new DomainException('Not implemented.');
34+
throw UnexpectedCall::forMethod(__METHOD__);
3535
}
3636

3737
public function getParameterOption($values, $default = false, $onlyParams = false): void
3838
{
39-
throw new DomainException('Not implemented.');
39+
throw UnexpectedCall::forMethod(__METHOD__);
4040
}
4141

4242
public function bind(InputDefinition $definition): void
4343
{
44-
throw new DomainException('Not implemented.');
44+
throw UnexpectedCall::forMethod(__METHOD__);
4545
}
4646

4747
public function validate(): void
4848
{
49-
throw new DomainException('Not implemented.');
49+
throw UnexpectedCall::forMethod(__METHOD__);
5050
}
5151

5252
public function getArguments(): array
5353
{
54-
throw new DomainException('Not implemented.');
54+
throw UnexpectedCall::forMethod(__METHOD__);
5555
}
5656

5757
public function getArgument($name): void
5858
{
59-
throw new DomainException('Not implemented.');
59+
throw UnexpectedCall::forMethod(__METHOD__);
6060
}
6161

6262
public function setArgument($name, $value): void
6363
{
64-
throw new DomainException('Not implemented.');
64+
throw UnexpectedCall::forMethod(__METHOD__);
6565
}
6666

6767
public function hasArgument($name): bool
6868
{
69-
throw new DomainException('Not implemented.');
69+
throw UnexpectedCall::forMethod(__METHOD__);
7070
}
7171

7272
public function getOptions(): array
7373
{
74-
throw new DomainException('Not implemented.');
74+
throw UnexpectedCall::forMethod(__METHOD__);
7575
}
7676

7777
public function getOption($name): void
7878
{
79-
throw new DomainException('Not implemented.');
79+
throw UnexpectedCall::forMethod(__METHOD__);
8080
}
8181

8282
public function setOption($name, $value): void
8383
{
84-
throw new DomainException('Not implemented.');
84+
throw UnexpectedCall::forMethod(__METHOD__);
8585
}
8686

8787
public function hasOption($name): bool
8888
{
89-
throw new DomainException('Not implemented.');
89+
throw UnexpectedCall::forMethod(__METHOD__);
9090
}
9191

9292
public function isInteractive(): bool
9393
{
94-
throw new DomainException('Not implemented.');
94+
throw UnexpectedCall::forMethod(__METHOD__);
9595
}
9696

9797
public function setInteractive($interactive): void
9898
{
99-
throw new DomainException('Not implemented.');
99+
throw UnexpectedCall::forMethod(__METHOD__);
100100
}
101101
}

tests/Input/FakeInput81.php

+17-17
Original file line numberDiff line numberDiff line change
@@ -13,89 +13,89 @@
1313

1414
namespace Webmozarts\Console\Parallelization\Input;
1515

16-
use DomainException;
1716
use Symfony\Component\Console\Input\InputDefinition;
1817
use Symfony\Component\Console\Input\InputInterface;
18+
use Webmozarts\Console\Parallelization\UnexpectedCall;
1919

2020
final class FakeInput81 implements InputInterface
2121
{
2222
public function __call($name, $arguments): void
2323
{
24-
throw new DomainException('Not implemented.');
24+
throw UnexpectedCall::forMethod(__METHOD__);
2525
}
2626

2727
public function getFirstArgument(): ?string
2828
{
29-
throw new DomainException('Not implemented.');
29+
throw UnexpectedCall::forMethod(__METHOD__);
3030
}
3131

3232
public function hasParameterOption($values, bool $onlyParams = false): bool
3333
{
34-
throw new DomainException('Not implemented.');
34+
throw UnexpectedCall::forMethod(__METHOD__);
3535
}
3636

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

4242
public function bind(InputDefinition $definition): void
4343
{
44-
throw new DomainException('Not implemented.');
44+
throw UnexpectedCall::forMethod(__METHOD__);
4545
}
4646

4747
public function validate(): void
4848
{
49-
throw new DomainException('Not implemented.');
49+
throw UnexpectedCall::forMethod(__METHOD__);
5050
}
5151

5252
public function getArguments(): array
5353
{
54-
throw new DomainException('Not implemented.');
54+
throw UnexpectedCall::forMethod(__METHOD__);
5555
}
5656

5757
public function getArgument(string $name): void
5858
{
59-
throw new DomainException('Not implemented.');
59+
throw UnexpectedCall::forMethod(__METHOD__);
6060
}
6161

6262
public function setArgument(string $name, $value): void
6363
{
64-
throw new DomainException('Not implemented.');
64+
throw UnexpectedCall::forMethod(__METHOD__);
6565
}
6666

6767
public function hasArgument(string $name): bool
6868
{
69-
throw new DomainException('Not implemented.');
69+
throw UnexpectedCall::forMethod(__METHOD__);
7070
}
7171

7272
public function getOptions(): array
7373
{
74-
throw new DomainException('Not implemented.');
74+
throw UnexpectedCall::forMethod(__METHOD__);
7575
}
7676

7777
public function getOption(string $name): void
7878
{
79-
throw new DomainException('Not implemented.');
79+
throw UnexpectedCall::forMethod(__METHOD__);
8080
}
8181

8282
public function setOption(string $name, $value): void
8383
{
84-
throw new DomainException('Not implemented.');
84+
throw UnexpectedCall::forMethod(__METHOD__);
8585
}
8686

8787
public function hasOption(string $name): bool
8888
{
89-
throw new DomainException('Not implemented.');
89+
throw UnexpectedCall::forMethod(__METHOD__);
9090
}
9191

9292
public function isInteractive(): bool
9393
{
94-
throw new DomainException('Not implemented.');
94+
throw UnexpectedCall::forMethod(__METHOD__);
9595
}
9696

9797
public function setInteractive(bool $interactive): void
9898
{
99-
throw new DomainException('Not implemented.');
99+
throw UnexpectedCall::forMethod(__METHOD__);
100100
}
101101
}

tests/Logger/FakeLogger.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
namespace Webmozarts\Console\Parallelization\Logger;
1515

16-
use DomainException;
1716
use Throwable;
1817
use Webmozarts\Console\Parallelization\Configuration;
18+
use Webmozarts\Console\Parallelization\UnexpectedCall;
1919

2020
final class FakeLogger implements Logger
2121
{
@@ -26,37 +26,37 @@ public function logConfiguration(
2626
string $itemName,
2727
bool $shouldSpawnChildProcesses
2828
): void {
29-
throw new DomainException('Unexpected call.');
29+
throw UnexpectedCall::forMethod(__METHOD__);
3030
}
3131

3232
public function logStart(?int $numberOfItems): void
3333
{
34-
throw new DomainException('Unexpected call.');
34+
throw UnexpectedCall::forMethod(__METHOD__);
3535
}
3636

3737
public function logAdvance(int $steps = 1): void
3838
{
39-
throw new DomainException('Unexpected call.');
39+
throw UnexpectedCall::forMethod(__METHOD__);
4040
}
4141

4242
public function logFinish(string $itemName): void
4343
{
44-
throw new DomainException('Unexpected call.');
44+
throw UnexpectedCall::forMethod(__METHOD__);
4545
}
4646

4747
public function logItemProcessingFailed(string $item, Throwable $throwable): void
4848
{
49-
throw new DomainException('Unexpected call.');
49+
throw UnexpectedCall::forMethod(__METHOD__);
5050
}
5151

5252
public function logChildProcessStarted(int $index, int $pid, string $commandName): void
5353
{
54-
throw new DomainException('Unexpected call.');
54+
throw UnexpectedCall::forMethod(__METHOD__);
5555
}
5656

5757
public function logChildProcessFinished(int $index): void
5858
{
59-
throw new DomainException('Unexpected call.');
59+
throw UnexpectedCall::forMethod(__METHOD__);
6060
}
6161

6262
public function logUnexpectedChildProcessOutput(
@@ -66,6 +66,6 @@ public function logUnexpectedChildProcessOutput(
6666
string $buffer,
6767
string $progressSymbol
6868
): void {
69-
throw new DomainException('Unexpected call.');
69+
throw UnexpectedCall::forMethod(__METHOD__);
7070
}
7171
}

0 commit comments

Comments
 (0)