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 1a33e1b

Browse filesBrowse files
committed
Merge branch '2.3' into 2.4
* 2.3: [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 Fixes #9633, Removed dependency to Symfony\Bundle\FrameworkBundle\Tests\TestCase [Validator] Replaced inexistent interface. When getting the session's id, check if the session is not closed Adjusting CacheClear Warmup method to namespaced kernels Conflicts: src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php
2 parents 2d31a0a + ad9008e commit 1a33e1b
Copy full SHA for 1a33e1b

File tree

Expand file treeCollapse file tree

13 files changed

+209
-26
lines changed
Filter options
Expand file treeCollapse file tree

13 files changed

+209
-26
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/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/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/Translation/Tests/Catalogue/AbstractOperationTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/Tests/Catalogue/AbstractOperationTest.php
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
1111

1212
namespace Symfony\Component\Translation\Test\Catalogue;
1313

14-
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
1514
use Symfony\Component\Translation\MessageCatalogue;
1615
use Symfony\Component\Translation\MessageCatalogueInterface;
1716

18-
abstract class AbstractOperationTest extends TestCase
17+
abstract class AbstractOperationTest extends \PHPUnit_Framework_TestCase
1918
{
2019
public function testGetEmptyDomains()
2120
{

‎src/Symfony/Component/Validator/Mapping/BlackholeMetadataFactory.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Mapping/BlackholeMetadataFactory.php
+16-3Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,28 @@
1111

1212
namespace Symfony\Component\Validator\Mapping;
1313

14+
use Symfony\Component\Validator\MetadataFactoryInterface;
15+
1416
/**
15-
* Simple implementation of ClassMetadataFactoryInterface that can be used when using ValidatorInterface::validateValue().
17+
* Simple implementation of MetadataFactoryInterface that can be used when using ValidatorInterface::validateValue().
1618
*
1719
* @author Fabien Potencier <fabien@symfony.com>
1820
*/
19-
class BlackholeMetadataFactory implements ClassMetadataFactoryInterface
21+
class BlackholeMetadataFactory implements MetadataFactoryInterface
2022
{
21-
public function getClassMetadata($class)
23+
/**
24+
* @inheritdoc
25+
*/
26+
public function getMetadataFor($value)
2227
{
2328
throw new \LogicException('BlackholeClassMetadataFactory only works with ValidatorInterface::validateValue().');
2429
}
30+
31+
/**
32+
* @inheritdoc
33+
*/
34+
public function hasMetadataFor($value)
35+
{
36+
return false;
37+
}
2538
}
+33Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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\Validator\Tests\Mapping;
13+
14+
use Symfony\Component\Validator\Mapping\BlackholeMetadataFactory;
15+
16+
class BlackholeMetadataFactoryTest extends \PHPUnit_Framework_TestCase
17+
{
18+
/**
19+
* @expectedException \LogicException
20+
*/
21+
public function testGetMetadataForThrowsALogicException()
22+
{
23+
$metadataFactory = new BlackholeMetadataFactory();
24+
$metadataFactory->getMetadataFor('foo');
25+
}
26+
27+
public function testHasMetadataForReturnsFalse()
28+
{
29+
$metadataFactory = new BlackholeMetadataFactory();
30+
31+
$this->assertFalse($metadataFactory->hasMetadataFor('foo'));
32+
}
33+
}

0 commit comments

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