PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/Filesystem/FilesystemTest.php

https://bitbucket.org/mikebosire/framework
PHP | 110 lines | 89 code | 21 blank | 0 comment | 0 complexity | a3a1967cba9559d53a00bfe99b5d854f MD5 | raw file
  1. <?php
  2. use Illuminate\Filesystem\Filesystem;
  3. class FilesystemTest extends PHPUnit_Framework_TestCase {
  4. public function testGetRetrievesFiles()
  5. {
  6. file_put_contents(__DIR__.'/file.txt', 'Hello World');
  7. $files = new Filesystem;
  8. $this->assertEquals('Hello World', $files->get(__DIR__.'/file.txt'));
  9. @unlink(__DIR__.'/file.txt');
  10. }
  11. public function testPutStoresFiles()
  12. {
  13. $files = new Filesystem;
  14. $files->put(__DIR__.'/file.txt', 'Hello World');
  15. $this->assertEquals('Hello World', file_get_contents(__DIR__.'/file.txt'));
  16. @unlink(__DIR__.'/file.txt');
  17. }
  18. public function testDeleteRemovesFiles()
  19. {
  20. file_put_contents(__DIR__.'/file.txt', 'Hello World');
  21. $files = new Filesystem;
  22. $files->delete(__DIR__.'/file.txt');
  23. $this->assertFalse(file_exists(__DIR__.'/file.txt'));
  24. @unlink(__DIR__.'/file.txt');
  25. }
  26. public function testDeleteDirectory()
  27. {
  28. mkdir(__DIR__.'/foo');
  29. file_put_contents(__DIR__.'/foo/file.txt', 'Hello World');
  30. $files = new Filesystem;
  31. $files->deleteDirectory(__DIR__.'/foo');
  32. $this->assertFalse(is_dir(__DIR__.'/foo'));
  33. $this->assertFalse(file_exists(__DIR__.'/foo/file.txt'));
  34. }
  35. public function testCleanDirectory()
  36. {
  37. mkdir(__DIR__.'/foo');
  38. file_put_contents(__DIR__.'/foo/file.txt', 'Hello World');
  39. $files = new Filesystem;
  40. $files->cleanDirectory(__DIR__.'/foo');
  41. $this->assertTrue(is_dir(__DIR__.'/foo'));
  42. $this->assertFalse(file_exists(__DIR__.'/foo/file.txt'));
  43. @rmdir(__DIR__.'/foo');
  44. }
  45. public function testFilesMethod()
  46. {
  47. mkdir(__DIR__.'/foo');
  48. file_put_contents(__DIR__.'/foo/1.txt', '1');
  49. file_put_contents(__DIR__.'/foo/2.txt', '2');
  50. mkdir(__DIR__.'/foo/bar');
  51. $files = new Filesystem;
  52. $this->assertEquals(array(__DIR__.'/foo/1.txt', __DIR__.'/foo/2.txt'), $files->files(__DIR__.'/foo'));
  53. unset($files);
  54. @unlink(__DIR__.'/foo/1.txt');
  55. @unlink(__DIR__.'/foo/2.txt');
  56. @rmdir(__DIR__.'/foo/bar');
  57. @rmdir(__DIR__.'/foo');
  58. }
  59. public function testCopyDirectoryReturnsFalseIfSourceIsntDirectory()
  60. {
  61. $files = new Filesystem;
  62. $this->assertFalse($files->copyDirectory(__DIR__.'/foo/bar/baz/breeze/boom', __DIR__));
  63. }
  64. public function testCopyDirectoryMovesEntireDirectory()
  65. {
  66. mkdir(__DIR__.'/tmp', 0777, true);
  67. file_put_contents(__DIR__.'/tmp/foo.txt', '');
  68. file_put_contents(__DIR__.'/tmp/bar.txt', '');
  69. mkdir(__DIR__.'/tmp/nested', 0777, true);
  70. file_put_contents(__DIR__.'/tmp/nested/baz.txt', '');
  71. $files = new Filesystem;
  72. $files->copyDirectory(__DIR__.'/tmp', __DIR__.'/tmp2');
  73. $this->assertTrue(is_dir(__DIR__.'/tmp2'));
  74. $this->assertTrue(file_exists(__DIR__.'/tmp2/foo.txt'));
  75. $this->assertTrue(file_exists(__DIR__.'/tmp2/bar.txt'));
  76. $this->assertTrue(is_dir(__DIR__.'/tmp2/nested'));
  77. $this->assertTrue(file_exists(__DIR__.'/tmp2/nested/baz.txt'));
  78. unlink(__DIR__.'/tmp/nested/baz.txt');
  79. rmdir(__DIR__.'/tmp/nested');
  80. unlink(__DIR__.'/tmp/bar.txt');
  81. unlink(__DIR__.'/tmp/foo.txt');
  82. rmdir(__DIR__.'/tmp');
  83. unlink(__DIR__.'/tmp2/nested/baz.txt');
  84. rmdir(__DIR__.'/tmp2/nested');
  85. unlink(__DIR__.'/tmp2/foo.txt');
  86. unlink(__DIR__.'/tmp2/bar.txt');
  87. rmdir(__DIR__.'/tmp2');
  88. }
  89. }