-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Test.php
87 lines (72 loc) 路 2.8 KB
/
Test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
declare(strict_types=1);
/**
* Copyright (c) 2018-2021 Andreas M枚ller
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/ergebnis/composer-normalize
*/
namespace Ergebnis\Composer\Normalize\Test\Integration\Command\NormalizeCommand\Normalizer\Throws;
use Composer\Factory;
use Ergebnis\Composer\Normalize\Command\NormalizeCommand;
use Ergebnis\Composer\Normalize\Test\Integration;
use Ergebnis\Composer\Normalize\Test\Util;
use Ergebnis\Json\Normalizer;
use Ergebnis\Json\Printer;
use Localheinz\Diff;
use Symfony\Component\Console;
/**
* @internal
*
* @covers \Ergebnis\Composer\Normalize\Command\NormalizeCommand
* @covers \Ergebnis\Composer\Normalize\NormalizePlugin
*
* @uses \Ergebnis\Composer\Normalize\Version
*/
final class Test extends Integration\Command\NormalizeCommand\AbstractTestCase
{
/**
* @dataProvider \Ergebnis\Composer\Normalize\Test\DataProvider\Command\NormalizeCommandProvider::commandInvocation()
*/
public function testFailsWhenNormalizerThrowsRuntimeExceptionDuringNormalization(Util\CommandInvocation $commandInvocation): void
{
$scenario = self::createScenario(
$commandInvocation,
__DIR__ . '/fixture',
);
$initialState = $scenario->initialState();
self::assertComposerJsonFileExists($initialState);
self::assertComposerLockFileNotExists($initialState);
$exceptionMessage = self::faker()->sentence;
$application = self::createApplication(new NormalizeCommand(
new Factory(),
new class($exceptionMessage) implements Normalizer\NormalizerInterface {
private string $exceptionMessage;
public function __construct(string $exceptionMessage)
{
$this->exceptionMessage = $exceptionMessage;
}
public function normalize(Normalizer\Json $json): Normalizer\Json
{
throw new \RuntimeException($this->exceptionMessage);
}
},
new Normalizer\Format\Formatter(new Printer\Printer()),
new Diff\Differ(new Diff\Output\StrictUnifiedDiffOutputBuilder([
'fromFile' => 'original',
'toFile' => 'normalized',
])),
));
$input = new Console\Input\ArrayInput($scenario->consoleParameters());
$output = new Console\Output\BufferedOutput();
$exitCode = $application->run(
$input,
$output,
);
self::assertExitCodeSame(1, $exitCode);
self::assertStringContainsString($exceptionMessage, $output->fetch());
self::assertEquals($initialState, $scenario->currentState());
}
}