Example #1
0
 public function testIterator()
 {
     $dir = new Directory($this->root->url() . '/prj');
     $dir->make();
     $path = $dir->toPath();
     $composer = $path->append('composer.json');
     $file = $composer->toFileDescriptor()->toFile();
     $file->write('{}');
     $vendor = $path->append('vendor');
     $folder = $vendor->toFileDescriptor()->toDirectory();
     $folder->make();
     $arr = new ArrayObject();
     foreach ($dir as $k => $file) {
         if (!$file->isDot()) {
             $this->assertTrue($file instanceof FileDescriptor);
             $arr[$k] = $file->getFilename();
             if ($file->isFile()) {
                 $this->assertEquals('composer.json', $file->getFilename());
             }
             if ($file->isDir()) {
                 $this->assertEquals('vendor', $file->getFilename());
             }
         }
     }
     $this->assertEquals(['composer.json', 'vendor'], $arr->sort()->toArray());
 }
Example #2
0
 public function testMutators()
 {
     $base = ['b', 'c', 'd'];
     $arr = new ArrayObject($base);
     $arr->push('e', 'f');
     $this->assertEquals(['b', 'c', 'd', 'e', 'f'], $arr->toArray());
     $this->assertEquals('f', $arr->pop());
     $this->assertEquals('e', $arr->pop());
     $arr->prepend('a');
     $this->assertEquals(['a', 'b', 'c', 'd'], $arr->toArray());
     $this->assertEquals('a', $arr->shift());
     $this->assertEquals($base, $arr->toArray());
 }
Example #3
0
 /**
  * Returns a copy of this path truncated after the given number of segments.
  * 
  * @param int $count
  * @return Path
  */
 public function upToSegment($count)
 {
     $segments = new ArrayObject();
     for ($i = 0; $i < $count; $i++) {
         $segments->push($this->segments[$i]);
     }
     return new Path($segments->join('/'));
 }