You are here

class vfsStreamContainerIteratorTestCase in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/mikey179/vfsStream/src/test/php/org/bovigo/vfs/vfsStreamContainerIteratorTestCase.php \org\bovigo\vfs\vfsStreamContainerIteratorTestCase

Test for org\bovigo\vfs\vfsStreamContainerIterator.

Hierarchy

Expanded class hierarchy of vfsStreamContainerIteratorTestCase

File

vendor/mikey179/vfsStream/src/test/php/org/bovigo/vfs/vfsStreamContainerIteratorTestCase.php, line 14

Namespace

org\bovigo\vfs
View source
class vfsStreamContainerIteratorTestCase extends \PHPUnit_Framework_TestCase {

  /**
   * instance to test
   *
   * @type  vfsStreamDirectory
   */
  private $dir;

  /**
   * child one
   *
   * @type  \PHPUnit_Framework_MockObject_MockObject
   */
  private $mockChild1;

  /**
   * child two
   *
   * @type  \PHPUnit_Framework_MockObject_MockObject
   */
  private $mockChild2;

  /**
   * set up test environment
   */
  public function setUp() {
    $this->dir = new vfsStreamDirectory('foo');
    $this->mockChild1 = $this
      ->getMock('org\\bovigo\\vfs\\vfsStreamContent');
    $this->mockChild1
      ->expects($this
      ->any())
      ->method('getName')
      ->will($this
      ->returnValue('bar'));
    $this->dir
      ->addChild($this->mockChild1);
    $this->mockChild2 = $this
      ->getMock('org\\bovigo\\vfs\\vfsStreamContent');
    $this->mockChild2
      ->expects($this
      ->any())
      ->method('getName')
      ->will($this
      ->returnValue('baz'));
    $this->dir
      ->addChild($this->mockChild2);
  }

  /**
   * clean up test environment
   */
  public function tearDown() {
    vfsStream::enableDotfiles();
  }

  /**
   * @return  array
   */
  public function provideSwitchWithExpectations() {
    return array(
      array(
        function () {
          vfsStream::disableDotfiles();
        },
        array(),
      ),
      array(
        function () {
          vfsStream::enableDotfiles();
        },
        array(
          '.',
          '..',
        ),
      ),
    );
  }
  private function getDirName($dir) {
    if (is_string($dir)) {
      return $dir;
    }
    return $dir
      ->getName();
  }

  /**
   * @param  \Closure  $dotFilesSwitch
   * @param  array     $dirNames
   * @test
   * @dataProvider  provideSwitchWithExpectations
   */
  public function iteration(\Closure $dotFilesSwitch, array $dirs) {
    $dirs[] = $this->mockChild1;
    $dirs[] = $this->mockChild2;
    $dotFilesSwitch();
    $dirIterator = $this->dir
      ->getIterator();
    foreach ($dirs as $dir) {
      $this
        ->assertEquals($this
        ->getDirName($dir), $dirIterator
        ->key());
      $this
        ->assertTrue($dirIterator
        ->valid());
      if (!is_string($dir)) {
        $this
          ->assertSame($dir, $dirIterator
          ->current());
      }
      $dirIterator
        ->next();
    }
    $this
      ->assertFalse($dirIterator
      ->valid());
    $this
      ->assertNull($dirIterator
      ->key());
    $this
      ->assertNull($dirIterator
      ->current());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
vfsStreamContainerIteratorTestCase::$dir private property instance to test
vfsStreamContainerIteratorTestCase::$mockChild1 private property child one
vfsStreamContainerIteratorTestCase::$mockChild2 private property child two
vfsStreamContainerIteratorTestCase::getDirName private function
vfsStreamContainerIteratorTestCase::iteration public function @test @dataProvider provideSwitchWithExpectations
vfsStreamContainerIteratorTestCase::provideSwitchWithExpectations public function
vfsStreamContainerIteratorTestCase::setUp public function set up test environment
vfsStreamContainerIteratorTestCase::tearDown public function clean up test environment