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