Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function accept()
 {
     $dir = $this->isCurrentDir();
     if ($this->subscriber->isAllowed($this->key(), $dir)) {
         if (is_string($this->current())) {
             return $this->subscriber->isAllowed($this->current(), $dir);
         }
         return true;
     }
     return false;
 }
 /**
  * Verifies that we can filter entries in an iterator.
  *
  * @covers \Box\Component\Builder\Iterator\FilterIterator
  */
 public function testOnBuildFromIterator()
 {
     // only allow one path
     $this->subscriber->expects(self::exactly(5))->method('isAllowed')->with(self::anything(), true)->willReturnCallback(function ($path) {
         return false !== strpos($path, 'to/a');
     });
     // make sure we only see allowed paths
     mkdir($this->dir . '/to/a', 0755, true);
     mkdir($this->dir . '/to/b', 0755, true);
     $iterator = new ArrayIterator(array('to/a' => $this->dir . '/to/a', 'to/b' => $this->dir . '/to/b'));
     $event = new PreBuildFromIteratorEvent($this->builder, $iterator);
     $this->subscriber->onBuildFromIterator($event);
     foreach ($event->getIterator() as $key => $value) {
         self::assertEquals('to/a', $key);
     }
     // make sure we only see allowed local paths
     $iterator = new ArrayIterator(array($this->dir . '/to/a' => 123, 'to/b' => new SplFileInfo($this->dir . '/to/b')));
     $event = new PreBuildFromIteratorEvent($this->builder, $iterator);
     $this->subscriber->onBuildFromIterator($event);
     foreach ($event->getIterator() as $key => $value) {
         self::assertEquals($this->dir . '/to/a', $key);
     }
 }