Skip to content

Fix test fixtures with deprecated method signatures #33484

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 2 commits into from
Sep 6, 2019
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
27 changes: 27 additions & 0 deletions src/Symfony/Bridge/Monolog/Tests/ClassThatInheritLogger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bridge\Monolog\Tests;

use Symfony\Bridge\Monolog\Logger;

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

public function countErrors(): int
{
return parent::countErrors();
}
}
25 changes: 2 additions & 23 deletions src/Symfony/Bridge/Monolog/Tests/LoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,33 +128,12 @@ public function testReset()
/**
* @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()
public function testInheritedClassWithoutArgument()
{
$loggerChild = new ClassThatInheritLogger('test');
$loggerChild->getLogs();
$loggerChild->countErrors();
}
}

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

public function countErrors()
{
parent::countErrors();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bridge\Monolog\Tests\Processor;

use Symfony\Bridge\Monolog\Processor\DebugProcessor;

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

public function countErrors(): int
{
return parent::countErrors();
}
}
25 changes: 2 additions & 23 deletions src/Symfony/Bridge/Monolog/Tests/Processor/DebugProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,12 @@ public function testWithRequestStack()
/**
* @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()
public function testInheritedClassWithoutArgument()
{
$debugProcessorChild = new ClassThatInheritDebugProcessor();
$debugProcessorChild->getLogs();
$debugProcessorChild->countErrors();
}

Expand All @@ -96,16 +88,3 @@ private function getRecord($level = Logger::WARNING, $message = 'test')
];
}
}

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

public function countErrors()
{
parent::countErrors();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,18 @@ public function testMissingParameterBag()

class TestAbstractController extends AbstractController
{
use TestControllerTrait;

private $throwOnUnexpectedService;

public function __construct($throwOnUnexpectedService = true)
{
$this->throwOnUnexpectedService = $throwOnUnexpectedService;
}

public function __call(string $method, array $arguments)
{
return $this->$method(...$arguments);
}

public function setContainer(ContainerInterface $container)
{
if (!$this->throwOnUnexpectedService) {
Expand All @@ -114,11 +117,6 @@ public function setContainer(ContainerInterface $container)
return parent::setContainer($container);
}

public function getParameter(string $name)
{
return parent::getParameter($name);
}

public function fooAction()
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\Controller;

use Fig\Link\Link;
use Symfony\Bundle\FrameworkBundle\Controller\ControllerTrait;
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\Form\Form;
Expand Down Expand Up @@ -550,29 +549,3 @@ public function testAddLink()
$this->assertContains($link2, $links);
}
}

trait TestControllerTrait
{
use ControllerTrait {
generateUrl as public;
redirect as public;
forward as public;
getUser as public;
json as public;
file as public;
isGranted as public;
denyAccessUnlessGranted as public;
redirectToRoute as public;
addFlash as public;
isCsrfTokenValid as public;
renderView as public;
render as public;
stream as public;
createNotFoundException as public;
createAccessDeniedException as public;
createForm as public;
createFormBuilder as public;
getDoctrine as public;
addLink as public;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,30 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\ControllerTrait;

class TestController extends Controller
{
use TestControllerTrait;
use ControllerTrait {
generateUrl as public;
redirect as public;
forward as public;
getUser as public;
json as public;
file as public;
isGranted as public;
denyAccessUnlessGranted as public;
redirectToRoute as public;
addFlash as public;
isCsrfTokenValid as public;
renderView as public;
render as public;
stream as public;
createNotFoundException as public;
createAccessDeniedException as public;
createForm as public;
createFormBuilder as public;
getDoctrine as public;
addLink as public;
}
}
66 changes: 0 additions & 66 deletions src/Symfony/Component/BrowserKit/Tests/AbstractBrowserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,61 +19,6 @@
use Symfony\Component\BrowserKit\Response;
use Symfony\Component\DomCrawler\Form as DomCrawlerForm;

class SpecialResponse extends Response
{
}

class TestClient extends AbstractBrowser
{
protected $nextResponse = null;
protected $nextScript = null;

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

public function setNextScript($script)
{
$this->nextScript = $script;
}

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

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

return $response;
}

protected function filterResponse($response)
{
if ($response instanceof SpecialResponse) {
return new Response($response->getContent(), $response->getStatusCode(), $response->getHeaders());
}

return $response;
}

protected function getScript($request)
{
$r = new \ReflectionClass('Symfony\Component\BrowserKit\Response');
$path = $r->getFileName();

return <<<EOF
<?php

require_once('$path');

echo serialize($this->nextScript);
EOF;
}
}

class AbstractBrowserTest extends TestCase
{
public function getBrowser(array $server = [], History $history = null, CookieJar $cookieJar = null)
Expand Down Expand Up @@ -159,17 +104,6 @@ public function testGetResponseNull()
$this->assertNull($client->getResponse());
}

public function testGetInternalResponse()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from #30602, this test is wrong: it relies on a class that extends Response while the class is @final
from #31674, it has already been removed from master, despite the fact it was not marked as legacy.
That's two mistakes in a row, fortunately, the recent improvements of DebugClassLoader will allow catching those before they happen :)

{
$client = $this->getBrowser();
$client->setNextResponse(new SpecialResponse('foo'));
$client->request('GET', 'http://example.com/');

$this->assertInstanceOf('Symfony\Component\BrowserKit\Response', $client->getInternalResponse());
$this->assertNotInstanceOf('Symfony\Component\BrowserKit\Tests\SpecialResponse', $client->getInternalResponse());
$this->assertInstanceOf('Symfony\Component\BrowserKit\Tests\SpecialResponse', $client->getResponse());
}

/**
* @group legacy
* @expectedDeprecation Calling the "Symfony\Component\BrowserKit\Tests\%s::getInternalResponse()" method before the "request()" one is deprecated since Symfony 4.1 and will throw an exception in 5.0.
Expand Down
44 changes: 44 additions & 0 deletions src/Symfony/Component/BrowserKit/Tests/ClassThatInheritClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\BrowserKit\Tests;

use Symfony\Component\BrowserKit\AbstractBrowser;
use Symfony\Component\BrowserKit\Response;
use Symfony\Component\DomCrawler\Crawler;
use Symfony\Component\DomCrawler\Form as DomCrawlerForm;

class ClassThatInheritClient extends AbstractBrowser
{
protected $nextResponse = null;

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

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

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

return $response;
}

public function submit(DomCrawlerForm $form, array $values = []): Crawler
{
return parent::submit($form, $values);
}
}
Loading