addConflict() public method

A mapping can refer to at most one conflict per conflicting repository path. If the same conflict is added twice, the second addition is ignored. If a different conflict is added for an existing repository path, the previous conflict is removed before adding the new conflict for the repository path. The repository path of the conflict must either be the repository path of the mapping or any path within. If a conflict with a different path is added, an exception is thrown. The method {@link load()} needs to be called before calling this method, otherwise an exception is thrown.
public addConflict ( Puli\Manager\Api\Repository\PathConflict $conflict )
$conflict Puli\Manager\Api\Repository\PathConflict The conflict to be added.
Esempio n. 1
0
 /**
  * Adds a path mapping involved in the conflict.
  *
  * @param PathMapping $mapping The path mapping to add.
  *
  * @throws NotLoadedException If the passed mapping is not loaded.
  */
 public function addMapping(PathMapping $mapping)
 {
     if (!$mapping->isLoaded()) {
         throw new NotLoadedException('The passed mapping must be loaded.');
     }
     $packageName = $mapping->getContainingPackage()->getName();
     $previousMapping = isset($this->mappings[$packageName]) ? $this->mappings[$packageName] : null;
     if ($previousMapping === $mapping) {
         return;
     }
     if ($previousMapping) {
         $previousMapping->removeConflict($this);
     }
     $this->mappings[$packageName] = $mapping;
     $mapping->addConflict($this);
 }
Esempio n. 2
0
 public function testGetConflictingMappings()
 {
     $mapping1 = new PathMapping('/path', 'resources');
     $mapping1->load($this->package1, $this->packages);
     $this->assertCount(0, $mapping1->getConflictingMappings());
     $mapping2 = new PathMapping('/path', 'resources');
     $mapping2->load($this->package2, $this->packages);
     $conflict = new PathConflict('/path/conflict');
     $mapping1->addConflict($conflict);
     $mapping2->addConflict($conflict);
     $this->assertCount(1, $mapping1->getConflictingMappings());
     $this->assertContains($mapping2, $mapping1->getConflictingMappings());
     $this->assertCount(1, $mapping2->getConflictingMappings());
     $this->assertContains($mapping1, $mapping2->getConflictingMappings());
     $mapping3 = new PathMapping('/path', 'resources');
     $mapping3->load($this->package3, $this->packages);
     $mapping3->addConflict($conflict);
     $this->assertCount(2, $mapping1->getConflictingMappings());
     $this->assertContains($mapping2, $mapping1->getConflictingMappings());
     $this->assertContains($mapping3, $mapping1->getConflictingMappings());
     $this->assertCount(2, $mapping2->getConflictingMappings());
     $this->assertContains($mapping1, $mapping2->getConflictingMappings());
     $this->assertContains($mapping3, $mapping2->getConflictingMappings());
     $this->assertCount(2, $mapping3->getConflictingMappings());
     $this->assertContains($mapping1, $mapping3->getConflictingMappings());
     $this->assertContains($mapping2, $mapping3->getConflictingMappings());
 }