From b7ffe5c6d6b628907fc51d63ddc4f008281393b6 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 29 Nov 2019 01:03:55 +0100 Subject: [PATCH] After update and install commands display how many packages want funding --- src/Composer/Installer.php | 19 +++++++ .../installer/install-funding-notice.test | 54 +++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 tests/Composer/Test/Fixtures/installer/install-funding-notice.test diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index 11edcbe72b0c..b2cddbabfcae 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -35,6 +35,7 @@ use Composer\Package\AliasPackage; use Composer\Package\BasePackage; use Composer\Package\CompletePackage; +use Composer\Package\CompletePackageInterface; use Composer\Package\Link; use Composer\Package\Loader\ArrayLoader; use Composer\Package\Dumper\ArrayDumper; @@ -318,6 +319,24 @@ public function run() } } + $fundingCount = 0; + foreach ($localRepo->getPackages() as $package) { + if ($package instanceof CompletePackageInterface && !empty($package->getFunding())) { + $fundingCount++; + } + } + if ($fundingCount) { + $this->io->writeError(array( + sprintf( + "%d package%s you are using %s looking for funding.", + $fundingCount, + 1 === $fundingCount ? '' : 's', + 1 === $fundingCount ? 'is' : 'are' + ), + 'Use the composer fund command to find out more!', + )); + } + if ($this->runScripts) { // dispatch post event $eventName = $this->update ? ScriptEvents::POST_UPDATE_CMD : ScriptEvents::POST_INSTALL_CMD; diff --git a/tests/Composer/Test/Fixtures/installer/install-funding-notice.test b/tests/Composer/Test/Fixtures/installer/install-funding-notice.test new file mode 100644 index 000000000000..638a31d97f98 --- /dev/null +++ b/tests/Composer/Test/Fixtures/installer/install-funding-notice.test @@ -0,0 +1,54 @@ +--TEST-- +Installs a simple package with exact match requirement +--COMPOSER-- +{ + "repositories": [ + { + "type": "package", + "package": [ + { + "name": "a/a", + "version": "1.0.0", + "funding": [{ "type": "example", "url": "http://example.org/fund" }], + "require": { + "d/d": "^1.0" + } + }, + { + "name": "b/b", + "version": "1.0.0", + "funding": [{ "type": "example", "url": "http://example.org/fund" }] + }, + { + "name": "c/c", + "version": "1.0.0", + "funding": [{ "type": "example", "url": "http://example.org/fund" }] + }, + { + "name": "d/d", + "version": "1.0.0", + "require": { + "b/b": "^1.0" + } + } + ] + } + ], + "require": { + "a/a": "1.0.0" + } +} +--RUN-- +install +--EXPECT-OUTPUT-- +Loading composer repositories with package information +Updating dependencies (including require-dev) +Package operations: 3 installs, 0 updates, 0 removals +Writing lock file +Generating autoload files +2 packages you are using are looking for funding. +Use the composer fund command to find out more! +--EXPECT-- +Installing b/b (1.0.0) +Installing d/d (1.0.0) +Installing a/a (1.0.0)