diff --git a/CHANGELOG.md b/CHANGELOG.md index a692d3d5..21e72ede 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), For a full diff see [`2.3.2...master`][2.3.2...master]. +### Changed + +* Started showing validation error messages as obtained from validation instead of relying on on executing composer validate ([#406]), by [@localheinz] + ## [`2.3.2`][2.3.2] For a full diff see [`2.3.1...2.3.2`][2.3.1...2.3.2]. @@ -436,6 +440,7 @@ For a full diff see [`81bc3a8...0.1.0`][81bc3a8...0.1.0]. [#374]: https://github.com/ergebnis/composer-normalize/pull/374 [#379]: https://github.com/ergebnis/composer-normalize/pull/379 [#380]: https://github.com/ergebnis/composer-normalize/pull/380 +[#406]: https://github.com/ergebnis/composer-normalize/pull/406 [@ergebnis]: https://github.com/ergebnis [@ergebnis-bot]: https://github.com/ergebnis-bot diff --git a/psalm-baseline.xml b/psalm-baseline.xml index b00f24fc..b120cd59 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,5 +1,5 @@ - + Application @@ -12,8 +12,7 @@ $formatter $differ - - $composerFile + $composerFile $composerFile $composerFile @@ -45,8 +44,7 @@ isLocked diff - - $composerFile + $composerFile $composerFile $composerFile diff --git a/src/Command/NormalizeCommand.php b/src/Command/NormalizeCommand.php index 706e0185..dc40c36f 100644 --- a/src/Command/NormalizeCommand.php +++ b/src/Command/NormalizeCommand.php @@ -159,16 +159,21 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O try { $normalized = $this->normalizer->normalize($json); - } catch (Normalizer\Exception\OriginalInvalidAccordingToSchemaException $exception) { + } catch (Normalizer\Exception\OriginalInvalidAccordingToSchemaException | Normalizer\Exception\NormalizedInvalidAccordingToSchemaException $exception) { $io->writeError(\sprintf( '%s', $exception->getMessage() )); - return $this->validateComposerFile( - $output, - $composerFile - ); + $errors = $exception->errors(); + + \array_walk($errors, static function (string $error) use ($io): void { + $io->writeError($error); + }); + + $io->writeError('See https://getcomposer.org/doc/04-schema.md for details on the schema'); + + return 1; } catch (\RuntimeException $exception) { $io->writeError(\sprintf( '%s', @@ -348,34 +353,6 @@ private function diff(string $before, string $after): string ); } - /** - * @see https://getcomposer.org/doc/03-cli.md#validate - * - * @param Console\Output\OutputInterface $output - * @param string $composerFile - * - * @throws \Exception - * - * @return int - */ - private function validateComposerFile(Console\Output\OutputInterface $output, string $composerFile): int - { - /** @var Console\Application $application */ - $application = $this->getApplication(); - - return $application->run( - new Console\Input\ArrayInput([ - 'command' => 'validate', - 'file' => $composerFile, - '--no-check-all' => true, - '--no-check-lock' => true, - '--no-check-publish' => true, - '--strict' => true, - ]), - $output - ); - } - /** * @see https://getcomposer.org/doc/03-cli.md#update * diff --git a/test/Integration/Command/NormalizeCommandTest.php b/test/Integration/Command/NormalizeCommandTest.php index 0e2e6c37..748fe32f 100644 --- a/test/Integration/Command/NormalizeCommandTest.php +++ b/test/Integration/Command/NormalizeCommandTest.php @@ -252,8 +252,8 @@ public function testFailsWhenComposerJsonIsPresentButNotValid(CommandInvocation ); self::assertContains($message, $display); + self::assertContains('The property name is required', $display); self::assertContains('See https://getcomposer.org/doc/04-schema.md for details on the schema', $display); - self::assertContains('No license specified, it is recommended to do so. For closed-source software you may use "proprietary" as license.', $display); self::assertEquals($initialState, $scenario->currentState()); }