Skip to content

Commit f6d0485

Browse files
committed
Fix: Actually run 'composer validate'
1 parent 9e0baff commit f6d0485

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

CHANGELOG.md

+13-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10-
For a full diff see [`2.1.0...master`][2.1.0...master].
10+
For a full diff see [`2.1.1...master`][2.1.1...master].
11+
12+
## [`2.1.1`][2.1.1]
13+
14+
For a full diff see [`2.1.0...2.1.1`][2.1.0...2.1.1].
15+
16+
### Fixed
17+
18+
* Actually run `composer validate` to show validation errors when `composer.json` is not valid according to its schema ([#297]), by [@localheinz]
1119

1220
## [`2.1.0`][2.1.0]
1321

@@ -266,6 +274,7 @@ For a full diff see [`81bc3a8...0.1.0`][81bc3a8...0.1.0].
266274
[2.0.1]: https://github.com/ergebnis/composer-normalize/releases/tag/2.0.1
267275
[2.0.2]: https://github.com/ergebnis/composer-normalize/releases/tag/2.0.2
268276
[2.1.0]: https://github.com/ergebnis/composer-normalize/releases/tag/2.1.0
277+
[2.1.1]: https://github.com/ergebnis/composer-normalize/releases/tag/2.1.1
269278

270279
[81bc3a8...0.1.0]: https://github.com/ergebnis/composer-normalize/compare/81bc3a8...0.1.0
271280
[0.1.0...0.2.0]: https://github.com/ergebnis/composer-normalize/compare/0.1.0...0.2.0
@@ -289,7 +298,8 @@ For a full diff see [`81bc3a8...0.1.0`][81bc3a8...0.1.0].
289298
[2.0.0...2.0.1]: https://github.com/ergebnis/composer-normalize/compare/2.0.0...2.0.1
290299
[2.0.1...2.0.2]: https://github.com/ergebnis/composer-normalize/compare/2.0.1...2.0.2
291300
[2.0.2...2.1.0]: https://github.com/ergebnis/composer-normalize/compare/2.0.2...2.1.0
292-
[2.1.0...master]: https://github.com/ergebnis/composer-normalize/compare/2.1.0...master
301+
[2.1.0...2.1.1]: https://github.com/ergebnis/composer-normalize/compare/2.1.0...2.1.1
302+
[2.1.1...master]: https://github.com/ergebnis/composer-normalize/compare/2.1.1...master
293303

294304
[#1]: https://github.com/ergebnis/composer-normalize/pull/1
295305
[#2]: https://github.com/ergebnis/composer-normalize/pull/2
@@ -327,6 +337,7 @@ For a full diff see [`81bc3a8...0.1.0`][81bc3a8...0.1.0].
327337
[#273]: https://github.com/ergebnis/composer-normalize/pull/273
328338
[#280]: https://github.com/ergebnis/composer-normalize/pull/280
329339
[#292]: https://github.com/ergebnis/composer-normalize/pull/292
340+
[#297]: https://github.com/ergebnis/composer-normalize/pull/297
330341

331342
[@ergebnis]: https://github.com/ergebnis
332343
[@localheinz]: https://github.com/localheinz

src/Command/NormalizeCommand.php

+8-3
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,16 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O
153153

154154
try {
155155
$normalized = $this->normalizer->normalize($json);
156-
} catch (\InvalidArgumentException $exception) {
156+
} catch (Normalizer\Exception\OriginalInvalidAccordingToSchemaException $exception) {
157157
$io->writeError(\sprintf(
158158
'<error>%s</error>',
159159
$exception->getMessage()
160160
));
161161

162-
return $this->validateComposerFile($output);
162+
return $this->validateComposerFile(
163+
$output,
164+
$composerFile
165+
);
163166
} catch (\RuntimeException $exception) {
164167
$io->writeError(\sprintf(
165168
'<error>%s</error>',
@@ -347,19 +350,21 @@ private function diff(string $before, string $after): string
347350
* @see https://getcomposer.org/doc/03-cli.md#validate
348351
*
349352
* @param Console\Output\OutputInterface $output
353+
* @param string $composerFile
350354
*
351355
* @throws \Exception
352356
*
353357
* @return int
354358
*/
355-
private function validateComposerFile(Console\Output\OutputInterface $output): int
359+
private function validateComposerFile(Console\Output\OutputInterface $output, string $composerFile): int
356360
{
357361
/** @var Console\Application $application */
358362
$application = $this->getApplication();
359363

360364
return $application->run(
361365
new Console\Input\ArrayInput([
362366
'command' => 'validate',
367+
'file' => $composerFile,
363368
'--no-check-all' => true,
364369
'--no-check-lock' => true,
365370
'--no-check-publish' => true,

test/Integration/Command/NormalizeCommandTest.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,12 @@ public function testFailsWhenComposerJsonIsPresentButNotValid(CommandInvocation
243243
);
244244

245245
self::assertExitCodeSame(1, $exitCode);
246-
self::assertRegExp('/Original JSON is not valid according to schema ".*"/', $output->fetch());
246+
247+
$display = $output->fetch();
248+
249+
self::assertRegExp('/Original JSON is not valid according to schema ".*"/', $display);
250+
self::assertContains('See https://getcomposer.org/doc/04-schema.md for details on the schema', $display);
251+
self::assertContains('No license specified, it is recommended to do so. For closed-source software you may use "proprietary" as license.', $display);
247252
self::assertEquals($initialState, $scenario->currentState());
248253
}
249254

0 commit comments

Comments
 (0)