/test/lib/Elastica/Test/LogTest.php

https://github.com/nordsee/Elastica · PHP · 57 lines · 42 code · 14 blank · 1 comment · 0 complexity · ebd3a768e657cb61f1565127404fbe0b MD5 · raw file

  1. <?php
  2. namespace Elastica\Test;
  3. use Elastica\Client;
  4. use Elastica\Log;
  5. use Elastica\Test\Base as BaseTest;
  6. class LogTest extends BaseTest
  7. {
  8. public function testSetLogConfigPath()
  9. {
  10. $logPath = '/tmp/php.log';
  11. $client = new Client(array('log' => $logPath));
  12. $this->assertEquals($logPath, $client->getConfig('log'));
  13. }
  14. public function testSetLogConfigEnable()
  15. {
  16. $client = new Client(array('log' => true));
  17. $this->assertTrue($client->getConfig('log'));
  18. }
  19. public function testEmptyLogConfig()
  20. {
  21. $client = $this->_getClient();
  22. $this->assertEmpty($client->getConfig('log'));
  23. }
  24. public function testGetLastMessage()
  25. {
  26. $log = new Log('/tmp/php.log');
  27. $message = 'hello world';
  28. $log->log($message);
  29. $this->assertEquals($message, $log->getLastMessage());
  30. }
  31. public function testGetLastMessage2()
  32. {
  33. $client = new Client(array('log' => true));
  34. $log = new Log($client);
  35. // Set log path temp path as otherwise test fails with output
  36. $errorLog = ini_get('error_log');
  37. ini_set('error_log', sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'php.log');
  38. $message = 'hello world';
  39. $log->log($message);
  40. ini_set('error_log', $errorLog);
  41. $this->assertEquals($message, $log->getLastMessage());
  42. }
  43. }