8000 Merge branch '2.3' into 2.7 · symfony/symfony@86c0a17 · GitHub
[go: up one dir, main page]

Skip to content

Commit 86c0a17

Browse files
Merge branch '2.3' into 2.7
* 2.3: [Validator] use correct term for a property in docblock (not "option") [PropertyAccess] Remove most ref mismatches to improve perf [Validator] EmailValidator cannot extract hostname if email contains multiple @ symbols [NumberFormatter] Fix invalid numeric literal on PHP 7 Use XML_ELEMENT_NODE in nodeType check [PropertyAccess] Reduce overhead of UnexpectedTypeException tracking [PropertyAccess] Throw an UnexpectedTypeException when the type do not match [FrameworkBundle] Add tests for the Controller class Conflicts: src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerTest.php src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php src/Symfony/Component/PropertyAccess/PropertyAccessor.php src/Symfony/Component/PropertyAccess/PropertyAccessorInterface.php src/Symfony/Component/PropertyAccess/PropertyPath.php src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php src/Symfony/Component/Validator/Constraints/EmailValidator.php
2 parents 46e8229 + d01a106 commit 86c0a17

File tree

11 files changed

+435
-228
lines changed

11 files changed

+435
-228
lines changed

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

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,4 +209,122 @@ public function isCsrfTokenValid($id, $token)
209209
{
210210
return parent::isCsrfTokenValid($id, $token);
211211
}
212+
213+
public function testGenerateUrl()
214+
{
215+
$router = $this->getMock('Symfony\Component\Routing\RouterInterface');
216+
$router->expects($this->once())->method('generate')->willReturn('/foo');
217+
218+
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
219+
$container->expects($this->at(0))->method('get')->will($this->returnValue($router));
220+
221+
$controller = new Controller();
222+
$controller->setContainer($container);
223+
224+
$this->assertEquals('/foo', $controller->generateUrl('foo'));
225+
}
226+
227+
public function testRedirect()
228+
{
229+
$controller = new Controller();
230+
$response = $controller->redirect('http://dunglas.fr', 301);
231+
232+
$this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response);
233+
$this->assertSame('http://dunglas.fr', $response->getTargetUrl());
234+
$this->assertSame(301, $response->getStatusCode());
235+
}
236+
237+
public function testRenderViewTemplating()
238+
{
239+
$templating = $this->getMock('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface');
240+
$templating->expects($this->once())->method('render')->willReturn('bar');
241+
242+
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
243+
$container->expects($this->at(0))->method('get')->will($this->returnValue($templating));
244+
245+
$controller = new Controller();
246+
$controller->setContainer($container);
247+
248+
$this->assertEquals('bar', $controller->renderView('foo'));
249+
}
250+
251+
public function testRenderTemplating()
252+
{
253+
$templating = $this->getMock('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface');
254+
$templating->expects($this->once())->method('renderResponse')->willReturn(new Response('bar'));
255+
256+
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
257+
$container->expects($this->at(0))->method('get')->will($this->returnValue($templating));
258+
259+
$controller = new Controller();
260+
$controller->setContainer($container);
261+
262+
$this->assertEquals('bar', $controller->render('foo')->getContent());
263+
}
264+
265+
public function testStreamTemplating()
266+
{
267+
$templating = $this->getMock('Symfony\Component\Routing\RouterInterface');
268+
269+
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
270+
$container->expects($this->at(0))->method('get')->will($this->returnValue($templating));
271+
272+
$controller = new Controller();
273+
$controller->setContainer($container);
274+
275+
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $controller->stream('foo'));
276+
}
277+
278+
public function testCreateNotFoundException()
279+
{
280+
$controller = new Controller();
281+
282+
$this->assertInstanceOf('Symfony\Component\HttpKernel\Exception\NotFoundHttpException', $controller->createNotFoundException());
283+
}
284+
285+
public function testCreateForm()
286+
{
287+
$form = $this->getMock('Symfony\Component\Form\FormInterface');
288+
289+
$formFactory = $this->getMock('Symfony\Component\Form\FormFactoryInterface');
290+
$formFactory->expects($this->once())->method('create')->willReturn($form);
291+
292+
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
293+
$container->expects($this->at(0))->method('get')->will($this->returnValue($formFactory));
294+
295+
$controller = new Controller();
296+
$controller->setContainer($container);
297+
298+
$this->assertEquals($form, $controller->createForm('foo'));
299+
}
300+
301+
public function testCreateFormBuilder()
302+
{
303+
$formBuilder = $this->getMock('Symfony\Component\Form\FormBuilderInterface');
304+
305+
$formFactory = $this->getMock('Symfony\Component\Form\FormFactoryInterface');
306+
$formFactory->expects($this->once())->method('createBuilder')->willReturn($formBuilder);
307+
308+
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
309+
$container->expects($this->at(0))->method('get')->will($this->returnValue($formFactory));
310+
311+
$controller = new Controller();
312+
$controller->setContainer($container);
313+
314+
$this->assertEquals($formBuilder, $controller->createFormBuilder('foo'));
315+
}
316+
317+
public function testGetDoctrine()
318+
{
319+
$doctrine = $this->getMock('Doctrine\Common\Persistence\ManagerRegistry');
320+
321+
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
322+
$container->expects($this->at(0))->method('has')->will($this->returnValue(true));
323+
$container->expects($this->at(1))->method('get')->will($this->returnValue($doctrine));
324+
325+
$controller = new Controller();
326+
$controller->setContainer($container);
327+
328+
$this->assertEquals($doctrine, $controller->getDoctrine());
329+
}
212330
}

