Exemplo n.º 1
0
 public function testSegments()
 {
     $p = new Path('this/is/the/path/to/my/file.ext');
     $this->assertEquals(new ArrayObject(['this', 'is', 'the', 'path', 'to', 'my', 'file.ext']), $p->segments());
     $this->assertEquals(7, $p->segmentCount());
     $this->assertNull($p->segment(-1));
     $this->assertEquals('is', $p->segment(1));
     $this->assertEquals('file.ext', $p->lastSegment());
     $this->assertEquals('this/is/the', $p->upToSegment(3)->toString());
     $this->assertEquals('the/path/to/my/file.ext', $p->removeFirstSegments(2)->toString());
     $this->assertEquals('this/is/the/path/to', $p->removeLastSegments(2)->toString());
     $this->assertEquals('file.ext', $p->lastSegment());
     $this->assertEquals('', $p->upToSegment(0)->toString());
 }
Exemplo n.º 2
0
 /**
  * Returns a count of the number of segments which match in this 
  * path and the given path, comparing in increasing segment number order.
  * 
  * @param Path $anotherPath
  * @return int
  */
 public function matchingFirstSegments(Path $anotherPath)
 {
     $segments = $anotherPath->segments();
     $count = 0;
     foreach ($this->segments as $i => $segment) {
         if ($segment != $segments[$i]) {
             break;
         }
         $count++;
     }
     return $count;
 }