Skip to content

Commit d1b9e00

Browse files
committed
Fix and improve FormatNotFoundException
1 parent faa6865 commit d1b9e00

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/Exceptions/FormatNotFoundException.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,20 @@
44

55
namespace CodeLts\CliTools\Exceptions;
66

7+
use CodeLts\CliTools\OutputFormat;
8+
79
class FormatNotFoundException extends \Exception
810
{
911

1012
public function __construct(string $formatName)
1113
{
12-
parent::__construct(sprintf('The format "%s" is not implemented.', $formatName));
14+
parent::__construct(
15+
sprintf(
16+
'Error formatter "%s" is not implemented. Available error formatters are: %s',
17+
$formatName,
18+
implode(', ', OutputFormat::VALID_OUTPUT_FORMATS)
19+
)
20+
);
1321
}
1422

1523
public function getTip(): ?string

tests/OutputFormatTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111

1212
class OutputFormatTest extends ErrorFormatterTestCase
1313
{
14+
/**
15+
* @var string
16+
*/
17+
private $availablesFormats = 'raw, rawtext, table, checkstyle, json, junit, prettyJson, gitlab, github, teamcity';
1418

1519
/**
1620
* @return array[]
@@ -41,7 +45,7 @@ public function testInValidFormats(string $formatName): void
4145
$this->expectException(FormatNotFoundException::class);
4246
$this->expectExceptionMessage(
4347
'Error formatter "' . $formatName . '" not found.'
44-
. ' Available error formatters are: raw, rawtext, table, checkstyle, json, junit, prettyJson, gitlab, github, teamcity'
48+
. ' Available error formatters are: ' . $this->availablesFormats
4549
);
4650
$this->assertTrue(OutputFormat::checkOutputFormatIsValid($formatName));
4751
}
@@ -62,7 +66,7 @@ public function testGetFormatterForChoiceInvalid(string $formatName): void
6266
$formatName = 'foo' . $formatName;
6367
$this->expectException(FormatNotFoundException::class);
6468
$this->expectExceptionMessage(
65-
'The format "' . $formatName . '" is not implemented.'
69+
'Error formatter "' . $formatName . '" is not implemented. Available error formatters are: ' . $this->availablesFormats
6670
);
6771
OutputFormat::getFormatterForChoice($formatName, new NullRelativePathHelper());
6872
}

0 commit comments

Comments
 (0)