PageRenderTime 35ms CodeModel.GetById 15ms app.highlight 12ms RepoModel.GetById 2ms 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
 3require_once dirname(__FILE__) . '/../../bootstrap.php';
 4
 5
 6class Elastica_LogTest extends Elastica_Test
 7{
 8	public function setUp() {
 9
10	}
11
12	public function tearDown() {
13	}
14
15	public function testSetLogConfigPath() {
16		$logPath = '/tmp/php.log';
17		$client = new Elastica_Client(array('log' => $logPath));
18		$this->assertEquals($logPath, $client->getConfig('log'));
19	}
20	
21	public function testSetLogConfigEnable() {
22		$client = new Elastica_Client(array('log' => true));
23		$this->assertTrue($client->getConfig('log'));
24	}
25	
26	public function testEmptyLogConfig() {
27		$client = new Elastica_Client();
28		$this->assertEmpty($client->getConfig('log'));
29	}
30	
31	public function testDisabledLog() {
32		$client = new Elastica_Client();
33		$log = new Elastica_Log($client);
34		
35		$log->log('hello world');
36		
37		$this->assertEmpty($log->getLastMessage());
38	}
39	
40	public function testGetLastMessage() {
41		$client = new Elastica_Client(array('log' => '/tmp/php.log'));
42		$log = new Elastica_Log($client);
43		$message = 'hello world';
44		
45		$log->log($message);
46	
47		$this->assertEquals($message, $log->getLastMessage());
48	}
49	
50	public function testGetLastMessage2() {
51		$client = new Elastica_Client(array('log' => true));
52		$log = new Elastica_Log($client);
53		
54		// Set log path temp path as otherwise test fails with output
55		$errorLog = ini_get('error_log');
56		ini_set('error_log', sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'php.log');
57		
58		$message = 'hello world';
59	
60		$log->log($message);
61		
62		ini_set('error_log', $errorLog);
63	
64		$this->assertEquals($message, $log->getLastMessage());
65	}
66}