8000 minor #33484 Fix test fixtures with deprecated method signatures (der… · symfony/symfony@1b835d1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1b835d1

Browse files
minor #33484 Fix test fixtures with deprecated method signatures (derrabus, nicolas-grekas)
This PR was merged into the 4.3 branch. Discussion ---------- Fix test fixtures with deprecated method signatures | Q | A | ------------- | --- | Branch? | 4.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #33483 (partly) | License | MIT | Doc PR | N/A This PR upgrades two fixtures that implemented deprecated method signatures. As far as I can tell, they are used in tests that do not specifically test legacy behavior, so the fixtures should be up to date. Currently, these fixtures cause failing tests on the 4.4 branch. Commits ------- cc3e3d5 Fix more bad tests 592aacf Fix test fixtures with deprecated method signatures.
2 parents 2feae7b + cc3e3d5 commit 1b835d1

21 files changed

+370
-270
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\Monolog\Tests;
13+
14+
use Symfony\Bridge\Monolog\Logger;
15+
16+
class ClassThatInheritLogger extends Logger
17+
{
18+
public function getLogs(): array
19+
{
20+
return parent::getLogs();
21+
}
22+
23+
public function countErrors(): int
24+
{
9E7A
25+
return parent::countErrors();
26+
}
27+
}

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

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -128,33 +128,12 @@ public function testReset()
128128
/**
129129
* @group legacy
130130
* @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.
131-
*/
132-
public function testInheritedClassCallGetLogsWithoutArgument()
133-
{
134-
$loggerChild = new ClassThatInheritLogger('test');
135-
$loggerChild->getLogs();
136-
}
137-
138-
/**
139-
* @group legacy
140131
* @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.
141132
*/
142-
public function testInheritedClassCallCountErrorsWithoutArgument()
133+
public function testInheritedClassWithoutArgument()
143134
{
144135
$loggerChild = new ClassThatInheritLogger('test');
136+
$loggerChild->getLogs();
145137
$loggerChild->countErrors();
146138
}
147139
}
148-
149-
class ClassThatInheritLogger extends Logger
150-
{
151-
public function getLogs()
152-
{
153-
parent::getLogs();
154-
}
155-
156-
public function countErrors()
157-
{
158-
parent::countErrors();
159-
}
160-
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\Monolog\Tests\Processor;
13+
14+
use Symfony\Bridge\Monolog\Processor\DebugProcessor;
15+
16+
class ClassThatInheritDebugProcessor extends DebugProcessor
17+
{
18+
public function getLogs(): array
19+
{
20+
return parent::getLogs();
21+
}
22+
23+
public function countErrors(): int
24+
{
25+
return parent::countErrors();
26+
}
27+
}

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

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,12 @@ public function testWithRequestStack()
6666
/**
6767
* @group legacy
6868
* @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.
69-
*/
70-
public function testInheritedClassCallGetLogsWithoutArgument()
71-
{
72-
$debugProcessorChild = new ClassThatInheritDebugProcessor();
73-
$debugProcessorChild->getLogs();
74-
}
75-
76-
/**
77-
* @group legacy
7869
* @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.
7970
*/
80-
public function testInheritedClassCallCountErrorsWithoutArgument()
71+
public function testInheritedClassWithoutArgument()
8172
{
8273
$debugProcessorChild = new ClassThatInheritDebugProcessor();
74+
$debugProcessorChild->getLogs();
8375
$debugProcessorChild->countErrors();
8476
}
8577

@@ -96,16 +88,3 @@ private function getRecord($level = Logger::WARNING, $message = 'test')
9688
];
9789
}
9890
}
99-
100-
class ClassThatInheritDebugProcessor extends DebugProcessor
101-
{
102-
public function getLogs()
103-
{
104-
parent::getLogs();
105-
}
106-
107-
public function countErrors()
108-
{
109-
parent::countErrors();
110-
}
111-
}

src/Symfony/Bundle/FrameworkBundle/Tests/Controller/AbstractControllerTest.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,18 @@ public function testMissingParameterBag()
8181

8282
class TestAbstractController extends AbstractController
8383
{
84-
use TestControllerTrait;
85-
8684
private $throwOnUnexpectedService;
8785

8886
public function __construct($throwOnUnexpectedService = true)
8987
{
9088
$this->throwOnUnexpectedService = $throwOnUnexpectedService;
9189
}
9290

91+
public function __call(string $method, array $arguments)
92+
{
93+
return $this->$method(...$arguments);
94+
}
95+
9396
public function setContainer(ContainerInterface $container)
9497
{
9598
if (!$this->throwOnUnexpectedService) {
@@ -114,11 +117,6 @@ public function setContainer(ContainerInterface $container)
114117
return parent::setContainer($container);
115118
}
116119

117-
public function getParameter(string $name)
118-
{
119-
return parent::getParameter($name);
120-
}
121-
122120
public function fooAction()
123121
{
124122
}

src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerTraitTest.php

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Controller;
1313

1414
use Fig\Link\Link;
15-
use Symfony\Bundle\FrameworkBundle\Controller\ControllerTrait;
1615
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
1716
use Symfony\Component\DependencyInjection\Container;
1817
use Symfony\Component\Form\Form;
@@ -550,29 +549,3 @@ public function testAddLink()
550549
$this->assertContains($link2, $links);
551550
}
552551
}
553-
554-
trait TestControllerTrait
555-
{
556-
use ControllerTrait {
557-
generateUrl as public;
558-
redirect as public;
559-
forward as public;
560-
getUser as public;
561-
json as public;
562-
file as public;
563-
isGranted as public;
564-
denyAccessUnlessGranted as public;
565-
redirectToRoute as public;
566-
addFlash as public;
567-
isCsrfTokenValid as public;
568-
renderView as public;
569-
render as public;
570-
stream as public;
571-
createNotFoundException as public;
572-
createAccessDeniedException as public;
573-
createForm as public;
574-
createFormBuilder as public;
575-
getDoctrine as public;
576-
addLink as public;
577-
}
578-
}

