FileTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * Lithium: the most rad php framework
  4. *
  5. * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
  6. * @license http://opensource.org/licenses/bsd-license.php The BSD License
  7. */
  8. namespace lithium\tests\cases\analysis\logger\adapter;
  9. use lithium\core\Libraries;
  10. use lithium\util\collection\Filters;
  11. use lithium\analysis\logger\adapter\File;
  12. class FileTest extends \lithium\test\Unit {
  13. public $subject;
  14. public function skip() {
  15. $path = realpath(Libraries::get(true, 'resources') . '/tmp/logs');
  16. $this->skipIf(!is_writable($path), "Path `{$path}` is not writable.");
  17. }
  18. public function setUp() {
  19. $this->path = Libraries::get(true, 'resources') . '/tmp/logs';
  20. $this->tearDown();
  21. }
  22. public function tearDown() {
  23. if (file_exists("{$this->path}/debug.log")) {
  24. unlink("{$this->path}/debug.log");
  25. }
  26. }
  27. public function testWriting() {
  28. $this->subject = new File(array('path' => $this->path));
  29. $priority = 'debug';
  30. $message = 'This is a debug message';
  31. $function = $this->subject->write($priority, $message);
  32. $now = date('Y-m-d H:i:s');
  33. $function('lithium\analysis\Logger', compact('priority', 'message'), new Filters());
  34. $log = file_get_contents("{$this->path}/debug.log");
  35. $this->assertEqual("{$now} This is a debug message\n", $log);
  36. }
  37. public function testWithoutTimestamp() {
  38. $this->subject = new File(array(
  39. 'path' => $this->path, 'timestamp' => false, 'format' => "{:message}\n"
  40. ));
  41. $priority = 'debug';
  42. $message = 'This is a debug message';
  43. $function = $this->subject->write($priority, $message);
  44. $now = date('Y-m-d H:i:s');
  45. $function('lithium\analysis\Logger', compact('priority', 'message'), new Filters());
  46. $log = file_get_contents("{$this->path}/debug.log");
  47. $this->assertEqual("This is a debug message\n", $log);
  48. }
  49. }
  50. ?>