PageRenderTime 49ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/test/lib/Elastica/LogTest.php

https://github.com/philippfrenzel/Elastica
PHP | 64 lines | 47 code | 16 blank | 1 comment | 0 complexity | 28aad2c322bb598c577fe15f3cebe2cc MD5 | raw file
Possible License(s): Apache-2.0
  1. <?php
  2. require_once dirname(__FILE__) . '/../../bootstrap.php';
  3. class Elastica_LogTest extends Elastica_Test
  4. {
  5. public function testSetLogConfigPath()
  6. {
  7. $logPath = '/tmp/php.log';
  8. $client = new Elastica_Client(array('log' => $logPath));
  9. $this->assertEquals($logPath, $client->getConfig('log'));
  10. }
  11. public function testSetLogConfigEnable()
  12. {
  13. $client = new Elastica_Client(array('log' => true));
  14. $this->assertTrue($client->getConfig('log'));
  15. }
  16. public function testEmptyLogConfig()
  17. {
  18. $client = new Elastica_Client();
  19. $this->assertEmpty($client->getConfig('log'));
  20. }
  21. public function testDisabledLog()
  22. {
  23. $client = new Elastica_Client();
  24. $log = new Elastica_Log($client);
  25. $log->log('hello world');
  26. $this->assertEmpty($log->getLastMessage());
  27. }
  28. public function testGetLastMessage()
  29. {
  30. $client = new Elastica_Client(array('log' => '/tmp/php.log'));
  31. $log = new Elastica_Log($client);
  32. $message = 'hello world';
  33. $log->log($message);
  34. $this->assertEquals($message, $log->getLastMessage());
  35. }
  36. public function testGetLastMessage2()
  37. {
  38. $client = new Elastica_Client(array('log' => true));
  39. $log = new Elastica_Log($client);
  40. // Set log path temp path as otherwise test fails with output
  41. $errorLog = ini_get('error_log');
  42. ini_set('error_log', sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'php.log');
  43. $message = 'hello world';
  44. $log->log($message);
  45. ini_set('error_log', $errorLog);
  46. $this->assertEquals($message, $log->getLastMessage());
  47. }
  48. }