From 494be8250ac055a9049338890f3e49c386678d6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Sat, 31 Oct 2020 23:45:50 +0100 Subject: [PATCH] Enhancement: Allow configuration via composer extra --- CHANGELOG.md | 15 +- README.md | 15 + composer.json | 6 +- composer.lock | 265 +++++++++++++++++- phpstan-baseline.neon | 7 +- psalm-baseline.xml | 7 +- src/Command/NormalizeCommand.php | 115 +++++++- .../Extra/NotValid/AdditionalKeys/Test.php | 53 ++++ .../AdditionalKeys/fixture/composer.json | 21 ++ .../NotValid/IndentSize/Missing/Test.php | 53 ++++ .../IndentSize/Missing/fixture/composer.json | 18 ++ .../IndentSize/NotGreaterThanZero/Test.php | 53 ++++ .../NotGreaterThanZero/fixture/composer.json | 19 ++ .../NotValid/IndentSize/NotInteger/Test.php | 53 ++++ .../NotInteger/fixture/composer.json | 21 ++ .../NotValid/IndentStyle/Missing/Test.php | 53 ++++ .../IndentStyle/Missing/fixture/composer.json | 18 ++ .../IndentStyle/NotSpaceOrTab/Test.php | 53 ++++ .../NotSpaceOrTab/fixture/composer.json | 19 ++ .../NotValid/IndentStyle/NotString/Test.php | 53 ++++ .../NotString/fixture/composer.json | 21 ++ .../Extra/Valid/WithOptions/Test.php | 78 ++++++ .../Valid/WithOptions/fixture/composer.json | 19 ++ .../Extra/Valid/WithoutOptions/Test.php | 68 +++++ .../WithoutOptions/fixture/composer.json | 19 ++ 25 files changed, 1113 insertions(+), 9 deletions(-) create mode 100644 test/Integration/Command/NormalizeCommand/Extra/NotValid/AdditionalKeys/Test.php create mode 100644 test/Integration/Command/NormalizeCommand/Extra/NotValid/AdditionalKeys/fixture/composer.json create mode 100644 test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentSize/Missing/Test.php create mode 100644 test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentSize/Missing/fixture/composer.json create mode 100644 test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentSize/NotGreaterThanZero/Test.php create mode 100644 test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentSize/NotGreaterThanZero/fixture/composer.json create mode 100644 test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentSize/NotInteger/Test.php create mode 100644 test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentSize/NotInteger/fixture/composer.json create mode 100644 test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentStyle/Missing/Test.php create mode 100644 test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentStyle/Missing/fixture/composer.json create mode 100644 test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentStyle/NotSpaceOrTab/Test.php create mode 100644 test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentStyle/NotSpaceOrTab/fixture/composer.json create mode 100644 test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentStyle/NotString/Test.php create mode 100644 test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentStyle/NotString/fixture/composer.json create mode 100644 test/Integration/Command/NormalizeCommand/Extra/Valid/WithOptions/Test.php create mode 100644 test/Integration/Command/NormalizeCommand/Extra/Valid/WithOptions/fixture/composer.json create mode 100644 test/Integration/Command/NormalizeCommand/Extra/Valid/WithoutOptions/Test.php create mode 100644 test/Integration/Command/NormalizeCommand/Extra/Valid/WithoutOptions/fixture/composer.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 46e08760..0469a532 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## Unreleased -For a full diff see [`2.9.1...main`][2.9.1...main]. +For a full diff see [`2.10.0...main`][2.10.0...main]. + +## [`2.10.0`][2.10.0] + +For a full diff see [`2.9.1...2.10.0`][2.9.1...2.10.0]. + +### Added + +* Allowed configuration via composer extra ([#608]), by [@localheinz] ## [`2.9.1`][2.9.1] @@ -475,6 +483,7 @@ For a full diff see [`81bc3a8...0.1.0`][81bc3a8...0.1.0]. [2.8.2]: https://github.com/ergebnis/composer-normalize/releases/tag/2.8.2 [2.9.0]: https://github.com/ergebnis/composer-normalize/releases/tag/2.9.0 [2.9.1]: https://github.com/ergebnis/composer-normalize/releases/tag/2.9.1 +[2.10.0]: https://github.com/ergebnis/composer-normalize/releases/tag/2.10.0 [81bc3a8...0.1.0]: https://github.com/ergebnis/composer-normalize/compare/81bc3a8...0.1.0 [0.1.0...0.2.0]: https://github.com/ergebnis/composer-normalize/compare/0.1.0...0.2.0 @@ -520,7 +529,8 @@ For a full diff see [`81bc3a8...0.1.0`][81bc3a8...0.1.0]. [2.8.1...2.8.2]: https://github.com/ergebnis/composer-normalize/compare/2.8.1...2.8.2 [2.8.2...2.9.0]: https://github.com/ergebnis/composer-normalize/compare/2.8.2...2.9.0 [2.9.0...2.9.1]: https://github.com/ergebnis/composer-normalize/compare/2.9.0...2.9.1 -[2.9.1...main]: https://github.com/ergebnis/composer-normalize/compare/2.9.1...main +[2.9.1...2.10.0]: https://github.com/ergebnis/composer-normalize/compare/2.9.1...2.10.0 +[2.10.0...main]: https://github.com/ergebnis/composer-normalize/compare/2.10.0...main [#1]: https://github.com/ergebnis/composer-normalize/pull/1 [#2]: https://github.com/ergebnis/composer-normalize/pull/2 @@ -588,6 +598,7 @@ For a full diff see [`81bc3a8...0.1.0`][81bc3a8...0.1.0]. [#582]: https://github.com/ergebnis/composer-normalize/pull/582 [#596]: https://github.com/ergebnis/composer-normalize/pull/596 [#597]: https://github.com/ergebnis/composer-normalize/pull/597 +[#608]: https://github.com/ergebnis/composer-normalize/pull/608 [@core23]: https://github.com/core23 [@dependabot]: https://github.com/dependabot diff --git a/README.md b/README.md index f60f8353..c616ebab 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,21 @@ The `NormalizeCommand` provided by the `NormalizePlugin` within this package wil * `--no-check-lock`: Do not check if lock file is up to date * `--no-update-lock`: Do not update lock file if it exists +As an alternative to specifying the `--indent-size` and `--indent-style` options, you can also use composer [extra](https://getcomposer.org/doc/04-schema.md#extra) to configure these options in `composer.json`: + +```json +{ + "extra": { + "composer-normalize": { + "indent-size": 2, + "indent-style": "space", + } + } +} +``` + +:bulb: The configuration provided in composer extra always overrides the configuration provided via command line options. + ### Continuous Integration If you want to run this in continuous integration services, use the `--dry-run` option. diff --git a/composer.json b/composer.json index 0e23f31a..3f2f3eb6 100644 --- a/composer.json +++ b/composer.json @@ -50,7 +50,11 @@ "sort-packages": true }, "extra": { - "class": "Ergebnis\\Composer\\Normalize\\NormalizePlugin" + "class": "Ergebnis\\Composer\\Normalize\\NormalizePlugin", + "composer-normalize": { + "indent-size": 2, + "indent-style": "space" + } }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index 83cc5c52..10db1b85 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f975dd6fd7ad69af7ab2fac8c961ec8a", + "content-hash": "1bdb201e6f5fb7186e828cff8e8cd372", "packages": [ { "name": "ergebnis/json-normalizer", @@ -133,6 +133,10 @@ "json", "printer" ], + "support": { + "issues": "https://github.com/ergebnis/json-printer/issues", + "source": "https://github.com/ergebnis/json-printer" + }, "funding": [ { "url": "https://github.com/localheinz", @@ -260,6 +264,9 @@ "unidiff", "unified diff" ], + "support": { + "source": "https://github.com/localheinz/diff/tree/main" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -346,6 +353,11 @@ "non-blocking", "promise" ], + "support": { + "irc": "irc://irc.freenode.org/amphp", + "issues": "https://github.com/amphp/amp/issues", + "source": "https://github.com/amphp/amp/tree/master" + }, "funding": [ { "url": "https://github.com/amphp", @@ -418,6 +430,11 @@ "non-blocking", "stream" ], + "support": { + "irc": "irc://irc.freenode.org/amphp", + "issues": "https://github.com/amphp/byte-stream/issues", + "source": "https://github.com/amphp/byte-stream/tree/master" + }, "time": "2020-06-29T18:35:05+00:00" }, { @@ -645,6 +662,10 @@ } ], "description": "Composer plugin that provides efficient querying for installed package versions (no runtime IO)", + "support": { + "issues": "https://github.com/composer/package-versions-deprecated/issues", + "source": "https://github.com/composer/package-versions-deprecated/tree/master" + }, "funding": [ { "url": "https://packagist.com", @@ -915,6 +936,10 @@ "MIT" ], "description": "implementation of xdg base directory specification for php", + "support": { + "issues": "https://github.com/dnoegel/php-xdg-base-dir/issues", + "source": "https://github.com/dnoegel/php-xdg-base-dir/tree/v0.1.1" + }, "time": "2019-12-04T15:06:13+00:00" }, { @@ -986,6 +1011,10 @@ "docblock", "parser" ], + "support": { + "issues": "https://github.com/doctrine/annotations/issues", + "source": "https://github.com/doctrine/annotations/tree/1.11.1" + }, "time": "2020-10-26T10:28:16+00:00" }, { @@ -1042,6 +1071,10 @@ "constructor", "instantiate" ], + "support": { + "issues": "https://github.com/doctrine/instantiator/issues", + "source": "https://github.com/doctrine/instantiator/tree/1.3.x" + }, "funding": [ { "url": "https://www.doctrine-project.org/sponsorship.html", @@ -1118,6 +1151,10 @@ "parser", "php" ], + "support": { + "issues": "https://github.com/doctrine/lexer/issues", + "source": "https://github.com/doctrine/lexer/tree/1.2.1" + }, "funding": [ { "url": "https://www.doctrine-project.org/sponsorship.html", @@ -1199,6 +1236,10 @@ "interfaces", "traits" ], + "support": { + "issues": "https://github.com/ergebnis/classy/issues", + "source": "https://github.com/ergebnis/classy" + }, "funding": [ { "url": "https://github.com/localheinz", @@ -1263,6 +1304,10 @@ "keywords": [ "license" ], + "support": { + "issues": "https://github.com/ergebnis/license/issues", + "source": "https://github.com/ergebnis/license" + }, "funding": [ { "url": "https://github.com/localheinz", @@ -1325,6 +1370,10 @@ ], "description": "Provides a configuration factory and multiple rule sets for friendsofphp/php-cs-fixer.", "homepage": "https://github.com/ergebnis/php-cs-fixer-config", + "support": { + "issues": "https://github.com/ergebnis/php-cs-fixer-config/issues", + "source": "https://github.com/ergebnis/php-cs-fixer-config" + }, "funding": [ { "url": "https://github.com/localheinz", @@ -1398,6 +1447,10 @@ "phpstan-extreme-rules", "phpstan-rules" ], + "support": { + "issues": "https://github.com/ergebnis/phpstan-rules/issues", + "source": "https://github.com/ergebnis/phpstan-rules" + }, "funding": [ { "url": "https://github.com/localheinz", @@ -1464,6 +1517,10 @@ "phpunit", "test" ], + "support": { + "issues": "https://github.com/ergebnis/test-util/issues", + "source": "https://github.com/ergebnis/test-util" + }, "funding": [ { "url": "https://github.com/localheinz", @@ -1511,6 +1568,10 @@ } ], "description": "A more advanced JSONRPC implementation", + "support": { + "issues": "https://github.com/felixfbecker/php-advanced-json-rpc/issues", + "source": "https://github.com/felixfbecker/php-advanced-json-rpc/tree/master" + }, "time": "2020-03-11T15:21:41+00:00" }, { @@ -1558,6 +1619,10 @@ "php", "server" ], + "support": { + "issues": "https://github.com/felixfbecker/php-language-server-protocol/issues", + "source": "https://github.com/felixfbecker/php-language-server-protocol/tree/v1.4.0" + }, "time": "2019-06-23T21:03:50+00:00" }, { @@ -1649,6 +1714,10 @@ } ], "description": "A tool to automatically fix PHP code style", + "support": { + "issues": "https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues", + "source": "https://github.com/FriendsOfPHP/PHP-CS-Fixer/tree/v2.16.7" + }, "funding": [ { "url": "https://github.com/keradus", @@ -1705,6 +1774,10 @@ "faker", "fixtures" ], + "support": { + "issues": "https://github.com/fzaninotto/Faker/issues", + "source": "https://github.com/fzaninotto/Faker/tree/v1.9.1" + }, "time": "2019-12-12T13:22:17+00:00" }, { @@ -1760,6 +1833,10 @@ } ], "description": "Provides a phpstan/phpstan extension for phpspec/prophecy", + "support": { + "issues": "https://github.com/Jan0707/phpstan-prophecy/issues", + "source": "https://github.com/Jan0707/phpstan-prophecy/tree/0.8.1" + }, "funding": [ { "url": "https://www.buymeacoffee.com/localheinz", @@ -1818,6 +1895,10 @@ "object", "object graph" ], + "support": { + "issues": "https://github.com/myclabs/DeepCopy/issues", + "source": "https://github.com/myclabs/DeepCopy/tree/1.x" + }, "funding": [ { "url": "https://tidelift.com/funding/github/packagist/myclabs/deep-copy", @@ -1870,6 +1951,11 @@ } ], "description": "Map nested JSON structures onto PHP classes", + "support": { + "email": "cweiske@cweiske.de", + "issues": "https://github.com/cweiske/jsonmapper/issues", + "source": "https://github.com/cweiske/jsonmapper/tree/master" + }, "time": "2020-04-16T18:48:43+00:00" }, { @@ -1922,6 +2008,10 @@ "parser", "php" ], + "support": { + "issues": "https://github.com/nikic/PHP-Parser/issues", + "source": "https://github.com/nikic/PHP-Parser/tree/master" + }, "time": "2020-08-18T19:48:01+00:00" }, { @@ -1971,6 +2061,10 @@ "xml", "xml conversion" ], + "support": { + "issues": "https://github.com/nullivex/lib-array2xml/issues", + "source": "https://github.com/nullivex/lib-array2xml/tree/master" + }, "time": "2019-03-29T20:06:56+00:00" }, { @@ -2026,6 +2120,10 @@ } ], "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", + "support": { + "issues": "https://github.com/phar-io/manifest/issues", + "source": "https://github.com/phar-io/manifest/tree/master" + }, "time": "2018-07-08T19:23:20+00:00" }, { @@ -2073,6 +2171,10 @@ } ], "description": "Library for handling version information and constraints", + "support": { + "issues": "https://github.com/phar-io/version/issues", + "source": "https://github.com/phar-io/version/tree/master" + }, "time": "2018-07-08T19:19:57+00:00" }, { @@ -2124,6 +2226,10 @@ "keywords": [ "diff" ], + "support": { + "issues": "https://github.com/PHP-CS-Fixer/diff/issues", + "source": "https://github.com/PHP-CS-Fixer/diff/tree/v1.3.1" + }, "time": "2020-10-14T08:39:05+00:00" }, { @@ -2173,6 +2279,10 @@ "reflection", "static analysis" ], + "support": { + "issues": "https://github.com/phpDocumentor/ReflectionCommon/issues", + "source": "https://github.com/phpDocumentor/ReflectionCommon/tree/2.x" + }, "time": "2020-06-27T09:03:43+00:00" }, { @@ -2225,6 +2335,10 @@ } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", + "support": { + "issues": "https://github.com/phpDocumentor/ReflectionDocBlock/issues", + "source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/master" + }, "time": "2020-08-15T11:14:08+00:00" }, { @@ -2270,6 +2384,10 @@ } ], "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", + "support": { + "issues": "https://github.com/phpDocumentor/TypeResolver/issues", + "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.x" + }, "time": "2020-06-27T10:12:23+00:00" }, { @@ -2333,6 +2451,10 @@ "spy", "stub" ], + "support": { + "issues": "https://github.com/phpspec/prophecy/issues", + "source": "https://github.com/phpspec/prophecy/tree/master" + }, "time": "2020-07-08T12:44:21+00:00" }, { @@ -2378,6 +2500,10 @@ "MIT" ], "description": "Composer plugin for automatic installation of PHPStan extensions", + "support": { + "issues": "https://github.com/phpstan/extension-installer/issues", + "source": "https://github.com/phpstan/extension-installer/tree/1.0.5" + }, "time": "2020-08-30T12:06:42+00:00" }, { @@ -2420,6 +2546,10 @@ "MIT" ], "description": "PHPStan - PHP Static Analysis Tool", + "support": { + "issues": "https://github.com/phpstan/phpstan/issues", + "source": "https://github.com/phpstan/phpstan/tree/0.12.52" + }, "funding": [ { "url": "https://github.com/ondrejmirtes", @@ -2485,6 +2615,10 @@ "MIT" ], "description": "PHPStan rules for detecting usage of deprecated classes, methods, properties, constants and traits.", + "support": { + "issues": "https://github.com/phpstan/phpstan-deprecation-rules/issues", + "source": "https://github.com/phpstan/phpstan-deprecation-rules/tree/0.12.5" + }, "time": "2020-07-21T14:52:30+00:00" }, { @@ -2541,6 +2675,10 @@ "MIT" ], "description": "PHPUnit extensions and rules for PHPStan", + "support": { + "issues": "https://github.com/phpstan/phpstan-phpunit/issues", + "source": "https://github.com/phpstan/phpstan-phpunit/tree/0.12.16" + }, "time": "2020-08-05T13:28:50+00:00" }, { @@ -2592,6 +2730,10 @@ "MIT" ], "description": "Extra strict and opinionated rules for PHPStan", + "support": { + "issues": "https://github.com/phpstan/phpstan-strict-rules/issues", + "source": "https://github.com/phpstan/phpstan-strict-rules/tree/master" + }, "time": "2020-08-30T15:42:06+00:00" }, { @@ -2655,6 +2797,10 @@ "testing", "xunit" ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/7.0.10" + }, "time": "2019-11-20T13:55:58+00:00" }, { @@ -2705,6 +2851,10 @@ "filesystem", "iterator" ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues", + "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/2.0.2" + }, "time": "2018-09-13T20:33:42+00:00" }, { @@ -2746,6 +2896,10 @@ "keywords": [ "template" ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-text-template/issues", + "source": "https://github.com/sebastianbergmann/php-text-template/tree/1.2.1" + }, "time": "2015-06-21T13:50:34+00:00" }, { @@ -2795,6 +2949,10 @@ "keywords": [ "timer" ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-timer/issues", + "source": "https://github.com/sebastianbergmann/php-timer/tree/master" + }, "time": "2019-06-07T04:22:29+00:00" }, { @@ -2844,6 +3002,10 @@ "keywords": [ "tokenizer" ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-token-stream/issues", + "source": "https://github.com/sebastianbergmann/php-token-stream/tree/3.1.1" + }, "abandoned": true, "time": "2019-09-17T06:23:10+00:00" }, @@ -2928,6 +3090,10 @@ "testing", "xunit" ], + "support": { + "issues": "https://github.com/sebastianbergmann/phpunit/issues", + "source": "https://github.com/sebastianbergmann/phpunit/tree/8.5" + }, "funding": [ { "url": "https://phpunit.de/donate.html", @@ -2990,6 +3156,10 @@ } ], "description": "Psalm plugin for PHPUnit", + "support": { + "issues": "https://github.com/psalm/psalm-plugin-phpunit/issues", + "source": "https://github.com/psalm/psalm-plugin-phpunit/tree/0.12.2" + }, "time": "2020-09-28T17:25:39+00:00" }, { @@ -3089,6 +3259,10 @@ "psr", "psr-14" ], + "support": { + "issues": "https://github.com/php-fig/event-dispatcher/issues", + "source": "https://github.com/php-fig/event-dispatcher/tree/1.0.0" + }, "time": "2019-01-08T18:20:26+00:00" }, { @@ -3234,6 +3408,10 @@ ], "description": "Looks up which function or method a line of code belongs to", "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", + "support": { + "issues": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/issues", + "source": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/tree/master" + }, "time": "2017-03-04T06:30:41+00:00" }, { @@ -3298,6 +3476,10 @@ "compare", "equality" ], + "support": { + "issues": "https://github.com/sebastianbergmann/comparator/issues", + "source": "https://github.com/sebastianbergmann/comparator/tree/master" + }, "time": "2018-07-12T15:12:46+00:00" }, { @@ -3354,6 +3536,10 @@ "unidiff", "unified diff" ], + "support": { + "issues": "https://github.com/sebastianbergmann/diff/issues", + "source": "https://github.com/sebastianbergmann/diff/tree/master" + }, "time": "2019-02-04T06:01:07+00:00" }, { @@ -3407,6 +3593,10 @@ "environment", "hhvm" ], + "support": { + "issues": "https://github.com/sebastianbergmann/environment/issues", + "source": "https://github.com/sebastianbergmann/environment/tree/4.2.3" + }, "time": "2019-11-20T08:46:58+00:00" }, { @@ -3474,6 +3664,10 @@ "export", "exporter" ], + "support": { + "issues": "https://github.com/sebastianbergmann/exporter/issues", + "source": "https://github.com/sebastianbergmann/exporter/tree/master" + }, "time": "2019-09-14T09:02:43+00:00" }, { @@ -3528,6 +3722,10 @@ "keywords": [ "global state" ], + "support": { + "issues": "https://github.com/sebastianbergmann/global-state/issues", + "source": "https://github.com/sebastianbergmann/global-state/tree/master" + }, "time": "2019-02-01T05:30:01+00:00" }, { @@ -3575,6 +3773,10 @@ ], "description": "Traverses array structures and object graphs to enumerate all referenced objects", "homepage": "https://github.com/sebastianbergmann/object-enumerator/", + "support": { + "issues": "https://github.com/sebastianbergmann/object-enumerator/issues", + "source": "https://github.com/sebastianbergmann/object-enumerator/tree/master" + }, "time": "2017-08-03T12:35:26+00:00" }, { @@ -3620,6 +3822,10 @@ ], "description": "Allows reflection of object attributes, including inherited and non-public ones", "homepage": "https://github.com/sebastianbergmann/object-reflector/", + "support": { + "issues": "https://github.com/sebastianbergmann/object-reflector/issues", + "source": "https://github.com/sebastianbergmann/object-reflector/tree/master" + }, "time": "2017-03-29T09:07:27+00:00" }, { @@ -3673,6 +3879,10 @@ ], "description": "Provides functionality to recursively process PHP variables", "homepage": "http://www.github.com/sebastianbergmann/recursion-context", + "support": { + "issues": "https://github.com/sebastianbergmann/recursion-context/issues", + "source": "https://github.com/sebastianbergmann/recursion-context/tree/master" + }, "time": "2017-03-03T06:23:57+00:00" }, { @@ -3715,6 +3925,10 @@ ], "description": "Provides a list of PHP built-in functions that operate on resources", "homepage": "https://www.github.com/sebastianbergmann/resource-operations", + "support": { + "issues": "https://github.com/sebastianbergmann/resource-operations/issues", + "source": "https://github.com/sebastianbergmann/resource-operations/tree/master" + }, "time": "2018-10-04T04:07:39+00:00" }, { @@ -3761,6 +3975,10 @@ ], "description": "Collection of value objects that represent the types of the PHP type system", "homepage": "https://github.com/sebastianbergmann/type", + "support": { + "issues": "https://github.com/sebastianbergmann/type/issues", + "source": "https://github.com/sebastianbergmann/type/tree/master" + }, "time": "2019-07-02T08:10:15+00:00" }, { @@ -3804,6 +4022,10 @@ ], "description": "Library that helps with managing the version number of Git-hosted PHP projects", "homepage": "https://github.com/sebastianbergmann/version", + "support": { + "issues": "https://github.com/sebastianbergmann/version/issues", + "source": "https://github.com/sebastianbergmann/version/tree/master" + }, "time": "2016-10-03T07:35:21+00:00" }, { @@ -4056,6 +4278,9 @@ ], "description": "A generic function and convention to trigger deprecation notices", "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/deprecation-contracts/tree/master" + }, "funding": [ { "url": "https://symfony.com/sponsor", @@ -4138,6 +4363,9 @@ ], "description": "Symfony EventDispatcher Component", "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/event-dispatcher/tree/v5.1.8" + }, "funding": [ { "url": "https://symfony.com/sponsor", @@ -4214,6 +4442,9 @@ "interoperability", "standards" ], + "support": { + "source": "https://github.com/symfony/event-dispatcher-contracts/tree/v2.2.0" + }, "funding": [ { "url": "https://symfony.com/sponsor", @@ -4402,6 +4633,9 @@ "configuration", "options" ], + "support": { + "source": "https://github.com/symfony/options-resolver/tree/v5.1.8" + }, "funding": [ { "url": "https://symfony.com/sponsor", @@ -4791,6 +5025,9 @@ "portable", "shim" ], + "support": { + "source": "https://github.com/symfony/polyfill-php70/tree/v1.20.0" + }, "funding": [ { "url": "https://symfony.com/sponsor", @@ -4864,6 +5101,9 @@ "portable", "shim" ], + "support": { + "source": "https://github.com/symfony/polyfill-php72/tree/v1.20.0" + }, "funding": [ { "url": "https://symfony.com/sponsor", @@ -5226,6 +5466,9 @@ ], "description": "Symfony Stopwatch Component", "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/stopwatch/tree/v5.1.8" + }, "funding": [ { "url": "https://symfony.com/sponsor", @@ -5363,6 +5606,10 @@ } ], "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", + "support": { + "issues": "https://github.com/theseer/tokenizer/issues", + "source": "https://github.com/theseer/tokenizer/tree/master" + }, "funding": [ { "url": "https://github.com/theseer", @@ -5469,6 +5716,10 @@ "inspection", "php" ], + "support": { + "issues": "https://github.com/vimeo/psalm/issues", + "source": "https://github.com/vimeo/psalm/tree/3.18.2" + }, "time": "2020-10-20T13:48:22+00:00" }, { @@ -5518,6 +5769,10 @@ "check", "validate" ], + "support": { + "issues": "https://github.com/webmozart/assert/issues", + "source": "https://github.com/webmozart/assert/tree/master" + }, "time": "2020-07-08T17:02:28+00:00" }, { @@ -5565,6 +5820,10 @@ } ], "description": "A PHP implementation of Ant's glob.", + "support": { + "issues": "https://github.com/webmozart/glob/issues", + "source": "https://github.com/webmozart/glob/tree/master" + }, "time": "2015-12-29T11:14:33+00:00" }, { @@ -5611,6 +5870,10 @@ } ], "description": "A robust cross-platform utility for normalizing, comparing and modifying file paths.", + "support": { + "issues": "https://github.com/webmozart/path-util/issues", + "source": "https://github.com/webmozart/path-util/tree/2.3.0" + }, "time": "2015-12-17T08:42:14+00:00" } ], diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 7f8614a9..9baffb30 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,7 +1,12 @@ parameters: ignoreErrors: - - message: "#^Method Ergebnis\\\\Composer\\\\Normalize\\\\Command\\\\NormalizeCommand\\:\\:indentFrom\\(\\) has a nullable return type declaration\\.$#" + message: "#^Method Ergebnis\\\\Composer\\\\Normalize\\\\Command\\\\NormalizeCommand\\:\\:indentFromInput\\(\\) has a nullable return type declaration\\.$#" + count: 1 + path: src/Command/NormalizeCommand.php + + - + message: "#^Method Ergebnis\\\\Composer\\\\Normalize\\\\Command\\\\NormalizeCommand\\:\\:indentFromExtra\\(\\) has a nullable return type declaration\\.$#" count: 1 path: src/Command/NormalizeCommand.php diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 7ac0946a..2c7a2f96 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -12,7 +12,8 @@ $formatter $normalizer - + + $composer->getPackage()->getExtra() $composerFile $composerFile $composerFile @@ -31,13 +32,15 @@ $locker $normalized - + createComposer diff encoded encoded format + getExtra getLocker + getPackage isFresh isLocked isLocked diff --git a/src/Command/NormalizeCommand.php b/src/Command/NormalizeCommand.php index 4c5523d5..44453474 100644 --- a/src/Command/NormalizeCommand.php +++ b/src/Command/NormalizeCommand.php @@ -104,8 +104,10 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O { $io = $this->getIO(); + $indent = null; + try { - $indent = self::indentFrom($input); + $indentFromInput = self::indentFromInput($input); } catch (\RuntimeException $exception) { $io->writeError(\sprintf( '%s', @@ -115,6 +117,10 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O return 1; } + if (null !== $indentFromInput) { + $indent = $indentFromInput; + } + $composerFile = $input->getArgument('file'); if (null === $composerFile) { @@ -126,6 +132,25 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O $composerFile ); + try { + $indentFromExtra = self::indentFromExtra($composer->getPackage()->getExtra()); + } catch (\RuntimeException $exception) { + $io->writeError(\sprintf( + '%s', + $exception->getMessage() + )); + + return 1; + } + + if (null !== $indentFromExtra) { + $indent = $indentFromExtra; + } + + if (null !== $indentFromInput && null !== $indentFromExtra) { + $io->write('Configuration provided via options and composer extra. Using configuration from composer extra.'); + } + if (false === $input->getOption('dry-run') && !\is_writable($composerFile)) { $io->writeError(\sprintf( '%s is not writable.', @@ -248,7 +273,7 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O /** * @throws \RuntimeException */ - private static function indentFrom(Console\Input\InputInterface $input): ?Normalizer\Format\Indent + private static function indentFromInput(Console\Input\InputInterface $input): ?Normalizer\Format\Indent { /** @var null|string $indentSize */ $indentSize = $input->getOption('indent-size'); @@ -292,6 +317,92 @@ private static function indentFrom(Console\Input\InputInterface $input): ?Normal ); } + /** + * @throws \RuntimeException + */ + private static function indentFromExtra(array $extra): ?Normalizer\Format\Indent + { + if (!\array_key_exists('composer-normalize', $extra)) { + return null; + } + + $configuration = $extra['composer-normalize']; + + $requiredKeys = [ + 'indent-size', + 'indent-style', + ]; + + if (!\is_array($configuration)) { + throw new \RuntimeException(\sprintf( + 'Configuration in composer extra requires keys "%s" with corresponding values."', + \implode('", "', $requiredKeys) + )); + } + + $missingKeys = \array_diff( + $requiredKeys, + \array_keys($configuration) + ); + + if ([] !== $missingKeys) { + throw new \RuntimeException(\sprintf( + 'Configuration in composer extra requires keys "%s" with corresponding values."', + \implode('", "', $requiredKeys) + )); + } + + $extraKeys = \array_diff( + \array_keys($configuration), + $requiredKeys + ); + + if ([] !== $extraKeys) { + throw new \RuntimeException(\sprintf( + 'Configuration in composer extra does not allow extra keys "%s"."', + \implode('", "', $extraKeys) + )); + } + + $indentSize = $configuration['indent-size']; + + if (!\is_int($indentSize)) { + throw new \RuntimeException(\sprintf( + 'Indent size needs to be an integer, got %s instead.', + \gettype($indentSize) + )); + } + + if (1 > $indentSize) { + throw new \RuntimeException(\sprintf( + 'Indent size needs to be an integer greater than 0, but %d is not.', + $indentSize + )); + } + + $indentStyle = $configuration['indent-style']; + + if (!\is_string($indentStyle)) { + throw new \RuntimeException(\sprintf( + 'Indent style needs to be a string, got %s instead.', + \gettype($indentStyle) + )); + } + + if (!\array_key_exists($indentStyle, Normalizer\Format\Indent::CHARACTERS)) { + throw new \RuntimeException(\sprintf( + 'Indent style needs to be one of "%s", but "%s" is not.', + \implode('", "', \array_keys(Normalizer\Format\Indent::CHARACTERS)), + $indentStyle + )); + } + + return Normalizer\Format\Indent::fromSizeAndStyle( + $indentSize, + $indentStyle + ); + } + private static function showValidationErrors(IO\IOInterface $io, string ...$errors): void { foreach ($errors as $error) { diff --git a/test/Integration/Command/NormalizeCommand/Extra/NotValid/AdditionalKeys/Test.php b/test/Integration/Command/NormalizeCommand/Extra/NotValid/AdditionalKeys/Test.php new file mode 100644 index 00000000..1592646d --- /dev/null +++ b/test/Integration/Command/NormalizeCommand/Extra/NotValid/AdditionalKeys/Test.php @@ -0,0 +1,53 @@ +consoleParameters()); + + $output = new Console\Output\BufferedOutput(); + + $exitCode = $application->run( + $input, + $output + ); + + self::assertExitCodeSame(1, $exitCode); + self::assertStringContainsString('Configuration in composer extra does not allow extra keys "another-option", "other-option".', $output->fetch()); + self::assertEquals($scenario->initialState(), $scenario->currentState()); + } +} diff --git a/test/Integration/Command/NormalizeCommand/Extra/NotValid/AdditionalKeys/fixture/composer.json b/test/Integration/Command/NormalizeCommand/Extra/NotValid/AdditionalKeys/fixture/composer.json new file mode 100644 index 00000000..f500b723 --- /dev/null +++ b/test/Integration/Command/NormalizeCommand/Extra/NotValid/AdditionalKeys/fixture/composer.json @@ -0,0 +1,21 @@ +{ + "type": "library", + "_comment": "This composer.json is valid according to a lax validation, , a composer.lock is not present, and composer.json is not yet normalized.", + "keywords": ["foo", "bar"], + "license": "MIT", + "authors": [ + {"name": "Andreas Möller", "email": "am@localheinz.com"} + ], + "extra": { + "composer-normalize": { + "another-option": "bar", + "indent-size": 2, + "indent-style": "space", + "other-option": "foo" + } + }, + "require": { + "ext-json": "*", + "php": "^5.6" + } +} diff --git a/test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentSize/Missing/Test.php b/test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentSize/Missing/Test.php new file mode 100644 index 00000000..2e372a86 --- /dev/null +++ b/test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentSize/Missing/Test.php @@ -0,0 +1,53 @@ +consoleParameters()); + + $output = new Console\Output\BufferedOutput(); + + $exitCode = $application->run( + $input, + $output + ); + + self::assertExitCodeSame(1, $exitCode); + self::assertStringContainsString('Configuration in composer extra requires keys "indent-size", "indent-style" with corresponding values.', $output->fetch()); + self::assertEquals($scenario->initialState(), $scenario->currentState()); + } +} diff --git a/test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentSize/Missing/fixture/composer.json b/test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentSize/Missing/fixture/composer.json new file mode 100644 index 00000000..b13f612a --- /dev/null +++ b/test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentSize/Missing/fixture/composer.json @@ -0,0 +1,18 @@ +{ + "type": "library", + "_comment": "This composer.json is valid according to a lax validation, , a composer.lock is not present, and composer.json is not yet normalized.", + "keywords": ["foo", "bar"], + "license": "MIT", + "authors": [ + {"name": "Andreas Möller", "email": "am@localheinz.com"} + ], + "extra": { + "composer-normalize": { + "indent-style": "space" + } + }, + "require": { + "ext-json": "*", + "php": "^5.6" + } +} diff --git a/test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentSize/NotGreaterThanZero/Test.php b/test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentSize/NotGreaterThanZero/Test.php new file mode 100644 index 00000000..397114a3 --- /dev/null +++ b/test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentSize/NotGreaterThanZero/Test.php @@ -0,0 +1,53 @@ +consoleParameters()); + + $output = new Console\Output\BufferedOutput(); + + $exitCode = $application->run( + $input, + $output + ); + + self::assertExitCodeSame(1, $exitCode); + self::assertStringContainsString('Indent size needs to be an integer greater than 0, but 0 is not.', $output->fetch()); + self::assertEquals($scenario->initialState(), $scenario->currentState()); + } +} diff --git a/test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentSize/NotGreaterThanZero/fixture/composer.json b/test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentSize/NotGreaterThanZero/fixture/composer.json new file mode 100644 index 00000000..878c61d9 --- /dev/null +++ b/test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentSize/NotGreaterThanZero/fixture/composer.json @@ -0,0 +1,19 @@ +{ + "type": "library", + "_comment": "This composer.json is valid according to a lax validation, , a composer.lock is not present, and composer.json is not yet normalized.", + "keywords": ["foo", "bar"], + "license": "MIT", + "authors": [ + {"name": "Andreas Möller", "email": "am@localheinz.com"} + ], + "extra": { + "composer-normalize": { + "indent-size": 0, + "indent-style": "space" + } + }, + "require": { + "ext-json": "*", + "php": "^5.6" + } +} diff --git a/test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentSize/NotInteger/Test.php b/test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentSize/NotInteger/Test.php new file mode 100644 index 00000000..f3c33014 --- /dev/null +++ b/test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentSize/NotInteger/Test.php @@ -0,0 +1,53 @@ +consoleParameters()); + + $output = new Console\Output\BufferedOutput(); + + $exitCode = $application->run( + $input, + $output + ); + + self::assertExitCodeSame(1, $exitCode); + self::assertStringContainsString('Indent size needs to be an integer, got array instead.', $output->fetch()); + self::assertEquals($scenario->initialState(), $scenario->currentState()); + } +} diff --git a/test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentSize/NotInteger/fixture/composer.json b/test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentSize/NotInteger/fixture/composer.json new file mode 100644 index 00000000..06a6c7d7 --- /dev/null +++ b/test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentSize/NotInteger/fixture/composer.json @@ -0,0 +1,21 @@ +{ + "type": "library", + "_comment": "This composer.json is valid according to a lax validation, , a composer.lock is not present, and composer.json is not yet normalized.", + "keywords": ["foo", "bar"], + "license": "MIT", + "authors": [ + {"name": "Andreas Möller", "email": "am@localheinz.com"} + ], + "extra": { + "composer-normalize": { + "indent-size": [ + "foo" + ], + "indent-style": "space" + } + }, + "require": { + "ext-json": "*", + "php": "^5.6" + } +} diff --git a/test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentStyle/Missing/Test.php b/test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentStyle/Missing/Test.php new file mode 100644 index 00000000..6d3847c4 --- /dev/null +++ b/test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentStyle/Missing/Test.php @@ -0,0 +1,53 @@ +consoleParameters()); + + $output = new Console\Output\BufferedOutput(); + + $exitCode = $application->run( + $input, + $output + ); + + self::assertExitCodeSame(1, $exitCode); + self::assertStringContainsString('Configuration in composer extra requires keys "indent-size", "indent-style" with corresponding values.', $output->fetch()); + self::assertEquals($scenario->initialState(), $scenario->currentState()); + } +} diff --git a/test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentStyle/Missing/fixture/composer.json b/test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentStyle/Missing/fixture/composer.json new file mode 100644 index 00000000..475953c3 --- /dev/null +++ b/test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentStyle/Missing/fixture/composer.json @@ -0,0 +1,18 @@ +{ + "type": "library", + "_comment": "This composer.json is valid according to a lax validation, , a composer.lock is not present, and composer.json is not yet normalized.", + "keywords": ["foo", "bar"], + "license": "MIT", + "authors": [ + {"name": "Andreas Möller", "email": "am@localheinz.com"} + ], + "extra": { + "composer-normalize": { + "indent-size": 4 + } + }, + "require": { + "ext-json": "*", + "php": "^5.6" + } +} diff --git a/test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentStyle/NotSpaceOrTab/Test.php b/test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentStyle/NotSpaceOrTab/Test.php new file mode 100644 index 00000000..1e1b9a1a --- /dev/null +++ b/test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentStyle/NotSpaceOrTab/Test.php @@ -0,0 +1,53 @@ +consoleParameters()); + + $output = new Console\Output\BufferedOutput(); + + $exitCode = $application->run( + $input, + $output + ); + + self::assertExitCodeSame(1, $exitCode); + self::assertStringContainsString('Indent style needs to be one of "space", "tab", but "foo" is not.', $output->fetch()); + self::assertEquals($scenario->initialState(), $scenario->currentState()); + } +} diff --git a/test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentStyle/NotSpaceOrTab/fixture/composer.json b/test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentStyle/NotSpaceOrTab/fixture/composer.json new file mode 100644 index 00000000..9c7a5df1 --- /dev/null +++ b/test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentStyle/NotSpaceOrTab/fixture/composer.json @@ -0,0 +1,19 @@ +{ + "type": "library", + "_comment": "This composer.json is valid according to a lax validation, , a composer.lock is not present, and composer.json is not yet normalized.", + "keywords": ["foo", "bar"], + "license": "MIT", + "authors": [ + {"name": "Andreas Möller", "email": "am@localheinz.com"} + ], + "extra": { + "composer-normalize": { + "indent-size": 4, + "indent-style": "foo" + } + }, + "require": { + "ext-json": "*", + "php": "^5.6" + } +} diff --git a/test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentStyle/NotString/Test.php b/test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentStyle/NotString/Test.php new file mode 100644 index 00000000..50614c32 --- /dev/null +++ b/test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentStyle/NotString/Test.php @@ -0,0 +1,53 @@ +consoleParameters()); + + $output = new Console\Output\BufferedOutput(); + + $exitCode = $application->run( + $input, + $output + ); + + self::assertExitCodeSame(1, $exitCode); + self::assertStringContainsString('Indent style needs to be a string, got array instead.', $output->fetch()); + self::assertEquals($scenario->initialState(), $scenario->currentState()); + } +} diff --git a/test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentStyle/NotString/fixture/composer.json b/test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentStyle/NotString/fixture/composer.json new file mode 100644 index 00000000..4b8fa75e --- /dev/null +++ b/test/Integration/Command/NormalizeCommand/Extra/NotValid/IndentStyle/NotString/fixture/composer.json @@ -0,0 +1,21 @@ +{ + "type": "library", + "_comment": "This composer.json is valid according to a lax validation, , a composer.lock is not present, and composer.json is not yet normalized.", + "keywords": ["foo", "bar"], + "license": "MIT", + "authors": [ + {"name": "Andreas Möller", "email": "am@localheinz.com"} + ], + "extra": { + "composer-normalize": { + "indent-size": 4, + "indent-style": [ + "foo" + ] + } + }, + "require": { + "ext-json": "*", + "php": "^5.6" + } +} diff --git a/test/Integration/Command/NormalizeCommand/Extra/Valid/WithOptions/Test.php b/test/Integration/Command/NormalizeCommand/Extra/Valid/WithOptions/Test.php new file mode 100644 index 00000000..63d89c6f --- /dev/null +++ b/test/Integration/Command/NormalizeCommand/Extra/Valid/WithOptions/Test.php @@ -0,0 +1,78 @@ +initialState(); + + self::assertComposerJsonFileExists($initialState); + self::assertComposerLockFileNotExists($initialState); + + $application = self::createApplicationWithNormalizeCommandAsProvidedByNormalizePlugin(); + + $input = new Console\Input\ArrayInput($scenario->consoleParametersWith([ + '--indent-size' => (string) $indentSize, + '--indent-style' => $indentStyle, + ])); + + $output = new Console\Output\BufferedOutput(); + + $exitCode = $application->run( + $input, + $output + ); + + self::assertExitCodeSame(0, $exitCode); + + $display = $output->fetch(); + + self::assertStringContainsString('Configuration provided via options and composer extra. Using configuration from composer extra.', $display); + + $expected = \sprintf( + 'Successfully normalized %s.', + $scenario->composerJsonFileReference() + ); + + self::assertStringContainsString($expected, $display); + + $currentState = $scenario->currentState(); + + self::assertComposerJsonFileModified($initialState, $currentState); + self::assertComposerLockFileNotExists($currentState); + } +} diff --git a/test/Integration/Command/NormalizeCommand/Extra/Valid/WithOptions/fixture/composer.json b/test/Integration/Command/NormalizeCommand/Extra/Valid/WithOptions/fixture/composer.json new file mode 100644 index 00000000..7fd704f2 --- /dev/null +++ b/test/Integration/Command/NormalizeCommand/Extra/Valid/WithOptions/fixture/composer.json @@ -0,0 +1,19 @@ +{ + "type": "library", + "_comment": "This composer.json is valid according to a lax validation, , a composer.lock is not present, and composer.json is not yet normalized.", + "keywords": ["foo", "bar"], + "license": "MIT", + "authors": [ + {"name": "Andreas Möller", "email": "am@localheinz.com"} + ], + "extra": { + "composer-normalize": { + "indent-size": 4, + "indent-style": "space" + } + }, + "require": { + "ext-json": "*", + "php": "^5.6" + } +} diff --git a/test/Integration/Command/NormalizeCommand/Extra/Valid/WithoutOptions/Test.php b/test/Integration/Command/NormalizeCommand/Extra/Valid/WithoutOptions/Test.php new file mode 100644 index 00000000..38704875 --- /dev/null +++ b/test/Integration/Command/NormalizeCommand/Extra/Valid/WithoutOptions/Test.php @@ -0,0 +1,68 @@ +initialState(); + + self::assertComposerJsonFileExists($initialState); + self::assertComposerLockFileNotExists($initialState); + + $application = self::createApplicationWithNormalizeCommandAsProvidedByNormalizePlugin(); + + $input = new Console\Input\ArrayInput($scenario->consoleParameters()); + + $output = new Console\Output\BufferedOutput(); + + $exitCode = $application->run( + $input, + $output + ); + + self::assertExitCodeSame(0, $exitCode); + + $expected = \sprintf( + 'Successfully normalized %s.', + $scenario->composerJsonFileReference() + ); + + self::assertStringContainsString($expected, $output->fetch()); + + $currentState = $scenario->currentState(); + + self::assertComposerJsonFileModified($initialState, $currentState); + self::assertComposerLockFileNotExists($currentState); + } +} diff --git a/test/Integration/Command/NormalizeCommand/Extra/Valid/WithoutOptions/fixture/composer.json b/test/Integration/Command/NormalizeCommand/Extra/Valid/WithoutOptions/fixture/composer.json new file mode 100644 index 00000000..7fd704f2 --- /dev/null +++ b/test/Integration/Command/NormalizeCommand/Extra/Valid/WithoutOptions/fixture/composer.json @@ -0,0 +1,19 @@ +{ + "type": "library", + "_comment": "This composer.json is valid according to a lax validation, , a composer.lock is not present, and composer.json is not yet normalized.", + "keywords": ["foo", "bar"], + "license": "MIT", + "authors": [ + {"name": "Andreas Möller", "email": "am@localheinz.com"} + ], + "extra": { + "composer-normalize": { + "indent-size": 4, + "indent-style": "space" + } + }, + "require": { + "ext-json": "*", + "php": "^5.6" + } +}