-
-
Notifications
You must be signed in to change notification settings - Fork 452
Expand file tree
/
Copy pathHttpLoggingTest.php
More file actions
93 lines (73 loc) · 2.62 KB
/
Copy pathHttpLoggingTest.php
File metadata and controls
93 lines (73 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
declare(strict_types=1);
namespace Kreait\Firebase\Tests\Integration;
use GuzzleHttp\MessageFormatter;
use GuzzleHttp\Middleware;
use Kreait\Firebase\Contract\Auth;
use Kreait\Firebase\Exception\Auth\UserNotFound;
use Kreait\Firebase\Http\HttpClientOptions;
use Kreait\Firebase\Tests\IntegrationTestCase;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
use Throwable;
/**
* @internal
*/
final class HttpLoggingTest extends IntegrationTestCase
{
private LoggerInterface&MockObject $logger;
private LoggerInterface&MockObject $debugLogger;
private Auth $auth;
private Auth $authWithLogger;
private Auth $authWithDebugLogger;
protected function setUp(): void
{
parent::setUp();
$this->logger = $this->createMock(LoggerInterface::class);
$this->debugLogger = $this->createMock(LoggerInterface::class);
$logMiddleware = Middleware::log($this->logger, new MessageFormatter(), LogLevel::INFO);
$debugLogMiddleware = Middleware::log($this->debugLogger, new MessageFormatter(MessageFormatter::DEBUG), LogLevel::DEBUG);
$clientOptions = HttpClientOptions::default();
$this->auth = self::$factory->createAuth();
$this->authWithLogger = self::$factory
->withHttpClientOptions($clientOptions->withGuzzleMiddleware($logMiddleware))
->createAuth();
$this->authWithDebugLogger = self::$factory
->withHttpClientOptions($clientOptions->withGuzzleMiddleware($debugLogMiddleware))
->createAuth();
}
#[Test]
public function itLogsSuccesses(): void
{
$user = $this->auth->createAnonymousUser();
try {
$this->logger->expects($this->atLeastOnce())->method('log');
$this->authWithLogger->getUser($user->uid);
} finally {
$this->auth->deleteUser($user->uid);
}
}
#[Test]
public function itLogsFailures(): void
{
$this->debugLogger->expects($this->atLeastOnce())->method('log');
try {
$this->authWithDebugLogger->updateUser('does-not-exist', []);
} catch (Throwable $e) {
$this->assertInstanceOf(UserNotFound::class, $e);
}
}
#[Test]
public function itUsesAHttpDebugLogger(): void
{
$user = $this->auth->createAnonymousUser();
try {
$this->debugLogger->expects($this->atLeastOnce())->method('log');
$this->authWithDebugLogger->getUser($user->uid);
} finally {
$this->auth->deleteUser($user->uid);
}
}
}