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

removePackageUsage() public method

Remove the row in the "packages.json" file
public removePackageUsage ( Composer\Package\PackageInterface $package )
$package Composer\Package\PackageInterface
    public function removePackageUsage(PackageInterface $package)
    {
        $usageData = $this->getPackageUsage($package);
        $newUsageData = array();
        $projectName = $this->composer->getPackage()->getName();
        foreach ($usageData as $usage) {
            if ($projectName !== $usage) {
                $newUsageData[] = $usage;
            }
        }
        $this->updatePackageUsageFile($package, $newUsageData);
    }

Usage Example

 /**
  * @test
  */
 public function removePackageUsageWithData()
 {
     $this->initializePackageData();
     $dataManager = new SharedPackageDataManager($this->composer);
     $dataManager->setVendorDir($this->vendorDir);
     $this->rootPackage->expects($this->exactly(2))->method('getName')->will($this->onConsecutiveCalls('letudiant/root-package', 'letudiant/root-package2'));
     $package = $this->getMock('Composer\\Package\\PackageInterface');
     $package->expects($this->exactly(4))->method('getPrettyName')->willReturn('letudiant/foo-bar');
     $package->expects($this->exactly(4))->method('getPrettyVersion')->willReturn('dev-develop');
     $package->expects($this->exactly(0))->method('getInstallationSource');
     // Remove the right package
     $this->initializePackageData();
     $dataManager->removePackageUsage($package);
     $this->assertFileExists($this->vendorDir . '/' . SharedPackageDataManager::PACKAGE_DATA_FILENAME);
     $content = file_get_contents($this->vendorDir . '/' . SharedPackageDataManager::PACKAGE_DATA_FILENAME);
     $this->assertJson($content);
     $this->assertEquals(array(), json_decode($content, true));
     // Remove another package, should not remove the initial package
     $this->initializePackageData();
     $dataManager = new SharedPackageDataManager($this->composer);
     $dataManager->setVendorDir($this->vendorDir);
     $dataManager->removePackageUsage($package);
     $this->assertFileExists($this->vendorDir . '/' . SharedPackageDataManager::PACKAGE_DATA_FILENAME);
     $content = file_get_contents($this->vendorDir . '/' . SharedPackageDataManager::PACKAGE_DATA_FILENAME);
     $this->assertJson($content);
     $this->assertEquals(array('letudiant/foo-bar/dev-develop' => array('installation-source' => 'source', 'project-usage' => array('letudiant/root-package'))), json_decode($content, true));
 }