Skip to content

Commit da43309

Browse files
Merge branch '2.7' into 2.8
* 2.7: Always enable clock-mock for HttpFoundation [ClassLoader] Fix parsing namespace when token_get_all() is missing Bug #16343 [Router] Too many Routes ? [Debug] Ensure class declarations are loaded only once
2 parents 1abfecf + d1a50a2 commit da43309

File tree

6 files changed

+52
-5
lines changed

6 files changed

+52
-5
lines changed

phpunit.xml.dist

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,14 @@
4747
</exclude>
4848
</whitelist>
4949
</filter>
50+
51+
<listeners>
52+
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener">
53+
<arguments>
54+
<array>
55+
<element><string>Symfony\Component\HttpFoundation</string></element>
56+
</array>
57+
</arguments>
58+
</listener>
59+
</listeners>
5060
</phpunit>

src/Symfony/Component/ClassLoader/ClassCollectionLoader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ public static function load($classes, $cacheDir, $name, $autoReload, $adaptive =
137137
public static function fixNamespaceDeclarations($source)
138138
{
139139
if (!function_exists('token_get_all') || !self::$useTokenizer) {
140-
if (preg_match('/namespace(.*?)\s*;/', $source)) {
141-
$source = preg_replace('/namespace(.*?)\s*;/', "namespace$1\n{", $source)."}\n";
140+
if (preg_match('/(^|\s)namespace(.*?)\s*;/', $source)) {
141+
$source = preg_replace('/(^|\s)namespace(.*?)\s*;/', "$1namespace$2\n{", $source)."}\n";
142142
}
143143

144144
return $source;

src/Symfony/Component/ClassLoader/Tests/ClassCollectionLoaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public function getFixNamespaceDeclarationsDataWithoutTokenizer()
205205
array("namespace Bar ;\nclass Foo {}\n", "namespace Bar\n{\nclass Foo {}\n}\n"),
206206
array("namespace Foo\Bar;\nclass Foo {}\n", "namespace Foo\Bar\n{\nclass Foo {}\n}\n"),
207207
array("namespace Foo\Bar\Bar\n{\nclass Foo {}\n}\n", "namespace Foo\Bar\Bar\n{\nclass Foo {}\n}\n"),
208-
array("namespace\n{\nclass Foo {}\n}\n", "namespace\n{\nclass Foo {}\n}\n"),
208+
array("\nnamespace\n{\nclass Foo {}\n\$namespace=123;}\n", "\nnamespace\n{\nclass Foo {}\n\$namespace=123;}\n"),
209209
);
210210
}
211211

src/Symfony/Component/Debug/DebugClassLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public function loadClass($class)
147147
try {
148148
if ($this->isFinder) {
149149
if ($file = $this->classLoader[0]->findFile($class)) {
150-
require $file;
150+
require_once $file;
151151
}
152152
} else {
153153
call_user_func($this->classLoader, $class);

src/Symfony/Component/Routing/Generator/Dumper/PhpGeneratorDumper.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function dump(array $options = array())
5353
*/
5454
class {$options['class']} extends {$options['base_class']}
5555
{
56-
private static \$declaredRoutes = {$this->generateDeclaredRoutes()};
56+
private static \$declaredRoutes;
5757
5858
/**
5959
* Constructor.
@@ -62,6 +62,9 @@ public function __construct(RequestContext \$context, LoggerInterface \$logger =
6262
{
6363
\$this->context = \$context;
6464
\$this->logger = \$logger;
65+
if (null === self::\$declaredRoutes) {
66+
self::\$declaredRoutes = {$this->generateDeclaredRoutes()};
67+
}
6568
}
6669
6770
{$this->generateGenerateMethod()}

src/Symfony/Component/Routing/Tests/Generator/Dumper/PhpGeneratorDumperTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,21 @@ class PhpGeneratorDumperTest extends \PHPUnit_Framework_TestCase
3434
*/
3535
private $testTmpFilepath;
3636

37+
/**
38+
* @var string
39+
*/
40+
private $largeTestTmpFilepath;
41+
3742
protected function setUp()
3843
{
3944
parent::setUp();
4045

4146
$this->routeCollection = new RouteCollection();
4247
$this->generatorDumper = new PhpGeneratorDumper($this->routeCollection);
4348
$this->testTmpFilepath = sys_get_temp_dir().DIRECTORY_SEPARATOR.'php_generator.'.$this->getName().'.php';
49+
$this->largeTestTmpFilepath = sys_get_temp_dir().DIRECTORY_SEPARATOR.'php_generator.'.$this->getName().'.large.php';
4450
@unlink($this->testTmpFilepath);
51+
@unlink($this->largeTestTmpFilepath);
4552
}
4653

4754
protected function tearDown()
@@ -76,6 +83,33 @@ public function testDumpWithRoutes()
7683
$this->assertEquals($relativeUrlWithoutParameter, '/app.php/testing2');
7784
}
7885

86+
public function testDumpWithTooManyRoutes()
87+
{
88+
$this->routeCollection->add('Test', new Route('/testing/{foo}'));
89+
for ( $i = 0; $i < 32769; ++$i ) {
90+
$this->routeCollection->add('route_'.$i, new Route('/route_'.$i));
91+
}
92+
$this->routeCollection->add('Test2', new Route('/testing2'));
93+
94+
$data = $this->generatorDumper->dump(array(
95+
'class' => 'ProjectLargeUrlGenerator',
96+
));
97+
file_put_contents($this->largeTestTmpFilepath, $data);
98+
include $this->largeTestTmpFilepath;
99+
100+
$projectUrlGenerator = new \ProjectLargeUrlGenerator(new RequestContext('/app.php'));
101+
102+
$absoluteUrlWithParameter = $projectUrlGenerator->generate('Test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_URL);
103+
$absoluteUrlWithoutParameter = $projectUrlGenerator->generate('Test2', array(), UrlGeneratorInterface::ABSOLUTE_URL);
104+
$relativeUrlWithParameter = $projectUrlGenerator->generate('Test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_PATH);
105+
$relativeUrlWithoutParameter = $projectUrlGenerator->generate('Test2', array(), UrlGeneratorInterface::ABSOLUTE_PATH);
106+
107+
$this->assertEquals($absoluteUrlWithParameter, 'http://localhost/app.php/testing/bar');
108+
$this->assertEquals($absoluteUrlWithoutParameter, 'http://localhost/app.php/testing2');
109+
$this->assertEquals($relativeUrlWithParameter, '/app.php/testing/bar');
110+
$this->assertEquals($relativeUrlWithoutParameter, '/app.php/testing2');
111+
}
112+
79113
/**
80114
* @expectedException \InvalidArgumentException
81115
*/

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