8000 Use static methods inside data providers · symfony/symfony@90c8f73 · GitHub
[go: up one dir, main page]

Skip to content

Commit 90c8f73

Browse files
committed
Use static methods inside data providers
Extracted from closed PR #48283 This is work, which needs to be done manually anyway.
1 parent 5a68b8c commit 90c8f73

File tree

5 files changed

+67
-67
lines changed

5 files changed

+67
-67
lines changed

src/Symfony/Bridge/Monolog/Tests/Handler/FingersCrossed/HttpCodeActivationStrategyTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,19 @@ public function isActivatedProvider(): array
101101
{
102102
return [
103103
['/test', ['level' => Logger::ERROR], true],
104-
['/400', ['level' => Logger::ERROR, 'context' => $this->getContextException(400)], true],
105-
['/400/a', ['level' => Logger::ERROR, 'context' => $this->getContextException(400)], false],
106-
['/400/b', ['level' => Logger::ERROR, 'context' => $this->getContextException(400)], false],
107-
['/400/c', ['level' => Logger::ERROR, 'context' => $this->getContextException(400)], true],
108-
['/401', ['level' => Logger::ERROR, 'context' => $this->getContextException(401)], true],
109-
['/403', ['level' => Logger::ERROR, 'context' => $this->getContextException(403)], false],
110-
['/404', ['level' => Logger::ERROR, 'context' => $this->getContextException(404)], false],
111-
['/405', ['level' => Logger::ERROR, 'context' => $this->getContextException(405)], false],
112-
['/500', ['level' => Logger::ERROR, 'context' => $this->getContextException(500)], true],
104+
['/400', ['level' => Logger::ERROR, 'context' => self::getContextException(400)], true],
105+
['/400/a', ['level' => Logger::ERROR, 'context' => self::getContextException(400)], false],
106+
['/400/b', ['level' => Logger::ERROR, 'context' => self::getContextException(400)], false],
107+
['/400/c', ['level' => Logger::ERROR, 'context' => self::getContextException(400)], true],
108+
['/401', ['level' => Logger::ERROR, 'context' => self::getContextException(401)], true],
109+
['/403', ['level' => Logger::ERROR, 'context' => self::getContextException(403)], false],
110+
['/404', ['level' => Logger::ERROR, 'context' => self::getContextException(404)], false],
111+
['/405', ['level' => Logger::ERROR, 'context' => self::getContextException(405)], false],
112+
['/500', ['level' => Logger::ERROR, 'context' => self::getContextException(500)], true],
113113
];
114114
}
115115
116-
private function getContextException(int $code): array
116+
private static function getContextException(int $code): array
117117
{
118118
return ['exception' => new HttpException($code)];
119119
}

src/Symfony/Bridge/Monolog/Tests/Handler/FingersCrossed/NotFoundActivationStrategyTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,18 @@ public function isActivatedProvider(): array
5353
{
5454
return [
5555
['/test', ['level' => Logger::DEBUG], false],
56-
['/foo', ['level' => Logger::DEBUG, 'context' => $this->getContextException(404)], false],
57-
['/baz/bar', ['level' => Logger::ERROR, 'context' => $this->getContextException(404)], false],
58-
['/foo', ['level' => Logger::ERROR, 'context' => $this->getContextException(404)], false],
59-
['/foo', ['level' => Logger::ERROR, 'context' => $this->getContextException(500)], true],
56+
['/foo', ['level' => Logger::DEBUG, 'context' => self::getContextException(404)], false],
57+
['/baz/bar', ['level' => Logger::ERROR, 'context' => self::getContextException(404)], false],
58+
['/foo', ['level' => Logger::ERROR, 'context' => self::getContextException(404)], false],
59+
['/foo', ['level' => Logger::ERROR, 'context' => self::getContextException(500)], true],
6060

6161
['/test', ['level' => Logger::ERROR], true],
62-
['/baz', ['level' => Logger::ERROR, 'context' => $this->getContextException(404)], true],
63-
['/baz', ['level' => Logger::ERROR, 'context' => $this->getContextException(500)], true],
62+
['/baz', ['level' => Logger::ERROR, 'context' => self::getContextException(404)], true],
63+
['/baz', ['level' => Logger::ERROR, 'context' => self::getContextException(500)], true],
6464
];
6565
}
6666

