Skip to content

Commit

Permalink
Merge pull request #111 from localheinz/fix/default
Browse files Browse the repository at this point in the history
Fix: Register all default message formats
  • Loading branch information
PowerKiKi authored Dec 8, 2021
2 parents 96d946d + eb88609 commit 590739c
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public static function getDefault(): self
{
$config = new self();
$config->addMessageFormat(new Camt052\MessageFormat\V01());
$config->addMessageFormat(new Camt052\MessageFormat\V02());
$config->addMessageFormat(new Camt052\MessageFormat\V04());
$config->addMessageFormat(new Camt052\MessageFormat\V06());
$config->addMessageFormat(new Camt053\MessageFormat\V02());
Expand Down
63 changes: 63 additions & 0 deletions test/Unit/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,77 @@

namespace Genkgo\TestCamt\Unit;

use Genkgo\Camt\Camt052;
use Genkgo\Camt\Camt053;
use Genkgo\Camt\Camt054;
use Genkgo\Camt\Config;
use Genkgo\Camt\MessageFormatInterface;
use PHPUnit\Framework\TestCase;

/**
* @group config
*/
class ConfigTest extends TestCase
{
public function testDefaultConfigHasMessageFormats(): void
{
$config = Config::getDefault();

$messageFormats = $config->getMessageFormats();

$expectedMessageFormats = [
Camt052\MessageFormat\V01::class,
Camt052\MessageFormat\V02::class,
Camt052\MessageFormat\V04::class,
Camt052\MessageFormat\V06::class,
Camt053\MessageFormat\V02::class,
Camt053\MessageFormat\V03::class,
Camt053\MessageFormat\V04::class,
Camt054\MessageFormat\V02::class,
Camt054\MessageFormat\V04::class,
];

$actualMessageFormats = array_map(static function (MessageFormatInterface $messageFormat): string {
return get_class($messageFormat);
}, $messageFormats);

$additionalMessageFormats = array_diff(
$actualMessageFormats,
$expectedMessageFormats
);

self::assertEmpty($additionalMessageFormats, sprintf(
<<<TXT
Failed asserting that the default configuration does not configure additional message formats.
Did you intend to add the following message formats?
- %s
TXT
,
implode("\n- ", $additionalMessageFormats)
));

$missingMessageFormats = array_diff(
$expectedMessageFormats,
$actualMessageFormats
);

self::assertEmpty($missingMessageFormats, sprintf(
<<<TXT
Failed asserting that the default configuration configures all expected formats.
Have you forgotten to add the following message formats?
- %s
TXT
,
implode("\n- ", $missingMessageFormats)
));
}

public function testDefaultConfigHasXsdValidation(): void
{
$config = Config::getDefault();
Expand Down

0 comments on commit 590739c

Please sign in to comment.