LoggerTest.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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\integration\analysis;
  9. use lithium\core\Libraries;
  10. use lithium\analysis\Logger;
  11. use lithium\util\collection\Filters;
  12. /**
  13. * Logger adapter integration test cases
  14. */
  15. class LoggerTest extends \lithium\test\Integration {
  16. public function testWriteFilter() {
  17. $base = Libraries::get(true, 'resources') . '/tmp/logs';
  18. $this->skipIf(!is_writable($base), "Path `{$base}` is not writable.");
  19. Filters::apply('lithium\analysis\Logger', 'write', function($self, $params, $chain) {
  20. $params['message'] = 'Filtered Message';
  21. return $chain->next($self, $params, $chain);
  22. });
  23. $config = array('default' => array(
  24. 'adapter' => 'File', 'timestamp' => false, 'format' => "{:message}\n"
  25. ));
  26. Logger::config($config);
  27. $result = Logger::write('info', 'Original Message');
  28. $this->assertTrue(file_exists($base . '/info.log'));
  29. $expected = "Filtered Message\n";
  30. $result = file_get_contents($base . '/info.log');
  31. $this->assertEqual($expected, $result);
  32. unlink($base . '/info.log');
  33. }
  34. }
  35. ?>