Skip to content

Commit b19e1be

Browse files
kevinjhappynicolas-grekas
authored andcommitted
Trigger deprecation notices when inherited class calls parent method but misses adding new arguments
1 parent 1a46605 commit b19e1be

File tree

19 files changed

+298
-21
lines changed

19 files changed

+298
-21
lines changed

UPGRADE-4.2.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
UPGRADE FROM 4.1 to 4.2
22
=======================
33

4+
BrowserKit
5+
----------
6+
7+
* The `Client::submit()` method will have a new `$serverParameters` argument in version 5.0, not defining it is deprecated.
8+
49
Cache
510
-----
611

@@ -37,6 +42,16 @@ DoctrineBridge
3742
* The `lazy` attribute on `doctrine.event_listener` tags was removed.
3843
Listeners are now lazy by default. So any `lazy` attributes can safely be removed from those tags.
3944

45+
DomCrawler
46+
----------
47+
48+
* The `Crawler::children()` method will have a new `$selector` argument in version 5.0, not defining it is deprecated.
49+
50+
Finder
51+
------
52+
53+
* The `Finder::sortByName()` method will have a new `$useNaturalSort` argument in version 5.0, not defining it is deprecated.
54+
4055
Form
4156
----
4257

@@ -123,6 +138,11 @@ Messenger
123138
];
124139
```
125140

141+
Monolog
142+
-------
143+
144+
* The methods `DebugProcessor::getLogs()`, `DebugProcessor::countErrors()`, `Logger::getLogs()` and `Logger::countErrors()` will have a new `$request` argument in version 5.0, not defining it is deprecated.
145+
126146
Security
127147
--------
128148

@@ -149,8 +169,9 @@ SecurityBundle
149169
Serializer
150170
----------
151171

152-
* Relying on the default value (false) of the "as_collection" option is deprecated since 4.2.
172+
* Relying on the default value (false) of the "as_collection" option is deprecated.
153173
You should set it to false explicitly instead as true will be the default value in 5.0.
174+
* The `AbstractNormalizer::handleCircularReference()` method will have two new `$format` and `$context` arguments in version 5.0, not defining them is deprecated.
154175

155176
Translation
156177
-----------

UPGRADE-5.0.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
UPGRADE FROM 4.x to 5.0
22
=======================
33

4+
BrowserKit
5+
----------
6+
7+
* The `Client::submit()` method has a new `$serverParameters` argument.
8+
49
Cache
510
-----
611

@@ -49,11 +54,21 @@ DoctrineBridge
4954
* Deprecated injecting `ClassMetadataFactory` in `DoctrineExtractor`, an instance of `EntityManagerInterface` should be
5055
injected instead
5156

57+
DomCrawler
58+
----------
59+
60+
* The `Crawler::children()` method has a new `$selector` argument.
61+
5262
EventDispatcher
5363
---------------
5464

5565
* The `TraceableEventDispatcherInterface` has been removed.
5666

67+
Finder
68+
------
69+
70+
* The `Finder::sortByName()` method has a new `$useNaturalSort` argument.
71+
5772
FrameworkBundle
5873
---------------
5974

@@ -101,6 +116,11 @@ HttpFoundation
101116
* The `getClientSize()` method of the `UploadedFile` class has been removed.
102117
* The `getSession()` method of the `Request` class throws an exception when session is null.
103118

119+
Monolog
120+
-------
121+
122+
* The methods `DebugProcessor::getLogs()`, `DebugProcessor::countErrors()`, `Logger::getLogs()` and `Logger::countErrors()` have a new `$request` argument.
123+
104124
Process
105125
-------
106126

@@ -142,6 +162,11 @@ SecurityBundle
142162
* The `security.authentication.trust_resolver.anonymous_class` parameter has been removed.
143163
* The `security.authentication.trust_resolver.rememberme_class` parameter has been removed.
144164

165+
Serializer
166+
----------
167+
168+
* The `AbstractNormalizer::handleCircularReference()` method has two new `$format` and `$context` arguments.
169+
145170
Translation
146171
-----------
147172

src/Symfony/Bridge/Monolog/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ CHANGELOG
55
-----
66

77
* added `ProcessorInterface`: an optional interface to allow autoconfiguration of Monolog processors
8+
* The methods `DebugProcessor::getLogs()`, `DebugProcessor::countErrors()`, `Logger::getLogs()`
9+
and `Logger::countErrors()` will have one `$request` argument in version 5.0, not defining
10+
it is deprecated since Symfony 4.2.
811

912
4.1.0
1013
-----

src/Symfony/Bridge/Monolog/Logger.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ class Logger extends BaseLogger implements DebugLoggerInterface, ResetInterface
2828
*/
2929
public function getLogs(/* Request $request = null */)
3030
{
31+
if (\func_num_args() < 1 && __CLASS__ !== \get_class($this) && __CLASS__ !== (new \ReflectionMethod($this, __FUNCTION__))->getDeclaringClass()->getName() && !$this instanceof \PHPUnit\Framework\MockObject\MockObject && !$this instanceof \Prophecy\Prophecy\ProphecySubjectInterface) {
32+
@trigger_error(sprintf('The "%s()" method will have one `Request $request = null` argument in version 5.0 and higher, not defining it is deprecated since Symfony 4.2.', __METHOD__), E_USER_DEPRECATED);
33+
}
34+
3135
if ($logger = $this->getDebugLogger()) {
3236
return \call_user_func_array(array($logger, 'getLogs'), \func_get_args());
3337
}
@@ -40,6 +44,10 @@ public function getLogs(/* Request $request = null */)
4044
*/
4145
public function countErrors(/* Request $request = null */)
4246
{
47+
if (\func_num_args() < 1 && __CLASS__ !== \get_class($this) && __CLASS__ !== (new \ReflectionMethod($this, __FUNCTION__))->getDeclaringClass()->getName() && !$this instanceof \PHPUnit\Framework\MockObject\MockObject && !$this instanceof \Prophecy\Prophecy\ProphecySubjectInterface) {
48+
@trigger_error(sprintf('The "%s()" method will have one `Request $request = null` argument in version 5.0 and higher, not defining it is deprecated since Symfony 4.2.', __METHOD__), E_USER_DEPRECATED);
49+
}
50+
4351
if ($logger = $this->getDebugLogger()) {
4452
return \call_user_func_array(array($logger, 'countErrors'), \func_get_args());
4553
}

src/Symfony/Bridge/Monolog/Processor/DebugProcessor.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ public function __invoke(array $record)
6161
*/
6262
public function getLogs(/* Request $request = null */)
6363
{
64+
if (\func_num_args() < 1 && __CLASS__ !== \get_class($this) && __CLASS__ !== (new \ReflectionMethod($this, __FUNCTION__))->getDeclaringClass()->getName() && !$this instanceof \PHPUnit\Framework\MockObject\MockObject && !$this instanceof \Prophecy\Prophecy\ProphecySubjectInterface) {
65+
@trigger_error(sprintf('The "%s()" method will have one `Request $request = null` argument in version 5.0 and higher, not defining it is deprecated since Symfony 4.2.', __METHOD__), E_USER_DEPRECATED);
66+
}
67+
6468
if (1 <= \func_num_args() && null !== ($request = \func_get_arg(0)) && isset($this->records[$hash = spl_object_hash($request)])) {
6569
return $this->records[$hash];
6670
}
@@ -77,6 +81,10 @@ public function getLogs(/* Request $request = null */)
7781
*/
7882
public function countErrors(/* Request $request = null */)
7983
{
84+
if (\func_num_args() < 1 && __CLASS__ !== \get_class($this) && __CLASS__ !== (new \ReflectionMethod($this, __FUNCTION__))->getDeclaringClass()->getName() && !$this instanceof \PHPUnit\Framework\MockObject\MockObject && !$this instanceof \Prophecy\Prophecy\ProphecySubjectInterface) {
85+
@trigger_error(sprintf('The "%s()" method will have one `Request $request = null` argument in version 5.0 and higher, not defining it is deprecated since Symfony 4.2.', __METHOD__), E_USER_DEPRECATED);
86+
}
87+
8088
if (1 <= \func_num_args() && null !== ($request = \func_get_arg(0)) && isset($this->errorCount[$hash = spl_object_hash($request)])) {
8189
return $this->errorCount[$hash];
8290
}

src/Symfony/Bridge/Monolog/Tests/LoggerTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,37 @@ public function testClear()
107107
$this->assertEmpty($logger->getLogs());
108108
$this->assertSame(0, $logger->countErrors());
109109
}
110+
111+
/**
112+
* @group legacy
113+
* @expectedDeprecation The "Symfony\Bridge\Monolog\Logger::getLogs()" method will have one `Request $request = null` argument in version 5.0 and higher, not defining it is deprecated since Symfony 4.2.
114+
*/
115+
public function testInheritedClassCallGetLogsWithoutArgument()
116+
{
117+
$loggerChild = new ClassThatInheritLogger('test');
118+
$loggerChild->getLogs();
119+
}
120+
121+
/**
122+
* @group legacy
123+
* @expectedDeprecation The "Symfony\Bridge\Monolog\Logger::countErrors()" method will have one `Request $request = null` argument in version 5.0 and higher, not defining it is deprecated since Symfony 4.2.
124+
*/
125+
public function testInheritedClassCallCountErrorsWithoutArgument()
126+
{
127+
$loggerChild = new ClassThatInheritLogger('test');
128+
$loggerChild->countErrors();
129+
}
130+
}
131+
132+
class ClassThatInheritLogger extends Logger
133+
{
134+
public function getLogs()
135+
{
136+
parent::getLogs();
137+
}
138+
139+
public function countErrors()
140+
{
141+
parent::countErrors();
142+
}
110143
}

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,26 @@ public function testWithRequestStack()
6060
$this->assertSame(1, $processor->countErrors($request));
6161
}
6262

63+
/**
64+
* @group legacy
65+
* @expectedDeprecation The "Symfony\Bridge\Monolog\Processor\DebugProcessor::getLogs()" method will have one `Request $request = null` argument in version 5.0 and higher, not defining it is deprecated since Symfony 4.2.
66+
*/
67+
public function testInheritedClassCallGetLogsWithoutArgument()
68+
{
69+
$debugProcessorChild = new ClassThatInheritDebugProcessor();
70+
$debugProcessorChild->getLogs();
71+
}
72+
73+
/**
74+
* @group legacy
75+
* @expectedDeprecation The "Symfony\Bridge\Monolog\Processor\DebugProcessor::countErrors()" method will have one `Request $request = null` argument in version 5.0 and higher, not defining it is deprecated since Symfony 4.2.
76+
*/
77+
public function testInheritedClassCallCountErrorsWithoutArgument()
78+
{
79+
$debugProcessorChild = new ClassThatInheritDebugProcessor();
80+
$debugProcessorChild->countErrors();
81+
}
82+
6383
private function getRecord($level = Logger::WARNING, $message = 'test')
6484
{
6585
return array(
@@ -73,3 +93,16 @@ private function getRecord($level = Logger::WARNING, $message = 'test')
7393
);
7494
}
7595
}
96+
97+
class ClassThatInheritDebugProcessor extends DebugProcessor
98+
{
99+
public function getLogs()
100+
{
101+
parent::getLogs();
102+
}
103+
104+
public function countErrors()
105+
{
106+
parent::countErrors();
107+
}
108+
}

src/Symfony/Component/BrowserKit/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
CHANGELOG
22
=========
33

4+
4.2.0
5+
-----
6+
7+
* The method `Client::submit()` will have one `$serverParameters` argument
8+
in version 5.0, not defining it is deprecated since version 4.2
9+
410
3.4.0
511
-----
612

src/Symfony/Component/BrowserKit/Client.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,10 @@ public function clickLink(string $linkText): Crawler
311311
*/
312312
public function submit(Form $form, array $values = array()/*, array $serverParameters = array()*/)
313313
{
314+
if (\func_num_args() < 3 && __CLASS__ !== \get_class($this) && __CLASS__ !== (new \ReflectionMethod($this, __FUNCTION__))->getDeclaringClass()->getName() && !$this instanceof \PHPUnit\Framework\MockObject\MockObject && !$this instanceof \Prophecy\Prophecy\ProphecySubjectInterface) {
315+
@trigger_error(sprintf('The "%s()" method will have a third `array $serverParameters = array()` argument in version 5.0 and higher.Not defining it is deprecated since Symfony 4.1.', __METHOD__), E_USER_DEPRECATED);
316+
}
317+
314318
$form->setValues($values);
315319
$serverParameters = 2 < \func_num_args() ? func_get_arg(2) : array();
316320

src/Symfony/Component/BrowserKit/Tests/ClientTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\BrowserKit\CookieJar;
1717
use Symfony\Component\BrowserKit\History;
1818
use Symfony\Component\BrowserKit\Response;
19+
use Symfony\Component\DomCrawler\Form as DomCrawlerForm;
1920

2021
class SpecialResponse extends Response
2122
{
@@ -877,4 +878,42 @@ public function testInternalRequestNull()
877878
$client = new TestClient();
878879
$this->assertNull($client->getInternalRequest());
879880
}
881+
882+
/**
883+
* @group legacy
884+
* @expectedDeprecation The "Symfony\Component\BrowserKit\Client::submit()" method will have a third `array $serverParameters = array()` argument in version 5.0 and higher.Not defining it is deprecated since Symfony 4.1.
885+
*/
886+
public function testInheritedClassCallSubmitWithTwoArguments()
887+
{
888+
$clientChild = new ClassThatInheritClient();
889+
$clientChild->setNextResponse(new Response('<html><form action="/foo"><input type="submit" /></form></html>'));
890+
$clientChild->submit($clientChild->request('GET', 'http://www.example.com/foo/foobar')->filter('input')->form());
891+
}
892+
}
893+
894+
class ClassThatInheritClient extends Client
895+
{
896+
protected $nextResponse = null;
897+
898+
public function setNextResponse(Response $response)
899+
{
900+
$this->nextResponse = $response;
901+
}
902+
903+
protected function doRequest($request)
904+
{
905+
if (null === $this->nextResponse) {
906+
return new Response();
907+
}
908+
909+
$response = $this->nextResponse;
910+
$this->nextResponse = null;
911+
912+
return $response;
913+
}
914+
915+
public function submit(DomCrawlerForm $form, array $values = array())
916+
{
917+
return parent::submit($form, $values);
918+
}
880919
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy