1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Bouncer package. |
5
|
|
|
* |
6
|
|
|
* (c) François Hodierne <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Bouncer; |
13
|
|
|
|
14
|
|
|
class LoggerTest extends \PHPUnit_Framework_TestCase |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
public function getRequest() |
18
|
|
|
{ |
19
|
|
|
$ip = '92.78.176.182'; |
20
|
|
|
$ua = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36'; |
21
|
|
|
|
22
|
|
|
$server = array(); |
23
|
|
|
$server['REMOTE_ADDR'] = $ip; |
24
|
|
|
$server['HTTP_USER_AGENT'] = $ua; |
25
|
|
|
$server['HTTP_HOST'] = 'bouncer.h6e.net'; |
26
|
|
|
$server['REQUEST_URI'] = '/test'; |
27
|
|
|
$server['SERVER_PROTOCOL'] = 'HTTP/1.1'; |
28
|
|
|
$server['HTTP_ACCEPT'] = 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'; |
29
|
|
|
$server['HTTP_ACCEPT_LANGUAGE'] = 'en-US,en;q=0.8'; |
30
|
|
|
$server['HTTP_ACCEPT_ENCODING'] = 'gzip, deflate, sdch'; |
31
|
|
|
|
32
|
|
|
$request = new \Bouncer\Request; |
33
|
|
|
$request->initialize(array(), array(), array(), array(), array(), $server); |
34
|
|
|
|
35
|
|
|
return $request; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function getBouncer($request) |
39
|
|
|
{ |
40
|
|
|
$bouncer = new Bouncer(array( |
41
|
|
|
'request' => $request, |
42
|
|
|
'profile' => new \Bouncer\Profile\TestProfile, |
43
|
|
|
)); |
44
|
|
|
|
45
|
|
|
return $bouncer; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testLogNoLogger() |
49
|
|
|
{ |
50
|
|
|
$request = $this->getRequest(); |
51
|
|
|
|
52
|
|
|
$bouncer = $this->getBouncer($request); |
53
|
|
|
|
54
|
|
|
$bouncer->log(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testLogErrorLogger() |
58
|
|
|
{ |
59
|
|
|
$request = $this->getRequest(); |
60
|
|
|
|
61
|
|
|
$bouncer = $this->getBouncer($request); |
62
|
|
|
$logger = new \Bouncer\Logger\ErrorLogger(); |
63
|
|
|
$bouncer->setOptions(array('logger' => $logger)); |
64
|
|
|
|
65
|
|
|
$bouncer->log(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
} |
69
|
|
|
|