Skip to content

Commit

Permalink
fix: force installation-source to "source".
Browse files Browse the repository at this point in the history
  • Loading branch information
Sylvain Lorinet committed Apr 13, 2017
1 parent 8e5216f commit 35d734c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 93 deletions.
28 changes: 5 additions & 23 deletions src/LEtudiant/Composer/Data/Package/SharedPackageDataManager.php
Expand Up @@ -19,7 +19,8 @@
*/
class SharedPackageDataManager implements PackageDataManagerInterface
{
const PACKAGE_DATA_FILENAME = 'packages.json';
const PACKAGE_DATA_FILENAME = 'packages.json';
const PACKAGE_INSTALLATION_SOURCE = 'source';

/**
* @var Composer
Expand Down Expand Up @@ -66,16 +67,9 @@ protected function updatePackageUsageFile(PackageInterface $package, array $pack
unset($this->packagesData[$packageKey]);
}
} elseif (!isset($this->packagesData[$packageKey])) {
if (null == $package->getInstallationSource()) {
throw new \RuntimeException(
'Unknown installation source for package "' . $package->getPrettyName()
. '" ("' . $package->getPrettyVersion() . '")'
);
}

$this->packagesData[$packageKey] = array(
'installation-source' => $package->getInstallationSource(),
'project-usage' => $packageData
// Force "source" installation to ensure that we download VCS files
'project-usage' => $packageData
);
} else {
$this->packagesData[$packageKey]['project-usage'] = $packageData;
Expand Down Expand Up @@ -149,16 +143,6 @@ protected function initializePackageData()
}
}

/**
* @param PackageInterface $package
*
* @return string|null
*/
protected function getPackageInstallationSource(PackageInterface $package)
{
return $this->getPackageDataKey($package, 'installation-source');
}

/**
* @param PackageInterface $package
* @param string $key
Expand All @@ -185,8 +169,6 @@ protected function getPackageDataKey(PackageInterface $package, $key, $defaultVa
*/
public function setPackageInstallationSource(PackageInterface $package)
{
if (null == $package->getInstallationSource()) {
$package->setInstallationSource($this->getPackageInstallationSource($package));
}
$package->setInstallationSource(static::PACKAGE_INSTALLATION_SOURCE);
}
}
Expand Up @@ -125,9 +125,8 @@ public function addPackageUsageWithoutData()
;

$package
->expects($this->exactly(2))
->expects($this->never())
->method('getInstallationSource')
->willReturn('source')
;

