Skip to content

Commit 403a325

Browse files
jaapiolinawolf
authored andcommitted
Allow warnings because we use phpdoc
1 parent 7a65053 commit 403a325

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

resources/schema/guides.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<xsd:attribute name="input-format" type="xsd:string"/>
2525
<xsd:attribute name="log-path" type="xsd:string"/>
2626
<xsd:attribute name="fail-on-log" type="xsd:string"/>
27+
<xsd:attribute name="fail-on-error" type="xsd:string"/>
2728
<xsd:attribute name="show-progress" type="xsd:string"/>
2829
<xsd:attribute name="theme" type="xsd:string"/>
2930
<xsd:attribute name="default-code-language" type="xsd:string"/>

src/Command/Run.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
use phpDocumentor\Guides\Settings\SettingsManager;
4141
use phpDocumentor\Guides\Twig\Theme\ThemeManager;
4242
use Psr\Clock\ClockInterface;
43+
use Psr\Log\LogLevel;
4344
use RuntimeException;
4445
use Symfony\Component\Console\Command\Command;
4546
use Symfony\Component\Console\Helper\ProgressBar;
@@ -117,6 +118,13 @@ public function __construct(
117118
'If set, returns a non-zero exit code as soon as any warnings/errors occur',
118119
);
119120

121+
$this->addOption(
122+
'fail-on-error',
123+
null,
124+
InputOption::VALUE_NONE,
125+
'If set, returns a non-zero exit code as soon as any errors occur',
126+
);
127+
120128
$this->addOption(
121129
'theme',
122130
null,
@@ -240,8 +248,12 @@ private function getSettingsOverriddenWithInput(InputInterface $input): ProjectS
240248
$settings->setLogPath((string) $input->getOption('log-path'));
241249
}
242250

251+
if ($input->getOption('fail-on-error')) {
252+
$settings->setFailOnError(LogLevel::ERROR);
253+
}
254+
243255
if ($input->getOption('fail-on-log')) {
244-
$settings->setFailOnError(true);
256+
$settings->setFailOnError(LogLevel::WARNING);
245257
}
246258

247259
if (count($input->getOption('output-format')) > 0) {
@@ -290,7 +302,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
290302
}
291303

292304
if ($settings->isFailOnError()) {
293-
$spyProcessor = new SpyProcessor();
305+
$spyProcessor = new SpyProcessor($settings->getFailOnError());
294306
$this->logger->pushProcessor($spyProcessor);
295307
}
296308

src/Logger/SpyProcessor.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
use Monolog\LogRecord;
1717
use Monolog\Processor\ProcessorInterface;
18+
use Psr\Log\LogLevel;
19+
20+
use function strtolower;
1821

1922
/**
2023
* This decorator has an extra method to check whether anything was logged
@@ -25,14 +28,20 @@ final class SpyProcessor implements ProcessorInterface
2528
{
2629
private bool $hasBeenCalled = false;
2730

31+
public function __construct(private string|null $level = LogLevel::WARNING)
32+
{
33+
}
34+
2835
public function hasBeenCalled(): bool
2936
{
3037
return $this->hasBeenCalled;
3138
}
3239

3340
public function __invoke(array|LogRecord $record): array|LogRecord
3441
{
35-
$this->hasBeenCalled = true;
42+
if (strtolower($record['level_name']) === $this->level) {
43+
$this->hasBeenCalled = true;
44+
}
3645

3746
return $record;
3847
}

tests/unit/Logger/SpyProcessorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function testHasBeenCalledReturnsFalseByDefault(): void
2727
public function testItKnowsWhenALogIsEmitted(): void
2828
{
2929
$process = new SpyProcessor();
30-
$process(['channel' => 'test']);
30+
$process(['channel' => 'test', 'level_name' => 'warning']);
3131
self::assertTrue($process->hasBeenCalled());
3232
}
3333
}

0 commit comments

Comments
 (0)