LEtudiant\Composer\Data\Package\SharedPackageDataManager::addPackageUsage PHP Method

addPackageUsage() public method

Add a row in the "packages.json" file, with the project name for the "package/version" key
public addPackageUsage ( Composer\Package\PackageInterface $package )
$package Composer\Package\PackageInterface
    public function addPackageUsage(PackageInterface $package)
    {
        $usageData = $this->getPackageUsage($package);
        $packageName = $this->composer->getPackage()->getName();
        if (!in_array($packageName, $usageData)) {
            $usageData[] = $packageName;
        }
        $this->updatePackageUsageFile($package, $usageData);
    }

Usage Example

 /**
  * @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);
 }