src/Symfony/Bundle/FrameworkBundle/Tests/Controller/TestController.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,30 @@
33
namespace Symfony\Bundle\FrameworkBundle\Tests\Controller;
44

55
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6+
use Symfony\Bundle\FrameworkBundle\Controller\ControllerTrait;
67

78
class TestController extends Controller
89
{
9-
use TestControllerTrait;
10+
use ControllerTrait {
11+
generateUrl as public;
12+
redirect as public;
13+
forward as public;
14+
getUser as public;
15+
json as public;
16+
file as public;
17+
isGranted as public;
18+
denyAccessUnlessGranted as public;
19+
redirectToRoute as public;
20+
addFlash as public;
21+
isCsrfTokenValid as public;
22+
renderView as public;
23+
render as public;
24+
stream as public;
25+
createNotFoundException as public;
26+
createAccessDeniedException as public;
27+
createForm as public;
28+
createFormBuilder as public;
29+
getDoctrine as public;
30+
addLink as public;
31+
}
1032
}

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

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -19,61 +19,6 @@
1919
use Symfony\Component\BrowserKit\Response;
2020
use Symfony\Component\DomCrawler\Form as DomCrawlerForm;
2121

22-
class SpecialResponse extends Response
23-
{
24-
}
25-
26-
class TestClient extends AbstractBrowser
27-
{
28-
protected $nextResponse = null;
29-
protected $nextScript = null;
30-
31-
public function setNextResponse(Response $response)
32- 10000
{
33-
$this->nextResponse = $response;
34-
}
35-
36-
public function setNextScript($script)
37-
{
38-
$this->nextScript = $script;
39-
}
40-
41-
protected function doRequest($request)
42-
{
43-
if (null === $this->nextResponse) {
44-
return new Response();
45-
}
46-
47-
$response = $this->nextResponse;
48-
$this->nextResponse = null;
49-
50-
return $response;
51-
}
52-
53-
protected function filterResponse($response)
54-
{
55-
if ($response instanceof SpecialResponse) {
56-
return new Response($response->getContent(), $response->getStatusCode(), $response->getHeaders());
57-
}
58-
59-
return $response;
60-
}
61-
62-
protected function getScript($request)
63-
{
64-
$r = new \ReflectionClass('Symfony\Component\BrowserKit\Response');
65-
$path = $r->getFileName();
66-
67-
return <<<EOF
68-
<?php
69-
70-
require_once('$path');
71-
72-
echo serialize($this->nextScript);
73-
EOF;
74-
}
75-
}
76-
7722
class AbstractBrowserTest extends TestCase
7823
{
7924
public function getBrowser(array $server = [], History $history = null, CookieJar $cookieJar = null)
@@ -159,17 +104,6 @@ public function testGetResponseNull()
159104
$this->assertNull($client->getResponse());
160105
}
161106

162-
public function testGetInternalResponse()
163-
{
164-
$client = $this->getBrowser();
165-
$client->setNextResponse(new SpecialResponse('foo'));
166-
$client->request('GET', 'http://example.com/');
167-
168-
$this->assertInstanceOf('Symfony\Component\BrowserKit\Response', $client->getInternalResponse());
169-
$this->assertNotInstanceOf('Symfony\Component\BrowserKit\Tests\SpecialResponse', $client->getInternalResponse());
170-
$this->assertInstanceOf('Symfony\Component\BrowserKit\Tests\SpecialResponse', $client->getResponse());
171-
}
172-
173107
/**
174108
* @group legacy
175109
* @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.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\BrowserKit\Tests;
13+
14+
use Symfony\Component\BrowserKit\AbstractBrowser;
15+
use Symfony\Component\BrowserKit\Response;
16+
use Symfony\Component\DomCrawler\Crawler;
17+
use Symfony\Component\DomCrawler\Form as DomCrawlerForm;
18+
19+
class ClassThatInheritClient extends AbstractBrowser
20+
{
21+
protected $nextResponse = null;
22+
23+
public function setNextResponse(Response $response)
24+
{
25+
$this->nextResponse = $response;
26+
}
27+
28+
protected function doRequest($request): Response
29+
{
30+
if (null === $this->nextResponse) {
31+
return new Response();
32+
}
33+
34+
$response = $this->nextResponse;
35+
$this->nextResponse = null;
36+
37+
return $response;
38+
}
39+
40+
public function submit(DomCrawlerForm $form, array $values = []): Crawler
41+
{
42+
return parent::submit($form, $values);
43+
}
44+
}

0 commit comments

Comments
 (0)
0