You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.4 KiB

  1. <?php
  2. /*
  3. * @copyright NetMonsters <team@netmonsters.ru>
  4. * @link http://netmonsters.ru
  5. * @package Majestic
  6. * @subpackage UnitTests
  7. * @since 2011-10-06
  8. *
  9. * Unit tests for CliLogger class
  10. */
  11. require_once dirname(__FILE__) . '/../../Registry.php';
  12. require_once dirname(__FILE__) . '/../../Config.php';
  13. require_once dirname(__FILE__) . '/../../logger/Logger.php';
  14. require_once dirname(__FILE__) . '/../../logger/CliLogger.php';
  15. class CliLoggerTest extends PHPUnit_Framework_TestCase
  16. {
  17. public function run(PHPUnit_Framework_TestResult $result = NULL)
  18. {
  19. $this->setPreserveGlobalState(false);
  20. return parent::run($result);
  21. }
  22. public function setUp()
  23. {
  24. Config::set('Logger', array('logger' => 'CliLogger'));
  25. }
  26. /**
  27. * @runInSeparateProcess
  28. */
  29. public function testGetInstance()
  30. {
  31. $logger = Logger::getInstance();
  32. $this->assertInstanceOf('CliLogger', $logger);
  33. }
  34. /**
  35. * @runInSeparateProcess
  36. */
  37. public function testLog()
  38. {
  39. Config::set('LOGGING', true);
  40. Config::set('Logger', array('logger' => 'CliLogger'));
  41. $logger = Logger::getInstance();
  42. ob_start();
  43. $logger->setPid(123);
  44. $logger->log('new msg');
  45. $out = ob_get_clean();
  46. $this->assertContains('<123> new msg', $out);
  47. }
  48. public function tearDown()
  49. {
  50. $conf = Config::getInstance();
  51. $conf->offsetUnset('Logger');
  52. }
  53. }