FileTest.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. require_once 'FSTools/FileSystemHarness.php';
  3. /**
  4. * These are not really unit tests, just sanity checks of basic functionality.
  5. */
  6. class FSTools_FileTest extends FSTools_FileSystemHarness
  7. {
  8. function test() {
  9. $name = 'test.txt';
  10. $file = new FSTools_File($name);
  11. $this->assertFalse($file->exists());
  12. $file->write('foobar');
  13. $this->assertTrue($file->exists());
  14. $this->assertEqual($file->get(), 'foobar');
  15. $file->delete();
  16. $this->assertFalse($file->exists());
  17. }
  18. function testGetNonExistent() {
  19. $name = 'notfound.txt';
  20. $file = new FSTools_File($name);
  21. $this->expectError();
  22. $this->assertFalse($file->get());
  23. }
  24. function testHandle() {
  25. $file = new FSTools_File('foo.txt');
  26. $this->assertFalse($file->exists());
  27. $file->open('w');
  28. $this->assertTrue($file->exists());
  29. $file->put('Foobar');
  30. $file->close();
  31. $file->open('r');
  32. $this->assertIdentical('F', $file->getChar());
  33. $this->assertFalse($file->eof());
  34. $this->assertIdentical('oo', $file->read(2));
  35. $this->assertIdentical('bar', $file->getLine());
  36. $this->assertTrue($file->eof());
  37. }
  38. }
  39. // vim: et sw=4 sts=4