src/Symfony/Component/DomCrawler/Crawler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ public function parents()
482482
$nodes = array();
483483

484484
while ($node = $node->parentNode) {
485-
if (1 === $node->nodeType) {
485+
if (XML_ELEMENT_NODE === $node->nodeType) {
486486
$nodes[] = $node;
487487
}
488488
}

src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -231,24 +231,18 @@ class NumberFormatter
231231
);
232232

233233
/**
234-
* The maximum values of the integer type in 32 bit platforms.
234+
* The maximum value of the integer type in 32 bit platforms.
235235
*
236-
* @var array
236+
* @var int
237237
*/
238-
private static $int32Range = array(
239-
'positive' => 2147483647,
240-
'negative' => -2147483648,
241-
);
238+
private static $int32Max = 2147483647;
242239

243240
/**
244-
* The maximum values of the integer type in 64 bit platforms.
241+
* The maximum value of the integer type in 64 bit platforms.
245242
*
246-
* @var array
243+
* @var int|float
247244
*/
248-
private static $int64Range = array(
249-
'positive' => 9223372036854775807,
250-
'negative' => -9223372036854775808,
251-
);
245+
private static $int64Max = 9223372036854775807;
252246

253247
private static $enSymbols = array(
254248
self::DECIMAL => array('.', ',', ';', '%', '0', '#', '-', '+', '¤', '¤¤', '.', 'E', '', '*', '', 'NaN', '@', ','),
@@ -526,7 +520,7 @@ public function parseCurrency($value, &$currency, &$position = null)
526520
* @param int $type Type of the formatting, one of the format type constants. NumberFormatter::TYPE_DOUBLE by default
527521
* @param int $position Offset to begin the parsing on return this value will hold the offset at which the parsing ended
528522
*
529-
* @return bool|string The parsed value of false on error
523+
* @return int|float|false The parsed value of false on error
530524
*
531525
* @see http://www.php.net/manual/en/numberformatter.parse.php
532526
*/
@@ -835,7 +829,7 @@ private function convertValueDataType($value, $type)
835829
*/
836830
private function getInt32Value($value)
837831
{
838-
if ($value > self::$int32Range['positive'] || $value < self::$int32Range['negative']) {
832+
if ($value > self::$int32Max || $value < -self::$int32Max - 1) {
839833
return false;
840834
}
841835

@@ -848,20 +842,18 @@ private function getInt32Value($value)
848842
* @param mixed $value The value to be converted
849843
*
850844
* @return int|float|false The converted value
851-
*
852-
* @see https://bugs.php.net/bug.php?id=59597 Bug #59597
853845
*/
854846
private function getInt64Value($value)
855847
{
856-
if ($value > self::$int64Range['positive'] || $value < self::$int64Range['negative']) {
848+
if ($value > self::$int64Max || $value < -self::$int64Max - 1) {
857849
return false;
858850
}
859851

860-
if (PHP_INT_SIZE !== 8 && ($value > self::$int32Range['positive'] || $value <= self::$int32Range['negative'])) {
852+
if (PHP_INT_SIZE !== 8 && ($value > self::$int32Max || $value <= -self::$int32Max - 1)) {
861853
// Bug #59597 was fixed on PHP 5.3.14 and 5.4.4
862854
// The negative PHP_INT_MAX was being converted to float
863855
if (
864-
$value == self::$int32Range['negative'] &&
856+
$value == -self::$int32Max - 1 &&
865857
((PHP_VERSION_ID < 50400 && PHP_VERSION_ID >= 50314) || PHP_VERSION_ID >= 50404 || (extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone')))
866858
) {
867859
return (int) $value;
@@ -874,7 +866,7 @@ private function getInt64Value($value)
874866
// Bug #59597 was fixed on PHP 5.3.14 and 5.4.4
875867
// A 32 bit integer was being generated instead of a 64 bit integer
876868
if (
877-
($value > self::$int32Range['positive'] || $value < self::$int32Range['negative']) &&
869+
($value > self::$int32Max || $value < -self::$int32Max - 1) &&
878870
(PHP_VERSION_ID < 50314 || (PHP_VERSION_ID >= 50400 && PHP_VERSION_ID < 50404)) &&
879871
!(extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))
880872
) {

0 commit comments

Comments
 (0)
0