Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit db4f551

Browse filesBrowse files
committed
Merge branch '2.4'
* 2.4: [Debug] fixed unit tests Avoid notice from being *eaten* by fatal error. Teardown used wrong property Modified guessDefaultEscapingStrategy to not escape txt templates Fix DateType for 32bits computers. Fixed the registration of validation.xml file when the form is disabled fixed lexing expression ending with spaces Fixes #9633, Removed dependency to Symfony\Bundle\FrameworkBundle\Tests\TestCase [Validator] Replaced inexistent interface. [HttpKernel] Fix profiler event-listener usage outside request stack context When getting the session's id, check if the session is not closed Fix undefined offset when formatting namespace suggestions Adjusting CacheClear Warmup method to namespaced kernels
2 parents ce64435 + 1a33e1b commit db4f551
Copy full SHA for db4f551

File tree

Expand file treeCollapse file tree

20 files changed

+288
-30
lines changed
Filter options
Expand file treeCollapse file tree

20 files changed

+288
-30
lines changed

‎src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,9 @@ protected function warmup($warmupDir, $realCacheDir, $enableOptionalWarmers = tr
120120
$warmer->warmUp($warmupDir);
121121

122122
// fix references to the Kernel in .meta files
123-
124123
$safeTempKernel = str_replace('\\', '\\\\', get_class($tempKernel));
125124
$realKernelFQN = get_class($realKernel);
126-
125+
127126
foreach (Finder::create()->files()->name('*.meta')->in($warmupDir) as $file) {
128127
file_put_contents($file, preg_replace(
129128
'/(C\:\d+\:)"'.$safeTempKernel.'"/',

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+7-3Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -671,9 +671,13 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
671671

672672
private function getValidatorXmlMappingFiles(ContainerBuilder $container)
673673
{
674-
$reflClass = new \ReflectionClass('Symfony\Component\Form\FormInterface');
675-
$files = array(dirname($reflClass->getFileName()).'/Resources/config/validation.xml');
676-
$container->addResource(new FileResource($files[0]));
674+
$files = array();
675+
676+
if (interface_exists('Symfony\Component\Form\FormInterface')) {
677+
$reflClass = new \ReflectionClass('Symfony\Component\Form\FormInterface');
678+
$files[] = dirname($reflClass->getFileName()).'/Resources/config/validation.xml';
679+
$container->addResource(new FileResource($files[0]));
680+
}
677681

678682
foreach ($container->getParameter('kernel.bundles') as $bundle) {
679683
$reflection = new \ReflectionClass($bundle);

‎src/Symfony/Bundle/TwigBundle/TwigEngine.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/TwigEngine.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ public function guessDefaultEscapingStrategy($filename)
5757
if ('js' === $format) {
5858
return 'js';
5959
}
60+
61+
if ('txt' === $format) {
62+
return false;
63+
}
6064

6165
return 'html';
6266
}

‎src/Symfony/Component/Console/Application.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Application.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,8 +515,8 @@ public function findNamespace($namespace)
515515
}
516516

517517
$exact = in_array($namespace, $namespaces, true);
518-
if (1 < count($namespaces) && !$exact) {
519-
throw new \InvalidArgumentException(sprintf('The namespace "%s" is ambiguous (%s).', $namespace, $this->getAbbreviationSuggestions($namespaces)));
518+
if (count($namespaces) > 1 && !$exact) {
519+
throw new \InvalidArgumentException(sprintf('The namespace "%s" is ambiguous (%s).', $namespace, $this->getAbbreviationSuggestions(array_values($namespaces))));
520520
}
521521

522522
return $exact ? $namespace : reset($namespaces);

‎src/Symfony/Component/Console/Tests/ApplicationTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/ApplicationTest.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public static function setUpBeforeClass()
4444
require_once self::$fixturesPath.'/Foo4Command.php';
4545
require_once self::$fixturesPath.'/Foo5Command.php';
4646
require_once self::$fixturesPath.'/FoobarCommand.php';
47+
require_once self::$fixturesPath.'/BarBucCommand.php';
4748
}
4849

4950
protected function normalizeLineBreaks($text)
@@ -207,6 +208,7 @@ public function testFindNamespace()
207208
public function testFindAmbiguousNamespace()
208209
{
209210
$application = new Application();
211+
$application->add(new \BarBucCommand());
210212
$application->add(new \FooCommand());
211213
$application->add(new \Foo2Command());
212214
$application->findNamespace('f');
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
use Symfony\Component\Console\Command\Command;
4+
5+
class BarBucCommand extends Command
6+
{
7+
protected function configure()
8+
{
9+
$this->setName('bar:buc');
10+
}
11+
}

‎src/Symfony/Component/Debug/ErrorHandler.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Debug/ErrorHandler.php
+12-1Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,18 @@ function ($row) {
144144
require __DIR__.'/Exception/ContextErrorException.php';
145145
}
146146

147-
throw new ContextErrorException(sprintf('%s: %s in %s line %d', isset($this->levels[$level]) ? $this->levels[$level] : $level, $message, $file, $line), 0, $level, $file, $line, $context);
147+
$exception = new ContextErrorException(sprintf('%s: %s in %s line %d', isset($this->levels[$level]) ? $this->levels[$level] : $level, $message, $file, $line), 0, $level, $file, $line, $context);
148+
149+
// Exceptions thrown from error handlers are sometimes not caught by the exception
150+
// handler, so we invoke it directly (https://bugs.php.net/bug.php?id=54275)
151+
$exceptionHandler = set_exception_handler(function() {});
152+
restore_exception_handler();
153+
154+
if (is_array($exceptionHandler) && $exceptionHandler[0] instanceof ExceptionHandler) {
155+
$exceptionHandler[0]->handle($exception);
156+
157+
return true;
158+
}
148159
}
149160

150161
return false;

‎src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php
+105-12Lines changed: 105 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,123 @@
2020
*/
2121
class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
2222
{
23+
/**
24+
* @var int Error reporting level before running tests.
25+
*/
26+
protected $errorReporting;
27+
28+
/**
29+
* @var string Display errors setting before running tests.
30+
*/
31+
protected $displayErrors;
32+
33+
public function setUp() {
34+
$this->errorReporting = error_reporting(E_ALL | E_STRICT);
35+
$this->displayErrors = ini_get('display_errors');
36+
ini_set('display_errors', '1');
37+
}
38+
39+
public function tearDown() {
40+
ini_set('display_errors', $this->displayErrors);
41+
error_reporting($this->errorReporting);
42+
}
43+
2344
public function testCompileTimeError()
2445
{
25-
// the ContextErrorException must not be loaded for this test to work
46+
// the ContextErrorException must not be loaded to test the workaround
47+
// for https://bugs.php.net/bug.php?id=65322.
2648
if (class_exists('Symfony\Component\Debug\Exception\ContextErrorException', false)) {
2749
$this->markTestSkipped('The ContextErrorException class is already loaded.');
2850
}
2951

30-
$handler = ErrorHandler::register(E_ALL | E_STRICT);
31-
$displayErrors = ini_get('display_errors');
32-
ini_set('display_errors', '1');
52+
$exceptionHandler = $this->getMock('Symfony\Component\Debug\ExceptionHandler', array('handle'));
3353

34-
try {
35-
// trigger compile time error
36-
eval(<<<'PHP'
54+
// the following code forces some PHPUnit classes to be loaded
55+
// so that they will be available in the exception handler
56+
// as they won't be autoloaded by PHP
57+
class_exists('PHPUnit_Framework_MockObject_Invocation_Object');
58+
$this->assertInstanceOf('stdClass', new \stdClass());
59+
$this->assertEquals(1, 1);
60+
$this->assertStringStartsWith('foo', 'foobar');
61+
$this->assertArrayHasKey('bar', array('bar' => 'foo'));
62+
63+
$that = $this;
64+
$exceptionCheck = function ($exception) use ($that) {
65+
$that->assertInstanceOf('Symfony\Component\Debug\Exception\ContextErrorException', $exception);
66+
$that->assertEquals(E_STRICT, $exception->getSeverity());
67+
$that->assertEquals(2, $exception->getLine());
68+
$that->assertStringStartsWith('Runtime Notice: Declaration of _CompileTimeError::foo() should be compatible with', $exception->getMessage());
69+
$that->assertArrayHasKey('bar', $exception->getContext());
70+
};
71+
72+
$exceptionHandler->expects($this->once())
73+
->method('handle')
74+
->will($this->returnCallback($exceptionCheck))
75+
;
76+
77+
ErrorHandler::register();
78+
set_exception_handler(array($exceptionHandler, 'handle'));
79+
80+
// dummy variable to check for in error handler.
81+
$bar = 123;
82+
83+
// trigger compile time error
84+
eval(<<<'PHP'
3785
class _BaseCompileTimeError { function foo() {} }
3886
class _CompileTimeError extends _BaseCompileTimeError { function foo($invalid) {} }
3987
PHP
40-
);
41-
} catch (\Exception $e) {
42-
// if an exception is thrown, the test passed
43-
}
88+
);
4489

45-
ini_set('display_errors', $displayErrors);
4690
restore_error_handler();
91+
restore_exception_handler();
92+
}
93+
94+
public function testNotice()
95+
{
96+
$exceptionHandler = $this->getMock('Symfony\Component\Debug\ExceptionHandler', array('handle'));
97+
set_exception_handler(array($exceptionHandler, 'handle'));
98+
99+
$that = $this;
100+
$exceptionCheck = function($exception) use ($that) {
101+
$that->assertInstanceOf('Symfony\Component\Debug\Exception\ContextErrorException', $exception);
102+
$that->assertEquals(E_NOTICE, $exception->getSeverity());
103+
$that->assertEquals(__LINE__ + 36, $exception->getLine());
104+
$that->assertEquals(__FILE__, $exception->getFile());
105+
$that->assertRegexp('/^Notice: Undefined variable: (foo|bar)/', $exception->getMessage());
106+
$that->assertArrayHasKey('foobar', $exception->getContext());
107+
108+
$trace = $exception->getTrace();
109+
$that->assertEquals(__FILE__, $trace[0]['file']);
110+
$that->assertEquals('Symfony\Component\Debug\ErrorHandler', $trace[0]['class']);
111+
$that->assertEquals('handle', $trace[0]['function']);
112+
$that->assertEquals('->', $trace[0]['type']);
113+
114+
$that->assertEquals(__FILE__, $trace[1]['file']);
115+
$that->assertEquals(__CLASS__, $trace[1]['class']);
116+
$that->assertEquals('triggerNotice', $trace[1]['function']);
117+
$that->assertEquals('::', $trace[1]['type']);
118+
119+
$that->assertEquals(__CLASS__, $trace[2]['class']);
120+
$that->assertEquals('testNotice', $trace[2]['function']);
121+
$that->assertEquals('->', $trace[2]['type']);
122+
};
123+
124+
$exceptionHandler->expects($this->exactly(3))
125+
->method('handle')
126+
->will($this->returnCallback($exceptionCheck));
127+
ErrorHandler::register();
128+
129+
self::triggerNotice($this);
130+
131+
restore_error_handler();
132+
}
133+
134+
// dummy function to test trace in error handler.
135+
private static function triggerNotice($that)
136+
{
137+
// dummy variable to check for in error handler.
138+
$foobar = 123;
139+
$that->assertSame('', $foo.$foo.$bar);
47140
}
48141

49142
public function testConstruct()

‎src/Symfony/Component/EventDispatcher/Tests/EventTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/EventDispatcher/Tests/EventTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected function setUp()
4646
protected function tearDown()
4747
{
4848
$this->event = null;
49-
$this->eventDispatcher = null;
49+
$this->dispatcher = null;
5050
}
5151

5252
public function testIsPropagationStopped()

‎src/Symfony/Component/ExpressionLanguage/Lexer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/ExpressionLanguage/Lexer.php
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ public function tokenize($expression)
3636
$end = strlen($expression);
3737

3838
while ($cursor < $end) {
39-
while (' ' == $expression[$cursor]) {
39+
if (' ' == $expression[$cursor]) {
4040
++$cursor;
41+
42+
continue;
4143
}
4244

4345
if (preg_match('/[0-9]+(?:\.[0-9]+)?/A', $expression, $match, null, $cursor)) {

‎src/Symfony/Component/ExpressionLanguage/Tests/LexerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/ExpressionLanguage/Tests/LexerTest.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ public function testTokenize($tokens, $expression)
3030
public function getTokenizeData()
3131
{
3232
return array(
33+
array(
34+
array(new Token('name', 'a', 3)),
35+
' a ',
36+
),
3337
array(
3438
array(new Token('name', 'a', 1)),
3539
'a',

‎src/Symfony/Component/Form/Extension/Core/Type/DateType.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/Type/DateType.php
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,9 @@ private function listYears(array $years)
279279
$result = array();
280280

281281
foreach ($years as $year) {
282-
$result[$year] = gmmktime(0, 0, 0, 6, 15, $year);
282+
if (false !== $y = gmmktime(0, 0, 0, 6, 15, $year)) {
283+
$result[$year] = $y;
284+
}
283285
}
284286

285287
return $result;

‎src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,4 +778,25 @@ public function testDayErrorsBubbleUp($widget)
778778
$this->assertSame(array(), $form['day']->getErrors());
779779
$this->assertSame(array($error), $form->getErrors());
780780
}
781+
782+
public function testYearsFor32BitsMachines()
783+
{
784+
if (4 !== PHP_INT_SIZE) {
785+
$this->markTestSkipped(
786+
'PHP must be compiled in 32 bit mode to run this test');
787+
}
788+
789+
$form = $this->factory->create('date', null, array(
790+
'years' => range(1900, 2040),
791+
));
792+
793+
$view = $form->createView();
794+
795+
$listChoices = array();
796+
foreach(range(1902, 2037) as $y) {
797+
$listChoices[] = new ChoiceView($y, $y, $y);
798+
}
799+
800+
$this->assertEquals($listChoices, $view['year']->vars['choices']);
801+
}
781802
}

‎src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public function start()
163163
*/
164164
public function getId()
165165
{
166-
if (!$this->started) {
166+
if (!$this->started && !$this->closed) {
167167
return ''; // returning empty is consistent with session_id() behaviour
168168
}
169169

‎src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,12 @@ public function testGetId()
8585
{
8686
$storage = $this->getStorage();
8787
$this->assertEquals('', $storage->getId());
88+
8889
$storage->start();
8990
$this->assertNotEquals('', $storage->getId());
91+
92+
$storage->save();
93+
$this->assertNotEquals('', $storage->getId());
9094
}
9195

9296
public function testRegenerate()

‎src/Symfony/Component/HttpKernel/EventListener/ProfilerListener.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/EventListener/ProfilerListener.php
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ public function onKernelTerminate(PostResponseEvent $event)
125125
{
126126
// attach children to parents
127127
foreach ($this->profiles as $request) {
128-
if ($parentRequest = $this->parents[$request]) {
128+
// isset call should be removed when requestStack is required
129+
if (isset($this->parents[$request]) && null !== $parentRequest = $this->parents[$request]) {
129130
$this->profiles[$parentRequest]->addChild($this->profiles[$request]);
130131
}
131132
}
+55Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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\HttpKernel\Tests\EventListener;
13+
14+
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
15+
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
16+
use Symfony\Component\HttpKernel\EventListener\ProfilerListener;
17+
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
18+
use Symfony\Component\HttpKernel\Kernel;
19+
20+
class ProfilerListenerTest extends \PHPUnit_Framework_TestCase
21+
{
22+
/**
23+
* Test to ensure BC without RequestStack
24+
*
25+
* @deprecated Deprecated since version 2.4, to be removed in 3.0.
26+
*/
27+
public function testEventsWithoutRequestStack()
28+
{
29+
$profile = $this->getMockBuilder('Symfony\Component\HttpKernel\Profiler\Profile')
30+
->disableOriginalConstructor()
31+
->getMock();
32+
33+
$profiler = $this->getMockBuilder('Symfony\Component\HttpKernel\Profiler\Profiler')
34+
->disableOriginalConstructor()
35+
->getMock();
36+
$profiler->expects($this->once())
37+
->method('collect')
38+
->will($this->returnValue($profile));
39+
40+
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
41+
42+
$request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')
43+
->disableOriginalConstructor()
44+
->getMock();
45+
46+
$response = $this->getMockBuilder('Symfony\Component\HttpFoundation\Response')
47+
->disableOriginalConstructor()
48+
->getMock();
49+
50+
$listener = new ProfilerListener($profiler);
51+
$listener->onKernelRequest(new GetResponseEvent($kernel, $request, Kernel::MASTER_REQUEST));
52+
$listener->onKernelResponse(new FilterResponseEvent($kernel, $request, Kernel::MASTER_REQUEST, $response));
53+
$listener->onKernelTerminate(new PostResponseEvent($kernel, $request, $response));
54+
}
55+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.