$dataManager->addPackageUsage($package);
Expand All @@ -138,8 +137,7 @@ public function addPackageUsageWithoutData()
$this->assertJson($content);
$this->assertEquals(array(
'letudiant/foo-bar/dev-develop' => array(
'installation-source' => 'source',
'project-usage' => array(
'project-usage' => array(
'letudiant/root-package'
)
)
Expand Down Expand Up @@ -188,7 +186,7 @@ public function addPackageUsageWithHasData()
$this->assertJson($content);
$this->assertEquals(array(
'letudiant/foo-bar/dev-develop' => array(
'installation-source' => 'source',
'installation-source' => SharedPackageDataManager::PACKAGE_INSTALLATION_SOURCE,
'project-usage' => array(
'letudiant/root-package',
'letudiant/root-package2'
Expand All @@ -197,45 +195,6 @@ public function addPackageUsageWithHasData()
), json_decode($content, true));
}

/**
* @test
*
* @expectedException \RuntimeException
* @expectedExceptionMessage Unknown installation source for package "letudiant/foo-bar" ("dev-develop")
*/
public function packageWithoutInstallationSource()
{
$dataManager = new SharedPackageDataManager($this->composer);
$dataManager->setVendorDir($this->vendorDir);

$this->rootPackage
->expects($this->once())
->method('getName')
->willReturn('letudiant/root-package')
;

$package = $this->getMock('Composer\Package\PackageInterface');
$package
->expects($this->exactly(3))
->method('getPrettyName')
->willReturn('letudiant/foo-bar')
;

$package
->expects($this->exactly(3))
->method('getPrettyVersion')
->willReturn('dev-develop')
;

$package
->expects($this->once())
->method('getInstallationSource')
->willReturn(null)
;

$dataManager->addPackageUsage($package);
}

/**
* @test
*/
Expand Down Expand Up @@ -338,7 +297,7 @@ public function removePackageUsageWithData()
$this->assertJson($content);
$this->assertEquals(array(
'letudiant/foo-bar/dev-develop' => array(
'installation-source' => 'source',
'installation-source' => SharedPackageDataManager::PACKAGE_INSTALLATION_SOURCE,
'project-usage' => array(
'letudiant/root-package'
)
Expand All @@ -354,12 +313,6 @@ public function setPackageInstallationSourceWhenNotNull()
$package = $this->getMock('Composer\Package\PackageInterface');
$package
->expects($this->once())
->method('getInstallationSource')
->willReturn('source')
;

$package
->expects($this->never())
->method('setInstallationSource')
;

Expand All @@ -374,17 +327,11 @@ public function setPackageInstallationSourceWhenNotNull()
*/
public function setPackageInstallationSourceWhenNull()
{
$package = $this->createPackage();
$package
->expects($this->once())
->method('getInstallationSource')
->willReturn(null)
;

$package = $this->getMock('Composer\Package\PackageInterface');
$package
->expects($this->once())
->method('setInstallationSource')
->with('source')
->with(SharedPackageDataManager::PACKAGE_INSTALLATION_SOURCE)
;

$this->initializePackageData();
Expand All @@ -398,17 +345,11 @@ public function setPackageInstallationSourceWhenNull()
*/
public function setPackageInstallationSourceWhenNullAndNoData()
{
$package = $this->createPackage();
$package
->expects($this->once())
->method('getInstallationSource')
->willReturn(null)
;

$package = $this->getMock('Composer\Package\PackageInterface');
$package
->expects($this->once())
->method('setInstallationSource')
->with(null)
->with(SharedPackageDataManager::PACKAGE_INSTALLATION_SOURCE)
;

$dataManager = new SharedPackageDataManager($this->composer);
Expand All @@ -423,7 +364,7 @@ protected function initializePackageData()
{
file_put_contents($this->vendorDir . '/' . SharedPackageDataManager::PACKAGE_DATA_FILENAME, json_encode(array(
'letudiant/foo-bar/dev-develop' => array(
'installation-source' => 'source',
'installation-source' => SharedPackageDataManager::PACKAGE_INSTALLATION_SOURCE,
'project-usage' => array(
'letudiant/root-package'
)
Expand Down
Expand Up @@ -22,6 +22,7 @@
use Composer\TestCase;
use Composer\Util\Filesystem;
use LEtudiant\Composer\Data\Package\PackageDataManagerInterface;
use LEtudiant\Composer\Data\Package\SharedPackageDataManager;
use LEtudiant\Composer\Installer\Config\SharedPackageInstallerConfig;
use LEtudiant\Composer\Installer\SharedPackageInstaller;
use LEtudiant\Composer\Util\SymlinkFilesystem;
Expand Down Expand Up @@ -647,7 +648,7 @@ protected function createPackageMock($prettyName = 'letudiant/foo-bar')
$package
->expects($this->any())
->method('getInstallationSource')
->willReturn('source')
->willReturn(SharedPackageDataManager::PACKAGE_INSTALLATION_SOURCE)
;

return $package;
Expand Down
Expand Up @@ -14,6 +14,7 @@
use Composer\Installer\LibraryInstaller;
use Composer\Package\Package;
use Composer\Repository\InstalledRepositoryInterface;
use LEtudiant\Composer\Data\Package\SharedPackageDataManager;
use LEtudiant\Composer\Installer\Config\SharedPackageInstallerConfig;
use LEtudiant\Composer\Installer\Solver\SharedPackageSolver;
use LEtudiant\Composer\Installer\SharedPackageInstaller;
Expand Down Expand Up @@ -210,7 +211,7 @@ protected function createPackageMock()
$package
->expects($this->any())
->method('getInstallationSource')
->willReturn('source')
->willReturn(SharedPackageDataManager::PACKAGE_INSTALLATION_SOURCE)
;

return $package;
Expand Down

0 comments on commit 35d734c

Please sign in to comment.