ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
PSR3Test.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Sabre\DAV;
4 
6 
7  function testIsLoggerAware() {
8 
9  $server = new Server();
10  $this->assertInstanceOf(
11  'Psr\Log\LoggerAwareInterface',
12  $server
13  );
14 
15  }
16 
18 
19  $server = new Server();
20  $this->assertInstanceOf(
21  'Psr\Log\NullLogger',
22  $server->getLogger()
23  );
24 
25  }
26 
27  function testSetLogger() {
28 
29  $server = new Server();
30  $logger = new MockLogger();
31 
32  $server->setLogger($logger);
33 
34  $this->assertEquals(
35  $logger,
36  $server->getLogger()
37  );
38 
39  }
40 
45  function testLogException() {
46 
47  $server = new Server();
48  $logger = new MockLogger();
49 
50  $server->setLogger($logger);
51 
52  // Creating a fake environment to execute http requests in.
53  $request = new \Sabre\HTTP\Request(
54  'GET',
55  '/not-found',
56  []
57  );
58  $response = new \Sabre\HTTP\Response();
59 
60  $server->httpRequest = $request;
61  $server->httpResponse = $response;
62  $server->sapi = new \Sabre\HTTP\SapiMock();
63 
64  // Executing the request.
65  $server->exec();
66 
67  // The request should have triggered a 404 status.
68  $this->assertEquals(404, $response->getStatus());
69 
70  // We should also see this in the PSR-3 log.
71  $this->assertEquals(1, count($logger->logs));
72 
73  $logItem = $logger->logs[0];
74 
75  $this->assertEquals(
76  \Psr\Log\LogLevel::INFO,
77  $logItem[0]
78  );
79 
80  $this->assertInstanceOf(
81  'Exception',
82  $logItem[2]['exception']
83  );
84 
85  }
86 
87 }
foreach($paths as $path) $request
Definition: asyncclient.php:32
$server
Definition: sabredav.php:48
Main DAV server class.
Definition: Server.php:23
testLogException()
Start the server, trigger an exception and see if the logger captured it.
Definition: PSR3Test.php:45
$response
The MockLogger is a simple PSR-3 implementation that we can use to test whether things get logged cor...
Definition: MockLogger.php:15
testGetNullLoggerByDefault()
Definition: PSR3Test.php:17