Skip to content

Commit

Permalink
Merge pull request #15 from Ocramius/hotfix/remove-autoload-re-dump-o…
Browse files Browse the repository at this point in the history
…ptimization

Remove autoload re-dump optimization
  • Loading branch information
Ocramius committed Feb 26, 2016
2 parents 25f302d + 043f263 commit a108adf
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 31 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ var_dump($version); // 1.0.0@0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33
composer require ocramius/package-versions
```

It is suggested that you re-dump the autoloader in order to prevent
autoload I/O when accessing the `PackageVersions\Versions` API:

```sh
composer dump-autoload --optimize
```

### Use-cases

This repository implements `PackageVersions\Versions::getVersion()` in such a way that no IO
Expand Down
19 changes: 0 additions & 19 deletions src/PackageVersions/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ public static function dumpVersionsClass(Event $composerEvent)
$composer->getPackage()
);

self::reDumpAutoloader($composer);

$io->write('<info>ocramius/package-versions:</info> ...done generating version class');
}

Expand Down Expand Up @@ -157,23 +155,6 @@ private static function getRootPackageAlias(RootPackageInterface $rootPackage) :
return $package;
}

/**
* @param Composer $composer
*
* @return void
*/
private static function reDumpAutoloader(Composer $composer)
{
$composer->getAutoloadGenerator()->dump(
$composer->getConfig(),
$composer->getRepositoryManager()->getLocalRepository(),
$composer->getPackage(),
$composer->getInstallationManager(),
'composer',
true // CBA to provide this manually, for now
);
}

/**
* @param Locker $locker
* @param RootPackageInterface $rootPackage
Expand Down
12 changes: 0 additions & 12 deletions test/PackageVersionsTest/InstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public function testDumpVersionsClass()
{
$config = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock();
$locker = $this->getMockBuilder(Locker::class)->disableOriginalConstructor()->getMock();
$autoloadGenerator = $this->getMockBuilder(AutoloadGenerator::class)->disableOriginalConstructor()->getMock();
$repositoryManager = $this->getMockBuilder(RepositoryManager::class)->disableOriginalConstructor()->getMock();
$installManager = $this->getMockBuilder(InstallationManager::class)->disableOriginalConstructor()->getMock();
$repository = $this->getMock(InstalledRepositoryInterface::class);
Expand Down Expand Up @@ -129,12 +128,10 @@ public function testDumpVersionsClass()
],
]);

$autoloadGenerator->expects(self::once())->method('dump');
$repositoryManager->expects(self::any())->method('getLocalRepository')->willReturn($repository);

$this->composer->expects(self::any())->method('getConfig')->willReturn($config);
$this->composer->expects(self::any())->method('getLocker')->willReturn($locker);
$this->composer->expects(self::any())->method('getAutoloadGenerator')->willReturn($autoloadGenerator);
$this->composer->expects(self::any())->method('getRepositoryManager')->willReturn($repositoryManager);
$this->composer->expects(self::any())->method('getPackage')->willReturn($package);
$this->composer->expects(self::any())->method('getInstallationManager')->willReturn($installManager);
Expand Down Expand Up @@ -201,7 +198,6 @@ public function testDumpVersionsClassNoDev()
{
$config = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock();
$locker = $this->getMockBuilder(Locker::class)->disableOriginalConstructor()->getMock();
$autoloadGenerator = $this->getMockBuilder(AutoloadGenerator::class)->disableOriginalConstructor()->getMock();
$repositoryManager = $this->getMockBuilder(RepositoryManager::class)->disableOriginalConstructor()->getMock();
$installManager = $this->getMockBuilder(InstallationManager::class)->disableOriginalConstructor()->getMock();
$repository = $this->getMock(InstalledRepositoryInterface::class);
Expand Down Expand Up @@ -235,12 +231,10 @@ public function testDumpVersionsClassNoDev()
],
]);

$autoloadGenerator->expects(self::once())->method('dump');
$repositoryManager->expects(self::any())->method('getLocalRepository')->willReturn($repository);

$this->composer->expects(self::any())->method('getConfig')->willReturn($config);
$this->composer->expects(self::any())->method('getLocker')->willReturn($locker);
$this->composer->expects(self::any())->method('getAutoloadGenerator')->willReturn($autoloadGenerator);
$this->composer->expects(self::any())->method('getRepositoryManager')->willReturn($repositoryManager);
$this->composer->expects(self::any())->method('getPackage')->willReturn($package);
$this->composer->expects(self::any())->method('getInstallationManager')->willReturn($installManager);
Expand Down Expand Up @@ -309,7 +303,6 @@ public function testDumpVersionsWithoutPackageSourceDetails()
{
$config = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock();
$locker = $this->getMockBuilder(Locker::class)->disableOriginalConstructor()->getMock();
$autoloadGenerator = $this->getMockBuilder(AutoloadGenerator::class)->disableOriginalConstructor()->getMock();
$repositoryManager = $this->getMockBuilder(RepositoryManager::class)->disableOriginalConstructor()->getMock();
$installManager = $this->getMockBuilder(InstallationManager::class)->disableOriginalConstructor()->getMock();
$repository = $this->getMock(InstalledRepositoryInterface::class);
Expand Down Expand Up @@ -340,12 +333,10 @@ public function testDumpVersionsWithoutPackageSourceDetails()
],
]);

$autoloadGenerator->expects(self::once())->method('dump');
$repositoryManager->expects(self::any())->method('getLocalRepository')->willReturn($repository);

$this->composer->expects(self::any())->method('getConfig')->willReturn($config);
$this->composer->expects(self::any())->method('getLocker')->willReturn($locker);
$this->composer->expects(self::any())->method('getAutoloadGenerator')->willReturn($autoloadGenerator);
$this->composer->expects(self::any())->method('getRepositoryManager')->willReturn($repositoryManager);
$this->composer->expects(self::any())->method('getPackage')->willReturn($package);
$this->composer->expects(self::any())->method('getInstallationManager')->willReturn($installManager);
Expand Down Expand Up @@ -417,7 +408,6 @@ public function testDumpsVersionsClassToSpecificLocation(RootPackageInterface $r
{
$config = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock();
$locker = $this->getMockBuilder(Locker::class)->disableOriginalConstructor()->getMock();
$autoloadGenerator = $this->getMockBuilder(AutoloadGenerator::class)->disableOriginalConstructor()->getMock();
$repositoryManager = $this->getMockBuilder(RepositoryManager::class)->disableOriginalConstructor()->getMock();
$installManager = $this->getMockBuilder(InstallationManager::class)->disableOriginalConstructor()->getMock();
$repository = $this->getMock(InstalledRepositoryInterface::class);
Expand All @@ -440,12 +430,10 @@ public function testDumpsVersionsClassToSpecificLocation(RootPackageInterface $r
'packages-dev' => [],
]);

$autoloadGenerator->expects(self::once())->method('dump');
$repositoryManager->expects(self::any())->method('getLocalRepository')->willReturn($repository);

$this->composer->expects(self::any())->method('getConfig')->willReturn($config);
$this->composer->expects(self::any())->method('getLocker')->willReturn($locker);
$this->composer->expects(self::any())->method('getAutoloadGenerator')->willReturn($autoloadGenerator);
$this->composer->expects(self::any())->method('getRepositoryManager')->willReturn($repositoryManager);
$this->composer->expects(self::any())->method('getPackage')->willReturn($rootPackage);
$this->composer->expects(self::any())->method('getInstallationManager')->willReturn($installManager);
Expand Down

0 comments on commit a108adf

Please sign in to comment.