Skip to content

Commit f66bf4f

Browse files
committed
Merge branch '6.4' into 7.3
* 6.4: do not use PHPUnit mock objects without configured expectations fix low deps test with Console component < 6.4 [FrameworkBundle] Check for console package before register `CommandDataCollector` do not use PHPUnit mock objects without configured expectations [FrameworkBundle] Ensure a fresh container is used after cache warmup in KernelTestCase do not use PHPUnit mock objects without configured expectations do not use PHPUnit mock objects without configured expectations [Finder] Fix `Finder::append()` breaking generic typing contract
2 parents de7849b + 0dc6253 commit f66bf4f

File tree

6 files changed

+91
-59
lines changed

6 files changed

+91
-59
lines changed

Tests/Loader/PhpFileLoaderTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Config\FileLocator;
16+
use Symfony\Component\Config\FileLocatorInterface;
1617
use Symfony\Component\Config\Loader\LoaderResolver;
1718
use Symfony\Component\Config\Resource\FileResource;
1819
use Symfony\Component\Routing\Loader\AttributeClassLoader;
@@ -26,7 +27,7 @@ class PhpFileLoaderTest extends TestCase
2627
{
2728
public function testSupports()
2829
{
29-
$loader = new PhpFileLoader($this->createMock(FileLocator::class));
30+
$loader = new PhpFileLoader($this->createStub(FileLocatorInterface::class));
3031

3132
$this->assertTrue($loader->supports('foo.php'), '->supports() returns true if the resource is loadable');
3233
$this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');

Tests/Loader/XmlFileLoaderTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Config\FileLocator;
16+
use Symfony\Component\Config\FileLocatorInterface;
1617
use Symfony\Component\Config\Loader\LoaderResolver;
1718
use Symfony\Component\Config\Resource\FileResource;
1819
use Symfony\Component\Routing\Loader\AttributeClassLoader;
@@ -27,7 +28,7 @@ class XmlFileLoaderTest extends TestCase
2728
{
2829
public function testSupports()
2930
{
30-
$loader = new XmlFileLoader($this->createMock(FileLocator::class));
31+
$loader = new XmlFileLoader($this->createStub(FileLocatorInterface::class));
3132

3233
$this->assertTrue($loader->supports('foo.xml'), '->supports() returns true if the resource is loadable');
3334
$this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');

Tests/Loader/YamlFileLoaderTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Config\FileLocator;
16+
use Symfony\Component\Config\FileLocatorInterface;
1617
use Symfony\Component\Config\Loader\LoaderResolver;
1718
use Symfony\Component\Config\Resource\FileResource;
1819
use Symfony\Component\Routing\Loader\AttributeClassLoader;
@@ -26,7 +27,7 @@ class YamlFileLoaderTest extends TestCase
2627
{
2728
public function testSupports()
2829
{
29-
$loader = new YamlFileLoader($this->createMock(FileLocator::class));
30+
$loader = new YamlFileLoader($this->createStub(FileLocatorInterface::class));
3031

3132
$this->assertTrue($loader->supports('foo.yml'), '->supports() returns true if the resource is loadable');
3233
$this->assertTrue($loader->supports('foo.yaml'), '->supports() returns true if the resource is loadable');

Tests/Matcher/CompiledRedirectableUrlMatcherTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@
1919

2020
class CompiledRedirectableUrlMatcherTest extends RedirectableUrlMatcherTest
2121
{
22-
protected function getUrlMatcher(RouteCollection $routes, ?RequestContext $context = null)
22+
protected function getUrlMatcher(RouteCollection $routes, ?RequestContext $context = null, bool $mock = false)
2323
{
2424
$dumper = new CompiledUrlMatcherDumper($routes);
2525
$compiledRoutes = $dumper->getCompiledRoutes();
2626

27+
if (!$mock) {
28+
return new TestCompiledRedirectableUrlMatcher($compiledRoutes, $context ?? new RequestContext());
29+
}
30+
2731
return $this->getMockBuilder(TestCompiledRedirectableUrlMatcher::class)
2832
->setConstructorArgs([$compiledRoutes, $context ?? new RequestContext()])
2933
->onlyMethods(['redirect'])

Tests/Matcher/RedirectableUrlMatcherTest.php

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function testMissingTrailingSlash()
2424
$coll = new RouteCollection();
2525
$coll->add('foo', new Route('/foo/'));
2626

27-
$matcher = $this->getUrlMatcher($coll);
27+
$matcher = $this->getUrlMatcher($coll, null, true);
2828
$matcher->expects($this->once())->method('redirect')->willReturn([]);
2929
$matcher->match('/foo');
3030
}
@@ -34,7 +34,7 @@ public function testExtraTrailingSlash()
3434
$coll = new RouteCollection();
3535
$coll->add('foo', new Route('/foo'));
3636

37-
$matcher = $this->getUrlMatcher($coll);
37+
$matcher = $this->getUrlMatcher($coll, null, true);
3838
$matcher->expects($this->once())->method('redirect')->willReturn([]);
3939
$matcher->match('/foo/');
4040
}
@@ -58,7 +58,7 @@ public function testSchemeRedirectRedirectsToFirstScheme()
5858
$coll = new RouteCollection();
5959
$coll->add('foo', new Route('/foo', [], [], [], '', ['FTP', 'HTTPS']));
6060

61-
$matcher = $this->getUrlMatcher($coll);
61+
$matcher = $this->getUrlMatcher($coll, null, true);
6262
$matcher
6363
->expects($this->once())
6464
->method('redirect')
@@ -73,7 +73,7 @@ public function testNoSchemaRedirectIfOneOfMultipleSchemesMatches()
7373
$coll = new RouteCollection();
7474
$coll->add('foo', new Route('/foo', [], [], [], '', ['https', 'http']));
7575

76-
$matcher = $this->getUrlMatcher($coll);
76+
$matcher = $this->getUrlMatcher($coll, null, true);
7777
$matcher
7878
->expects($this->never())
7979
->method('redirect');
@@ -85,7 +85,7 @@ public function testSchemeRedirectWithParams()
8585
$coll = new RouteCollection();
8686
$coll->add('foo', new Route('/foo/{bar}', [], [], [], '', ['https']));
8787

88-
$matcher = $this->getUrlMatcher($coll);
88+
$matcher = $this->getUrlMatcher($coll, null, true);
8989
$matcher
9090
->expects($this->once())
9191
->method('redirect')
@@ -100,7 +100,7 @@ public function testSchemeRedirectForRoot()
100100
$coll = new RouteCollection();
101101
$coll->add('foo', new Route('/', [], [], [], '', ['https']));
102102

103-
$matcher = $this->getUrlMatcher($coll);
103+
$matcher = $this->getUrlMatcher($coll, null, true);
104104
$matcher
105105
->expects($this->once())
106106
->method('redirect')
@@ -114,7 +114,7 @@ public function testSlashRedirectWithParams()
114114
$coll = new RouteCollection();
115115
$coll->add('foo', new Route('/foo/{bar}/'));
116116

117-
$matcher = $this->getUrlMatcher($coll);
117+
$matcher = $this->getUrlMatcher($coll, null, true);
118118
$matcher
119119
->expects($this->once())
120120
->method('redirect')
@@ -129,7 +129,7 @@ public function testRedirectPreservesUrlEncoding()
129129
$coll = new RouteCollection();
130130
$coll->add('foo', new Route('/foo:bar/'));
131131

132-
$matcher = $this->getUrlMatcher($coll);
132+
$matcher = $this->getUrlMatcher($coll, null, true);
133133
$matcher->expects($this->once())->method('redirect')->with('/foo%3Abar/')->willReturn([]);
134134
$matcher->match('/foo%3Abar');
135135
}
@@ -138,7 +138,7 @@ public function testSchemeRequirement()
138138
{
139139
$coll = new RouteCollection();
140140
$coll->add('foo', new Route('/foo', [], [], [], '', ['https']));
141-
$matcher = $this->getUrlMatcher($coll, new RequestContext());
141+
$matcher = $this->getUrlMatcher($coll, new RequestContext(), true);
142142
$matcher->expects($this->once())->method('redirect')->with('/foo', 'foo', 'https')->willReturn([]);
143143
$this->assertSame(['_route' => 'foo'], $matcher->match('/foo'));
144144
}
@@ -149,15 +149,15 @@ public function testFallbackPage()
149149
$coll->add('foo', new Route('/foo/'));
150150
$coll->add('bar', new Route('/{name}'));
151151

152-
$matcher = $this->getUrlMatcher($coll);
152+
$matcher = $this->getUrlMatcher($coll, null, true);
153153
$matcher->expects($this->once())->method('redirect')->with('/foo/', 'foo')->willReturn(['_route' => 'foo']);
154154
$this->assertSame(['_route' => 'foo'], $matcher->match('/foo'));
155155

156156
$coll = new RouteCollection();
157157
$coll->add('foo', new Route('/foo'));
158158
$coll->add('bar', new Route('/{name}/'));
159159

160-
$matcher = $this->getUrlMatcher($coll);
160+
$matcher = $this->getUrlMatcher($coll, null, true);
161161
$matcher->expects($this->once())->method('redirect')->with('/foo', 'foo')->willReturn(['_route' => 'foo']);
162162
$this->assertSame(['_route' => 'foo'], $matcher->match('/foo/'));
163163
}
@@ -167,7 +167,7 @@ public function testMissingTrailingSlashAndScheme()
167167
$coll = new RouteCollection();
168168
$coll->add('foo', (new Route('/foo/'))->setSchemes(['https']));
169169

170-
$matcher = $this->getUrlMatcher($coll);
170+
$matcher = $this->getUrlMatcher($coll, null, true);
171171
$matcher->expects($this->once())->method('redirect')->with('/foo/', 'foo', 'https')->willReturn([]);
172172
$matcher->match('/foo');
173173
}
@@ -178,7 +178,7 @@ public function testSlashAndVerbPrecedenceWithRedirection()
178178
$coll->add('a', new Route('/api/customers/{customerId}/contactpersons', [], [], [], '', [], ['post']));
179179
$coll->add('b', new Route('/api/customers/{customerId}/contactpersons/', [], [], [], '', [], ['get']));
180180

181-
$matcher = $this->getUrlMatcher($coll);
181+
$matcher = $this->getUrlMatcher($coll, null, true);
182182
$expected = [
183183
'_route' => 'b',
184184
'customerId' => '123',
@@ -194,7 +194,7 @@ public function testNonGreedyTrailingRequirement()
194194
$coll = new RouteCollection();
195195
$coll->add('a', new Route('/{a}', [], ['a' => '\d+']));
196196

197-
$matcher = $this->getUrlMatcher($coll);
197+
$matcher = $this->getUrlMatcher($coll, null, true);
198198
$matcher->expects($this->once())->method('redirect')->with('/123')->willReturn([]);
199199

200200
$this->assertEquals(['_route' => 'a', 'a' => '123'], $matcher->match('/123/'));
@@ -205,14 +205,23 @@ public function testTrailingRequirementWithDefaultA()
205205
$coll = new RouteCollection();
206206
$coll->add('a', new Route('/fr-fr/{a}', ['a' => 'aaa'], ['a' => '.+']));
207207

208-
$matcher = $this->getUrlMatcher($coll);
208+
$matcher = $this->getUrlMatcher($coll, null, true);
209209
$matcher->expects($this->once())->method('redirect')->with('/fr-fr')->willReturn([]);
210210

211211
$this->assertEquals(['_route' => 'a', 'a' => 'aaa'], $matcher->match('/fr-fr/'));
212212
}
213213

214-
protected function getUrlMatcher(RouteCollection $routes, ?RequestContext $context = null)
214+
protected function getUrlMatcher(RouteCollection $routes, ?RequestContext $context = null, bool $mock = false)
215215
{
216+
if (!$mock) {
217+
return new class($routes, $context ?? new RequestContext()) extends RedirectableUrlMatcher {
218+
public function redirect(string $path, string $route, ?string $scheme = null): array
219+
{
220+
return [];
221+
}
222+
};
223+
}
224+
216225
return $this->getMockBuilder(RedirectableUrlMatcher::class)
217226
->setConstructorArgs([$routes, $context ?? new RequestContext()])
218227
->onlyMethods(['redirect'])

0 commit comments

Comments
 (0)