Skip to content

Trigger deprecation notices when inherited class calls parent method but misses adding new arguments #28316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion UPGRADE-4.2.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
UPGRADE FROM 4.1 to 4.2
=======================

BrowserKit
----------

* The `Client::submit()` method will have a new `$serverParameters` argument in version 5.0, not defining it is deprecated.

Cache
-----

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

DomCrawler
----------

* The `Crawler::children()` method will have a new `$selector` argument in version 5.0, not defining it is deprecated.

Finder
------

* The `Finder::sortByName()` method will have a new `$useNaturalSort` argument in version 5.0, not defining it is deprecated.

Form
----

Expand Down Expand Up @@ -123,6 +138,11 @@ Messenger
];
```

Monolog
-------

* 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.

Security
--------

Expand All @@ -149,8 +169,9 @@ SecurityBundle
Serializer
----------

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

Translation
-----------
Expand Down
25 changes: 25 additions & 0 deletions UPGRADE-5.0.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
UPGRADE FROM 4.x to 5.0
=======================

BrowserKit
----------

* The `Client::submit()` method has a new `$serverParameters` argument.

Cache
-----

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

DomCrawler
----------

* The `Crawler::children()` method has a new `$selector` argument.

EventDispatcher
---------------

* The `TraceableEventDispatcherInterface` has been removed.

Finder
------

* The `Finder::sortByName()` method has a new `$useNaturalSort` argument.

FrameworkBundle
---------------

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

Monolog
-------

* The methods `DebugProcessor::getLogs()`, `DebugProcessor::countErrors()`, `Logger::getLogs()` and `Logger::countErrors()` have a new `$request` argument.

Process
-------

Expand Down Expand Up @@ -142,6 +162,11 @@ SecurityBundle
* The `security.authentication.trust_resolver.anonymous_class` parameter has been removed.
* The `security.authentication.trust_resolver.rememberme_class` parameter has been removed.

Serializer
----------

* The `AbstractNormalizer::handleCircularReference()` method has two new `$format` and `$context` arguments.

Translation
-----------

Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Bridge/Monolog/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ CHANGELOG
-----

* added `ProcessorInterface`: an optional interface to allow autoconfiguration of Monolog processors
* 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 since Symfony 4.2.

4.1.0
-----
Expand Down
8 changes: 8 additions & 0 deletions src/Symfony/Bridge/Monolog/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class Logger extends BaseLogger implements DebugLoggerInterface, ResetInterface
*/
public function getLogs(/* Request $request = null */)
{
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) {
@trigger_error(sprintf('The "%s()" method will have a new "Request $request = null" argument in version 5.0, not defining it is deprecated since Symfony 4.2.', __METHOD__), E_USER_DEPRECATED);
}

if ($logger = $this->getDebugLogger()) {
return \call_user_func_array(array($logger, 'getLogs'), \func_get_args());
}
Expand All @@ -40,6 +44,10 @@ public function getLogs(/* Request $request = null */)
*/
public function countErrors(/* Request $request = null */)
{
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) {
@trigger_error(sprintf('The "%s()" method will have a new "Request $request = null" argument in version 5.0, not defining it is deprecated since Symfony 4.2.', __METHOD__), E_USER_DEPRECATED);
}

if ($logger = $this->getDebugLogger()) {
return \call_user_func_array(array($logger, 'countErrors'), \func_get_args());
}
Expand Down
8 changes: 8 additions & 0 deletions src/Symfony/Bridge/Monolog/Processor/DebugProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public function __invoke(array $record)
*/
public function getLogs(/* Request $request = null */)
{
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) {
@trigger_error(sprintf('The "%s()" method will have a new "Request $request = null" argument in version 5.0, not defining it is deprecated since Symfony 4.2.', __METHOD__), E_USER_DEPRECATED);
}

if (1 <= \func_num_args() && null !== ($request = \func_get_arg(0)) && isset($this->records[$hash = spl_object_hash($request)])) {
return $this->records[$hash];
}
Expand All @@ -77,6 +81,10 @@ public function getLogs(/* Request $request = null */)
*/
public function countErrors(/* Request $request = null */)
{
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) {
@trigger_error(sprintf('The "%s()" method will have a new "Request $request = null" argument in version 5.0, not defining it is deprecated since Symfony 4.2.', __METHOD__), E_USER_DEPRECATED);
}

if (1 <= \func_num_args() && null !== ($request = \func_get_arg(0)) && isset($this->errorCount[$hash = spl_object_hash($request)])) {
return $this->errorCount[$hash];
}
Expand Down
33 changes: 33 additions & 0 deletions src/Symfony/Bridge/Monolog/Tests/LoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,37 @@ public function testClear()
$this->assertEmpty($logger->getLogs());
$this->assertSame(0, $logger->countErrors());
}

/**
* @group legacy
* @expectedDeprecation The "Symfony\Bridge\Monolog\Logger::getLogs()" method will have a new "Request $request = null" argument in version 5.0, not defining it is deprecated since Symfony 4.2.
*/
public function testInheritedClassCallGetLogsWithoutArgument()
{
$loggerChild = new ClassThatInheritLogger('test');
$loggerChild->getLogs();
}

/**
* @group legacy
* @expectedDeprecation The "Symfony\Bridge\Monolog\Logger::countErrors()" method will have a new "Request $request = null" argument in version 5.0, not defining it is deprecated since Symfony 4.2.
*/
public function testInheritedClassCallCountErrorsWithoutArgument()
{
$loggerChild = new ClassThatInheritLogger('test');
$loggerChild->countErrors();
}
}

class ClassThatInheritLogger extends Logger
{
public function getLogs()
{
parent::getLogs();
}

public function countErrors()
{
parent::countErrors();
}
}
33 changes: 33 additions & 0 deletions src/Symfony/Bridge/Monolog/Tests/Processor/DebugProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,26 @@ public function testWithRequestStack()
$this->assertSame(1, $processor->countErrors($request));
}

/**
* @group legacy
* @expectedDeprecation The "Symfony\Bridge\Monolog\Processor\DebugProcessor::getLogs()" method will have a new "Request $request = null" argument in version 5.0, not defining it is deprecated since Symfony 4.2.
*/
public function testInheritedClassCallGetLogsWithoutArgument()
{
$debugProcessorChild = new ClassThatInheritDebugProcessor();
$debugProcessorChild->getLogs();
}

/**
* @group legacy
* @expectedDeprecation The "Symfony\Bridge\Monolog\Processor\DebugProcessor::countErrors()" method will have a new "Request $request = null" argument in version 5.0, not defining it is deprecated since Symfony 4.2.
*/
public function testInheritedClassCallCountErrorsWithoutArgument()
{
$debugProcessorChild = new ClassThatInheritDebugProcessor();
$debugProcessorChild->countErrors();
}

private function getRecord($level = Logger::WARNING, $message = 'test')
{
return array(
Expand All @@ -73,3 +93,16 @@ private function getRecord($level = Logger::WARNING, $message = 'test')
);
}
}

class ClassThatInheritDebugProcessor extends DebugProcessor
{
public function getLogs()
{
parent::getLogs();
}

public function countErrors()
{
parent::countErrors();
}
}
6 changes: 6 additions & 0 deletions src/Symfony/Component/BrowserKit/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
CHANGELOG
=========

4.2.0
-----

* The method `Client::submit()` will have a new `$serverParameters` argument
in version 5.0, not defining it is deprecated since version 4.2

3.4.0
-----

Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/BrowserKit/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,10 @@ public function clickLink(string $linkText): Crawler
*/
public function submit(Form $form, array $values = array()/*, array $serverParameters = array()*/)
{
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) {
@trigger_error(sprintf('The "%s()" method will have a new "array $serverParameters = array()" argument in version 5.0, not defining it is deprecated since Symfony 4.2.', __METHOD__), E_USER_DEPRECATED);
}

$form->setValues($values);
$serverParameters = 2 < \func_num_args() ? func_get_arg(2) : array();

Expand Down
39 changes: 39 additions & 0 deletions src/Symfony/Component/BrowserKit/Tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Symfony\Component\BrowserKit\CookieJar;
use Symfony\Component\BrowserKit\History;
use Symfony\Component\BrowserKit\Response;
use Symfony\Component\DomCrawler\Form as DomCrawlerForm;

class SpecialResponse extends Response
{
Expand Down Expand Up @@ -877,4 +878,42 @@ public function testInternalRequestNull()
$client = new TestClient();
$this->assertNull($client->getInternalRequest());
}

/**
* @group legacy
* @expectedDeprecation The "Symfony\Component\BrowserKit\Client::submit()" method will have a new "array $serverParameters = array()" argument in version 5.0, not defining it is deprecated since Symfony 4.2.
*/
public function testInheritedClassCallSubmitWithTwoArguments()
{
$clientChild = new ClassThatInheritClient();
$clientChild->setNextResponse(new Response('<html><form action="/foo"><input type="submit" /></form></html>'));
$clientChild->submit($clientChild->request('GET', 'http://www.example.com/foo/foobar')->filter('input')->form());
}
}

class ClassThatInheritClient extends Client
{
protected $nextResponse = null;

public function setNextResponse(Response $response)
{
$this->nextResponse = $response;
}

protected function doRequest($request)
{
if (null === $this->nextResponse) {
return new Response();
}

$response = $this->nextResponse;
$this->nextResponse = null;

return $response;
}

public function submit(DomCrawlerForm $form, array $values = array())
{
return parent::submit($form, $values);
}
}
2 changes: 2 additions & 0 deletions src/Symfony/Component/DomCrawler/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ CHANGELOG

* The `$currentUri` constructor argument of the `AbstractUriElement`, `Link` and
`Image` classes is now optional.
* The `Crawler::children()` method will have a new `$selector` argument in version 5.0,
not defining it is deprecated since version 4.2.

3.1.0
-----
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Component/DomCrawler/Crawler.php
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,9 @@ public function parents()
*/
public function children(/* string $selector = null */)
{
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) {
@trigger_error(sprintf('The "%s()" method will have a new "string $selector = null" argument in version 5.0, not defining it is deprecated since Symfony 4.2.', __METHOD__), E_USER_DEPRECATED);
}
$selector = 0 < \func_num_args() ? func_get_arg(0) : null;

if (!$this->nodes) {
Expand Down
Loading