FileSystemTest

The Gravity PDF FileSystemTest class.

Defined (1)

The class is defined in the following location(s).

/vendor/codeguy/upload/tests/Storage/FileSystemTest.php  
  1. class FileSystemTest extends PHPUnit_Framework_TestCase 
  2. /** 
  3. * Setup (each test) 
  4. */ 
  5. public function setUp() 
  6. // Path to test assets 
  7. $this->assetsDirectory = dirname(__DIR__) . '/assets'; 
  8.  
  9. // Reset $_FILES superglobal 
  10. $_FILES['foo'] = array( 
  11. 'name' => 'foo.txt',  
  12. 'tmp_name' => $this->assetsDirectory . '/foo.txt',  
  13. 'error' => 0 
  14. ); 
  15.  
  16. public function testInstantiationWithValidDirectory() 
  17. try { 
  18. $storage = $this->getMock( 
  19. '\Upload\Storage\FileSystem',  
  20. array('upload'),  
  21. array($this->assetsDirectory) 
  22. ); 
  23. } catch(\InvalidArgumentException $e) { 
  24. $this->fail('Unexpected argument thrown during instantiation with valid directory'); 
  25.  
  26. /** 
  27. * @expectedException \InvalidArgumentException 
  28. */ 
  29. public function testInstantiationWithInvalidDirectory() 
  30. $storage = $this->getMock( 
  31. '\Upload\Storage\FileSystem',  
  32. array('upload'),  
  33. array('/foo') 
  34. ); 
  35.  
  36. /** 
  37. * Test won't overwrite existing file 
  38. * @expectedException \RuntimeException 
  39. */ 
  40. public function testWillNotOverwriteFile() 
  41. $storage = new \Upload\Storage\FileSystem($this->assetsDirectory, false); 
  42. $file = new \Upload\File('foo', $storage); 
  43. $file->upload(); 
  44.  
  45. /** 
  46. * Test will overwrite existing file 
  47. */ 
  48. public function testWillOverwriteFile() 
  49. $storage = $this->getMock( 
  50. '\Upload\Storage\FileSystem',  
  51. array('moveUploadedFile'),  
  52. array($this->assetsDirectory, true) 
  53. ); 
  54. $storage->expects($this->any()) 
  55. ->method('moveUploadedFile') 
  56. ->will($this->returnValue(true)); 
  57. $file = $this->getMock( 
  58. '\Upload\File',  
  59. array('isUploadedFile'),  
  60. array('foo', $storage) 
  61. ); 
  62. $file->expects($this->any()) 
  63. ->method('isUploadedFile') 
  64. ->will($this->returnValue(true)); 
  65. $this->assertTrue($file->upload());