67-
protected function getContextException(int $code): array
67+
protected static function getContextException(int $code): array
6868
{
6969
return ['exception' => new HttpException($code)];
7070
}

src/Symfony/Bridge/Monolog/Tests/Processor/DebugProcessorTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function testDatetimeFormat(array $record, $expectedTimestamp)
3434

3535
public function providerDatetimeFormatTests(): array
3636
{
37-
$record = $this->getRecord();
37+
$record = self::getRecord();
3838

3939
return [
4040
[array_merge($record, ['datetime' => new \DateTime('2019-01-01T00:01:00+00:00')]), 1546300860],
@@ -58,7 +58,7 @@ public function testDatetimeRfc3339Format(array $record, $expectedTimestamp)
5858

5959
public function providerDatetimeRfc3339FormatTests(): array
6060
{
61-
$record = $this->getRecord();
61+
$record = self::getRecord();
6262

6363
return [
6464
[array_merge($record, ['datetime' => new \DateTime('2019-01-01T00:01:00+00:00')]), '2019-01-01T00:01:00.000+00:00'],
@@ -70,8 +70,8 @@ public function providerDatetimeRfc3339FormatTests(): array
7070
public function testDebugProcessor()
7171
{
7272
$processor = new DebugProcessor();
73-
$processor($this->getRecord());
74-
$processor($this->getRecord(Logger::ERROR));
73+
$processor(self::getRecord());
74+
$processor(self::getRecord(Logger::ERROR));
7575

7676
$this->assertCount(2, $processor->getLogs());
7777
$this->assertSame(1, $processor->countErrors());
@@ -89,17 +89,17 @@ public function testWithRequestStack()
8989
{
9090
$stack = new RequestStack();
9191
$processor = new DebugProcessor($stack);
92-
$processor($this->getRecord());
93-
$processor($this->getRecord(Logger::ERROR));
92+
$processor(self::getRecord());
93+
$processor(self::getRecord(Logger::ERROR));
9494

9595
$this->assertCount(2, $processor->getLogs());
9696
$this->assertSame(1, $processor->countErrors());
9797

9898
$request = new Request();
9999
$stack->push($request);
100100

101-
$processor($this->getRecord());
102-
$processor($this->getRecord(Logger::ERROR));
101+
$processor(self::getRecord());
102+
$processor(self::getRecord(Logger::ERROR));
103103

104104
$this->assertCount(4, $processor->getLogs());
105105
$this->assertSame(2, $processor->countErrors());
@@ -123,7 +123,7 @@ public function testInheritedClassCallCountErrorsWithoutArgument()
123123
$this->assertEquals(0, $debugProcessorChild->countErrors());
124124
}
125125

126-
private function getRecord($level = Logger::WARNING, $message = 'test'): array
126+
private static function getRecord($level = Logger::WARNING, $message = 'test'): array
127127
{
128128
return [
129129
'message' => $message,

src/Symfony/Bundle/WebProfilerBundle/Tests/Csp/ContentSecurityPolicyHandlerTest.php

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ public function provideRequestAndResponses()
6666
];
6767

6868
return [
69-
[$nonce, ['csp_script_nonce' => $nonce, 'csp_style_nonce' => $nonce], $this->createRequest(), $this->createResponse()],
70-
[$nonce, ['csp_script_nonce' => $requestScriptNonce, 'csp_style_nonce' => $requestStyleNonce], $this->createRequest($requestNonceHeaders), $this->createResponse($responseNonceHeaders)],
71-
[$nonce, ['csp_script_nonce' => $requestScriptNonce, 'csp_style_nonce' => $requestStyleNonce], $this->createRequest($requestNonceHeaders), $this->createResponse()],
72-
[$nonce, ['csp_script_nonce' => $responseScriptNonce, 'csp_style_nonce' => $responseStyleNonce], $this->createRequest(), $this->createResponse($responseNonceHeaders)],
69+
[$nonce, ['csp_script_nonce' => $nonce, 'csp_style_nonce' => $nonce], self::createRequest(), self::createResponse()],
70+
[$nonce, ['csp_script_nonce' => $requestScriptNonce, 'csp_style_nonce' => $requestStyleNonce], self::createRequest($requestNonceHeaders), self::createResponse($responseNonceHeaders)],
71+
[$nonce, ['csp_script_nonce' => $requestScriptNonce, 'csp_style_nonce' => $requestStyleNonce], self::createRequest($requestNonceHeaders), self::createResponse()],
72+
[$nonce, ['csp_script_nonce' => $responseScriptNonce, 'csp_style_nonce' => $responseStyleNonce], self::createRequest(), self::createResponse($responseNonceHeaders)],
7373
];
7474
}
7575

@@ -96,112 +96,112 @@ public function provideRequestAndResponsesForOnKernelResponse()
9696
[
9797
$nonce,
9898
['csp_script_nonce' => $nonce, 'csp_style_nonce' => $nonce],
99-
$this->createRequest(),
100-
$this->createResponse(),
99+
self::createRequest(),
100+
self::createResponse(),
101101
['Content-Security-Policy' => null, 'Content-Security-Policy-Report-Only' => null, 'X-Content-Security-Policy' => null],
102102
],
103103
[
104104
$nonce, ['csp_script_nonce' => $requestScriptNonce, 'csp_style_nonce' => $requestStyleNonce],
105-
$this->createRequest($requestNonceHeaders),
106-
$this->createResponse($responseNonceHeaders),
105+
self::createRequest($requestNonceHeaders),
106+
self::createResponse($responseNonceHeaders),
107107
['Content-Security-Policy' => null, 'Content-Security-Policy-Report-Only' => null, 'X-Content-Security-Policy' => null],
108108
],
109109
[
110110
$nonce,
111111
['csp_script_nonce' => $requestScriptNonce, 'csp_style_nonce' => $requestStyleNonce],
112-
$this->createRequest($requestNonceHeaders),
113-
$this->createResponse(),
112+
self::createRequest($requestNonceHeaders),
113+
self::createResponse(),
114114
['Content-Security-Policy' => null, 'Content-Security-Policy-Report-Only' => null, 'X-Content-Security-Policy' => null],
115115
],
116116
[
117117
$nonce,
118118
['csp_script_nonce' => $responseScriptNonce, 'csp_style_nonce' => $responseStyleNonce],
119-
$this->createRequest(),
120-
$this->createResponse($responseNonceHeaders),
119+
self::createRequest(),
120+
self::createResponse($responseNonceHeaders),
121121
['Content-Security-Policy' => null, 'Content-Security-Policy-Report-Only' => null, 'X-Content-Security-Policy' => null],
122122
],
123123
[
124124
$nonce,
125125
['csp_script_nonce' => $nonce, 'csp_style_nonce' => $nonce],
126-
$this->createRequest(),
127-
$this->createResponse(['Content-Security-Policy' => 'frame-ancestors https: ; form-action: https:', 'Content-Security-Policy-Report-Only' => 'frame-ancestors http: ; form-action: http:']),
126+
self::createRequest(),
127+
self::createResponse(['Content-Security-Policy' => 'frame-ancestors https: ; form-action: https:', 'Content-Security-Policy-Report-Only' => 'frame-ancestors http: ; form-action: http:']),
128128
['Content-Security-Policy' => 'frame-ancestors https: ; form-action: https:', 'Content-Security-Policy-Report-Only' => 'frame-ancestors http: ; form-action: http:', 'X-Content-Security-Policy' => null],
129129
],
130130
[
131131
$nonce,
132132
['csp_script_nonce' => $nonce, 'csp_style_nonce' => $nonce],
133-
$this->createRequest(),
134-
$this->createResponse(['Content-Security-Policy' => 'default-src \'self\' domain.com; script-src \'self\' \'unsafe-inline\'', 'Content-Security-Policy-Report-Only' => 'default-src \'self\' domain-report-only.com; script-src \'self\' \'unsafe-inline\'']),
133+
self::createRequest(),
134+
self::createResponse(['Content-Security-Policy' => 'default-src \'self\' domain.com; script-src \'self\' \'unsafe-inline\'', 'Content-Security-Policy-Report-Only' => 'default-src \'self\' domain-report-only.com; script-src \'self\' \'unsafe-inline\'']),
135135
['Content-Security-Policy' => 'default-src \'self\' domain.com; script-src \'self\' \'unsafe-inline\'; style-src \'self\' domain.com \'unsafe-inline\' \'nonce-'.$nonce.'\'', 'Content-Security-Policy-Report-Only' => 'default-src \'self\' domain-report-only.com; script-src \'self\' \'unsafe-inline\'; style-src \'self\' domain-report-only.com \'unsafe-inline\' \'nonce-'.$nonce.'\'', 'X-Content-Security-Policy' => null],
136136
],
137137
[
138138
$nonce,
139139
['csp_script_nonce' => $nonce, 'csp_style_nonce' => $nonce],
140-
$this->createRequest(),
141-
$this->createResponse(['Content-Security-Policy' => 'default-src \'self\' domain.com; script-src \'self\' \'unsafe-inline\'; script-src-elem \'self\'; style-src \'self\' \'unsafe-inline\'; style-src-elem \'self\'', 'Content-Security-Policy-Report-Only' => 'default-src \'self\' domain-report-only.com; script-src \'self\' \'unsafe-inline\'; script-src-elem \'self\'; style-src \'self\' \'unsafe-inline\'; style-src-elem \'self\'']),
140+
self::createRequest(),
141+
self::createResponse(['Content-Security-Policy' => 'default-src \'self\' domain.com; script-src \'self\' \'unsafe-inline\'; script-src-elem \'self\'; style-src \'self\' \'unsafe-inline\'; style-src-elem \'self\'', 'Content-Security-Policy-Report-Only' => 'default-src \'self\' domain-report-only.com; script-src \'self\' \'unsafe-inline\'; script-src-elem \'self\'; style-src \'self\' \'unsafe-inline\'; style-src-elem \'self\'']),
142142
['Content-Security-Policy' => 'default-src \'self\' domain.com; script-src \'self\' \'unsafe-inline\'; script-src-elem \'self\' \'unsafe-inline\' \'nonce-'.$nonce.'\'; style-src \'self\' \'unsafe-inline\'; style-src-elem \'self\' \'unsafe-inline\' \'nonce-'.$nonce.'\'', 'Content-Security-Policy-Report-Only' => 'default-src \'self\' domain-report-only.com; script-src \'self\' \'unsafe-inline\'; script-src-elem \'self\' \'unsafe-inline\' \'nonce-'.$nonce.'\'; style-src \'self\' \'unsafe-inline\'; style-src-elem \'self\' \'unsafe-inline\' \'nonce-'.$nonce.'\'', 'X-Content-Security-Policy' => null],
143143
],
144144
[
145145
$nonce,
146146
['csp_script_nonce' => $nonce, 'csp_style_nonce' => $nonce],
147-
$this->createRequest(),
148-
$this->createResponse(['Content-Security-Policy' => 'default-src \'none\'', 'Content-Security-Policy-Report-Only' => 'default-src \'none\'']),
147+
self::createRequest(),
148+
self::createResponse(['Content-Security-Policy' => 'default-src \'none\'', 'Content-Security-Policy-Report-Only' => 'default-src \'none\'']),
149149
['Content-Security-Policy' => 'default-src \'none\'; script-src \'unsafe-inline\' \'nonce-'.$nonce.'\'; style-src \'unsafe-inline\' \'nonce-'.$nonce.'\'', 'Content-Security-Policy-Report-Only' => 'default-src \'none\'; script-src \'unsafe-inline\' \'nonce-'.$nonce.'\'; style-src \'unsafe-inline\' \'nonce-'.$nonce.'\'', 'X-Content-Security-Policy' => null],
150150
],
151151
[
152152
$nonce,
153153
['csp_script_nonce' => $nonce, 'csp_style_nonce' => $nonce],
154-
$this->createRequest(),
155-
$this->createResponse(['Content-Security-Policy' => 'script-src \'self\' \'unsafe-inline\'']),
154+
self::createRequest(),
155+
self::createResponse(['Content-Security-Policy' => 'script-src \'self\' \'unsafe-inline\'']),
156156
['Content-Security-Policy' => 'script-src \'self\' \'unsafe-inline\'', 'X-Content-Security-Policy' => null],
157157
],
158158
[
159159
$nonce,
160160
['csp_script_nonce' => $nonce, 'csp_style_nonce' => $nonce],
161-
$this->createRequest(),
162-
$this->createResponse(['Content-Security-Policy' => 'script-src \'self\'; style-src \'self\'']),
161+
self::createRequest(),
162+
self::createResponse(['Content-Security-Policy' => 'script-src \'self\'; style-src \'self\'']),
163163
['Content-Security-Policy' => 'script-src \'self\' \'unsafe-inline\' \'nonce-'.$nonce.'\'; style-src \'self\' \'unsafe-inline\' \'nonce-'.$nonce.'\'', 'X-Content-Security-Policy' => null],
164164
],
165165
[
166166
$nonce,
167167
['csp_script_nonce' => $nonce, 'csp_style_nonce' => $nonce],
168-
$this->createRequest(),
169-
$this->createResponse(['X-Content-Security-Policy' => 'script-src \'self\' \'unsafe-inline\'']),
168+
self::createRequest(),
169+
self::createResponse(['X-Content-Security-Policy' => 'script-src \'self\' \'unsafe-inline\'']),
170170
['X-Content-Security-Policy' => 'script-src \'self\' \'unsafe-inline\'', 'Content-Security-Policy' => null],
171171
],
172172
[
173173
$nonce,
174174
['csp_script_nonce' => $nonce, 'csp_style_nonce' => $nonce],
175-
$this->createRequest(),
176-
$this->createResponse(['X-Content-Security-Policy' => 'script-src \'self\'']),
175+
self::createRequest(),
176+
self::createResponse(['X-Content-Security-Policy' => 'script-src \'self\'']),
177177
['X-Content-Security-Policy' => 'script-src \'self\' \'unsafe-inline\' \'nonce-'.$nonce.'\'', 'Content-Security-Policy' => null],
178178
],
179179
[
180180
$nonce,
181181
['csp_script_nonce' => $nonce, 'csp_style_nonce' => $nonce],
182-
$this->createRequest(),
183-
$this->createResponse(['X-Content-Security-Policy' => 'script-src \'self\' \'unsafe-inline\' \'sha384-LALALALALAAL\'']),
182+
self::createRequest(),
183+
self::createResponse(['X-Content-Security-Policy' => 'script-src \'self\' \'unsafe-inline\' \'sha384-LALALALALAAL\'']),
184184
['X-Content-Security-Policy' => 'script-src \'self\' \'unsafe-inline\' \'sha384-LALALALALAAL\' \'nonce-'.$nonce.'\'', 'Content-Security-Policy' => null],
185185
],
186186
[
187187
$nonce,
188188
['csp_script_nonce' => $nonce, 'csp_style_nonce' => $nonce],
189-
$this->createRequest(),
190-
$this->createResponse(['Content-Security-Policy' => 'script-src \'self\'; style-src \'self\'', 'X-Content-Security-Policy' => 'script-src \'self\' \'unsafe-inline\'; style-src \'self\'']),
189+
self::createRequest(),
190+
self::createResponse(['Content-Security-Policy' => 'script-src \'self\'; style-src \'self\'', 'X-Content-Security-Policy' => 'script-src \'self\' \'unsafe-inline\'; style-src \'self\'']),
191191
['Content-Security-Policy' => 'script-src \'self\' \'unsafe-inline\' \'nonce-'.$nonce.'\'; style-src \'self\' \'unsafe-inline\' \'nonce-'.$nonce.'\'', 'X-Content-Security-Policy' => 'script-src \'self\' \'unsafe-inline\'; style-src \'self\' \'unsafe-inline\' \'nonce-'.$nonce.'\''],
192192
],
193193
];
194194
}
195195

196-
private function createRequest(array $headers = [])
196+
private static function createRequest(array $headers = [])
197197
{
198198
$request = new Request();
199199
$request->headers->add($headers);
200200

201201
return $request;
202202
}
203203

204-
private function createResponse(array $headers = [])
204+
private static function createResponse(array $headers = [])
205205
{
206206
$response = new Response();
207207
$response->headers->add($headers);

0 commit comments

Comments
 (0)
0