Skip to content
This repository was archived by the owner on Mar 1, 2023. It is now read-only.

Commit be8d37c

Browse files
authored
feat: fixed #96 and added some test for the InstallationManager (#114)
| Q | A | --------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Related tickets | fixes #96 | License | MIT | Doc PR | -
1 parent 55dba2d commit be8d37c

File tree

6 files changed

+333
-21
lines changed

6 files changed

+333
-21
lines changed

src/Automatic/Automatic.php

+13-8
Original file line numberDiff line numberDiff line change
@@ -216,18 +216,23 @@ public function activate(Composer $composer, IOInterface $io): void
216216

217217
$this->container = new Container($composer, $io);
218218

219-
/** @var \Composer\Installer\InstallationManager $installationManager */
220-
$installationManager = $composer->getInstallationManager();
221-
$installationManager->addInstaller($this->container->get(ConfiguratorInstaller::class));
222-
$installationManager->addInstaller($this->container->get(SkeletonInstaller::class));
223-
224219
/** @var \Narrowspark\Automatic\LegacyTagsManager $tagsManager */
225220
$tagsManager = $this->container->get(LegacyTagsManager::class);
226221

227222
$this->configureLegacyTagsManager($io, $tagsManager, $this->container->get('composer-extra'));
228223

229224
$composer->setRepositoryManager($this->extendRepositoryManager($composer, $io, $tagsManager));
230225

226+
// overwrite composer instance
227+
$this->container->set(Composer::class, static function () use ($composer) {
228+
return $composer;
229+
});
230+
231+
/** @var \Composer\Installer\InstallationManager $installationManager */
232+
$installationManager = $composer->getInstallationManager();
233+
$installationManager->addInstaller($this->container->get(ConfiguratorInstaller::class));
234+
$installationManager->addInstaller($this->container->get(SkeletonInstaller::class));
235+
231236
$this->container->get(Lock::class)->add('@readme', [
232237
'This file locks the automatic information of your project to a known state',
233238
'This file is @generated automatically',
@@ -237,9 +242,9 @@ public function activate(Composer $composer, IOInterface $io): void
237242

238243
$this->extendComposer(\debug_backtrace(), $tagsManager);
239244

240-
$this->container->set(InstallationManager::class, static function (Container $container) use ($composer) {
245+
$this->container->set(InstallationManager::class, static function (Container $container) {
241246
return new InstallationManager(
242-
$composer,
247+
$container->get(Composer::class),
243248
$container->get(IOInterface::class),
244249
$container->get(InputInterface::class)
245250
);
@@ -1077,7 +1082,7 @@ private function extendComposer($backtrace, LegacyTagsManager $tagsManager): voi
10771082
}
10781083

10791084
/**
1080-
* Extend the repository manager with a truncated composer repository.
1085+
* Extend the repository manager with a truncated composer repository and parallel downloader.
10811086
*
10821087
* @param \Composer\Composer $composer
10831088
* @param \Composer\IO\IOInterface $io

src/Automatic/Prefetcher/ParallelDownloader.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public function __construct(IOInterface $io, Config $config, array $options = []
108108
{
109109
$this->io = $io;
110110

111-
if (! \method_exists(RemoteFilesystem::class, 'getRemoteContents')) {
111+
if (! \method_exists(parent::class, 'getRemoteContents')) {
112112
$this->io->writeError('Composer >=1.7 not found, downloads will happen in sequence', true, IOInterface::DEBUG);
113113
// @codeCoverageIgnoreStart
114114
} elseif (! \extension_loaded('curl')) {

src/Automatic/Prefetcher/Prefetcher.php

+9-5
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@ class Prefetcher
5858
*/
5959
private $config;
6060

61-
/**
62-
* @var bool
63-
*/
64-
private $cacheDirPopulated = false;
65-
6661
/**
6762
* Patch to the file cache.
6863
*
@@ -71,10 +66,19 @@ class Prefetcher
7166
private $cacheFilesDir;
7267

7368
/**
69+
* Check if the repo cache should be populated.
70+
*
7471
* @var null|bool
7572
*/
7673
private $populateRepoCacheDir;
7774

75+
/**
76+
* Check if the dir cache should be populated.
77+
*
78+
* @var bool
79+
*/
80+
private $cacheDirPopulated = false;
81+
7882
/**
7983
* @var array
8084
*/

src/Common/Installer/AbstractInstallationManager.php

-4
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,6 @@ public function __construct(Composer $composer, IOInterface $io, InputInterface
129129

130130
$this->versionSelector = new VersionSelector($pool);
131131
$this->localRepository = $this->composer->getRepositoryManager()->getLocalRepository();
132-
133-
foreach ($this->localRepository->getPackages() as $package) {
134-
$this->installedPackages[\strtolower($package->getName())] = \ltrim($package->getPrettyVersion(), 'v');
135-
}
136132
}
137133

138134
/**

tests/Automatic/AutomaticTest.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ final class AutomaticTest extends MockeryTestCase
5959
*/
6060
protected function setUp(): void
6161
{
62+
parent::setUp();
63+
6264
$this->composerCachePath = __DIR__ . '/AutomaticTest';
6365

6466
@\mkdir($this->composerCachePath);
@@ -120,9 +122,6 @@ public function testActivate(): void
120122
->andReturn(null);
121123

122124
$localRepositoryMock = $this->mock(WritableRepositoryInterface::class);
123-
$localRepositoryMock->shouldReceive('getPackages')
124-
->once()
125-
->andReturn([]);
126125

127126
$repositoryMock = $this->mock(RepositoryManager::class);
128127
$repositoryMock->shouldReceive('getLocalRepository')

0 commit comments

Comments
 (0)