PageRenderTime 24ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/test/lib/Elastica/LogTest.php

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