Ejemplo n.º 1
0
 /** Filesystem */
 public function testFs()
 {
     $dir = __DIR__ . '/03/output';
     $command = new Commands\Filesystem\Directory();
     $command->clean($dir);
     $res = glob($dir . "/*");
     $this->assertCount(0, $res);
     $command = new Commands\Filesystem\Directory();
     $command->create($dir . '/test-dir', 777);
     $this->assertFileExists($dir . '/test-dir');
     $iterator = $command->read($dir);
     $this->assertCount(1, $iterator);
     $this->assertEquals('test-dir', $iterator->current()->getFileName());
     $command = new Commands\Filesystem\File();
     $command->create($dir . '/testfile.json', '{}');
     $this->assertFileExists($dir . '/testfile.json');
     $this->assertEquals('{}', file_get_contents($dir . '/testfile.json'));
     $command = new Commands\Filesystem\File();
     $command->copy($dir . '/testfile.json', $dir . '/testfile2.json');
     $this->assertFileExists($dir . '/testfile.json');
     // old file still exists
     $this->assertFileExists($dir . '/testfile2.json');
     $this->assertEquals('{}', file_get_contents($dir . '/testfile2.json'));
     $command = new Commands\Filesystem\Symlink();
     $command->create($dir . '/testfile.json', $dir . '/sym-testfile.json');
     $this->assertFileExists($dir . '/sym-testfile.json');
     $this->assertTrue(is_link($dir . '/sym-testfile.json'));
     $command = new Commands\Filesystem\File();
     $command->delete($dir . '/testfile.json');
     $this->assertFileNotExists($dir . '/testfile.json');
     $command = new Commands\Filesystem\Directory();
     $command->clean($dir);
     $res = glob($dir . "/*");
     $this->assertCount(0, $res);
     // filesystem class
     $command = new Commands\Filesystem\Filesystem();
     $command->addDirectoriesToCreate([$dir . '/testfs1' => 777]);
     $command->addDirectoriesToCreate([$dir . '/testfs2' => 777]);
     $command->addFilesToCopy([$dir . '/testfs2/test.js' => $dir . '/../gulpfile.js']);
     ob_start();
     $command->execute();
     ob_end_clean();
     $res = glob($dir . "/*");
     $this->assertCount(2, $res);
     $this->assertTrue(is_dir($dir . '/testfs1'));
     $this->assertTrue(is_dir($dir . '/testfs2'));
     $this->assertFileExists($dir . '/testfs2/test.js');
     $command = new Commands\Filesystem\Filesystem();
     $command->addDirectoriesToClean([$dir]);
     ob_start();
     $command->execute();
     ob_end_clean();
     $res = glob($dir . "/*");
     $this->assertCount(0, $res);
 }