1 | <?php |
||||
2 | |||||
3 | /** |
||||
4 | * Copyright © 2016-present Spryker Systems GmbH. All rights reserved. |
||||
5 | * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. |
||||
6 | */ |
||||
7 | |||||
8 | namespace SprykerTest\Shared\Application\Log\Processor; |
||||
9 | |||||
10 | use Codeception\Test\Unit; |
||||
11 | use Generated\Shared\Transfer\UserTransfer; |
||||
12 | use Spryker\Shared\Application\Log\Processor\RequestProcessor; |
||||
13 | use Spryker\Shared\Log\Sanitizer\Sanitizer; |
||||
14 | use Symfony\Component\HttpFoundation\Request; |
||||
15 | use Symfony\Component\HttpFoundation\Session\Session; |
||||
16 | use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; |
||||
17 | |||||
18 | /** |
||||
19 | * Auto-generated group annotations |
||||
20 | * |
||||
21 | * @group SprykerTest |
||||
22 | * @group Shared |
||||
23 | * @group Application |
||||
24 | * @group Log |
||||
25 | * @group Processor |
||||
26 | * @group RequestProcessorTest |
||||
27 | * Add your own group annotations below this line |
||||
28 | */ |
||||
29 | class RequestProcessorTest extends Unit |
||||
30 | { |
||||
31 | /** |
||||
32 | * @return void |
||||
33 | */ |
||||
34 | public function testInvokeShouldAddRequestInformationToRecordsExtra(): void |
||||
35 | { |
||||
36 | $sanitizer = new Sanitizer([], '***'); |
||||
37 | $processor = new RequestProcessor($sanitizer); |
||||
0 ignored issues
–
show
Deprecated Code
introduced
by
Loading history...
|
|||||
38 | $record = [RequestProcessor::RECORD_EXTRA => [], RequestProcessor::RECORD_CONTEXT => []]; |
||||
39 | $result = $processor($record); |
||||
40 | |||||
41 | $this->assertArrayHasKey(RequestProcessor::EXTRA, $result[RequestProcessor::RECORD_EXTRA]); |
||||
42 | } |
||||
43 | |||||
44 | /** |
||||
45 | * @return void |
||||
46 | */ |
||||
47 | public function testWhenRequestInContextSessionIdShouldBeAdded(): void |
||||
48 | { |
||||
49 | $sanitizer = new Sanitizer([], '***'); |
||||
50 | $processor = new RequestProcessor($sanitizer); |
||||
0 ignored issues
–
show
The class
Spryker\Shared\Applicati...cessor\RequestProcessor has been deprecated: Use `RequestProcessorPlugin`s from Log module instead.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
51 | $record = [ |
||||
52 | RequestProcessor::RECORD_EXTRA => [], |
||||
53 | RequestProcessor::RECORD_CONTEXT => [ |
||||
54 | RequestProcessor::CONTEXT_KEY => $this->getRequestMockWithSession(), |
||||
55 | ], |
||||
56 | ]; |
||||
57 | $result = $processor($record); |
||||
58 | |||||
59 | $this->assertArrayHasKey(RequestProcessor::SESSION_ID, $result[RequestProcessor::RECORD_EXTRA][RequestProcessor::EXTRA]); |
||||
60 | } |
||||
61 | |||||
62 | /** |
||||
63 | * @return void |
||||
64 | */ |
||||
65 | public function testWhenRequestInContextAndUserInSessionUsernameShouldBeAdded(): void |
||||
66 | { |
||||
67 | $sanitizer = new Sanitizer([], '***'); |
||||
68 | $processor = new RequestProcessor($sanitizer); |
||||
0 ignored issues
–
show
The class
Spryker\Shared\Applicati...cessor\RequestProcessor has been deprecated: Use `RequestProcessorPlugin`s from Log module instead.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
69 | $record = [ |
||||
70 | RequestProcessor::RECORD_EXTRA => [], |
||||
71 | RequestProcessor::RECORD_CONTEXT => [ |
||||
72 | RequestProcessor::CONTEXT_KEY => $this->getRequestMockWithUser(), |
||||
73 | ], |
||||
74 | ]; |
||||
75 | $result = $processor($record); |
||||
76 | |||||
77 | $this->assertArrayHasKey(RequestProcessor::USERNAME, $result[RequestProcessor::RECORD_EXTRA][RequestProcessor::EXTRA]); |
||||
78 | } |
||||
79 | |||||
80 | /** |
||||
81 | * @return void |
||||
82 | */ |
||||
83 | public function testWhenRequestInContextItMustBeRemovedAfterProcessing(): void |
||||
84 | { |
||||
85 | $sanitizer = new Sanitizer([], '***'); |
||||
86 | $processor = new RequestProcessor($sanitizer); |
||||
0 ignored issues
–
show
The class
Spryker\Shared\Applicati...cessor\RequestProcessor has been deprecated: Use `RequestProcessorPlugin`s from Log module instead.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
87 | $record = [ |
||||
88 | RequestProcessor::RECORD_EXTRA => [], |
||||
89 | RequestProcessor::RECORD_CONTEXT => [ |
||||
90 | RequestProcessor::CONTEXT_KEY => $this->getRequestMockWithSession(), |
||||
91 | ], |
||||
92 | ]; |
||||
93 | $result = $processor($record); |
||||
94 | |||||
95 | $this->assertArrayNotHasKey(RequestProcessor::CONTEXT_KEY, $result[RequestProcessor::RECORD_CONTEXT]); |
||||
96 | } |
||||
97 | |||||
98 | /** |
||||
99 | * @return \Symfony\Component\HttpFoundation\Request |
||||
100 | */ |
||||
101 | protected function getRequestMockWithSession(): Request |
||||
102 | { |
||||
103 | $request = Request::createFromGlobals(); |
||||
104 | $session = new Session(new MockArraySessionStorage()); |
||||
105 | $request->setSession($session); |
||||
106 | |||||
107 | return $request; |
||||
108 | } |
||||
109 | |||||
110 | /** |
||||
111 | * @return \Symfony\Component\HttpFoundation\Request |
||||
112 | */ |
||||
113 | protected function getRequestMockWithUser(): Request |
||||
114 | { |
||||
115 | $request = Request::createFromGlobals(); |
||||
116 | $session = new Session(new MockArraySessionStorage()); |
||||
117 | $userTransfer = new UserTransfer(); |
||||
118 | $userTransfer->setUsername('username'); |
||||
119 | $session->set(RequestProcessor::SESSION_KEY_USER, $userTransfer); |
||||
120 | $request->setSession($session); |
||||
121 | |||||
122 | return $request; |
||||
123 | } |
||||
124 | } |
||||
125 |