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
This commit is contained in:
commit
db4f551527
@ -120,7 +120,6 @@ EOF
|
||||
$warmer->warmUp($warmupDir);
|
||||
|
||||
// fix references to the Kernel in .meta files
|
||||
|
||||
$safeTempKernel = str_replace('\\', '\\\\', get_class($tempKernel));
|
||||
$realKernelFQN = get_class($realKernel);
|
||||
|
||||
|
@ -671,9 +671,13 @@ class FrameworkExtension extends Extension
|
||||
|
||||
private function getValidatorXmlMappingFiles(ContainerBuilder $container)
|
||||
{
|
||||
$files = array();
|
||||
|
||||
if (interface_exists('Symfony\Component\Form\FormInterface')) {
|
||||
$reflClass = new \ReflectionClass('Symfony\Component\Form\FormInterface');
|
||||
$files = array(dirname($reflClass->getFileName()).'/Resources/config/validation.xml');
|
||||
$files[] = dirname($reflClass->getFileName()).'/Resources/config/validation.xml';
|
||||
$container->addResource(new FileResource($files[0]));
|
||||
}
|
||||
|
||||
foreach ($container->getParameter('kernel.bundles') as $bundle) {
|
||||
$reflection = new \ReflectionClass($bundle);
|
||||
|
@ -58,6 +58,10 @@ class TwigEngine extends BaseEngine implements EngineInterface
|
||||
return 'js';
|
||||
}
|
||||
|
||||
if ('txt' === $format) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return 'html';
|
||||
}
|
||||
|
||||
|
@ -515,8 +515,8 @@ class Application
|
||||
}
|
||||
|
||||
$exact = in_array($namespace, $namespaces, true);
|
||||
if (1 < count($namespaces) && !$exact) {
|
||||
throw new \InvalidArgumentException(sprintf('The namespace "%s" is ambiguous (%s).', $namespace, $this->getAbbreviationSuggestions($namespaces)));
|
||||
if (count($namespaces) > 1 && !$exact) {
|
||||
throw new \InvalidArgumentException(sprintf('The namespace "%s" is ambiguous (%s).', $namespace, $this->getAbbreviationSuggestions(array_values($namespaces))));
|
||||
}
|
||||
|
||||
return $exact ? $namespace : reset($namespaces);
|
||||
|
@ -44,6 +44,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
|
||||
require_once self::$fixturesPath.'/Foo4Command.php';
|
||||
require_once self::$fixturesPath.'/Foo5Command.php';
|
||||
require_once self::$fixturesPath.'/FoobarCommand.php';
|
||||
require_once self::$fixturesPath.'/BarBucCommand.php';
|
||||
}
|
||||
|
||||
protected function normalizeLineBreaks($text)
|
||||
@ -207,6 +208,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
|
||||
public function testFindAmbiguousNamespace()
|
||||
{
|
||||
$application = new Application();
|
||||
$application->add(new \BarBucCommand());
|
||||
$application->add(new \FooCommand());
|
||||
$application->add(new \Foo2Command());
|
||||
$application->findNamespace('f');
|
||||
|
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
||||
class BarBucCommand extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('bar:buc');
|
||||
}
|
||||
}
|
@ -144,7 +144,18 @@ class ErrorHandler
|
||||
require __DIR__.'/Exception/ContextErrorException.php';
|
||||
}
|
||||
|
||||
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);
|
||||
$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);
|
||||
|
||||
// Exceptions thrown from error handlers are sometimes not caught by the exception
|
||||
// handler, so we invoke it directly (https://bugs.php.net/bug.php?id=54275)
|
||||
$exceptionHandler = set_exception_handler(function() {});
|
||||
restore_exception_handler();
|
||||
|
||||
if (is_array($exceptionHandler) && $exceptionHandler[0] instanceof ExceptionHandler) {
|
||||
$exceptionHandler[0]->handle($exception);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -20,32 +20,125 @@ use Symfony\Component\Debug\ErrorHandler;
|
||||
*/
|
||||
class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var int Error reporting level before running tests.
|
||||
*/
|
||||
protected $errorReporting;
|
||||
|
||||
/**
|
||||
* @var string Display errors setting before running tests.
|
||||
*/
|
||||
protected $displayErrors;
|
||||
|
||||
public function setUp() {
|
||||
$this->errorReporting = error_reporting(E_ALL | E_STRICT);
|
||||
$this->displayErrors = ini_get('display_errors');
|
||||
ini_set('display_errors', '1');
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
ini_set('display_errors', $this->displayErrors);
|
||||
error_reporting($this->errorReporting);
|
||||
}
|
||||
|
||||
public function testCompileTimeError()
|
||||
{
|
||||
// the ContextErrorException must not be loaded for this test to work
|
||||
// the ContextErrorException must not be loaded to test the workaround
|
||||
// for https://bugs.php.net/bug.php?id=65322.
|
||||
if (class_exists('Symfony\Component\Debug\Exception\ContextErrorException', false)) {
|
||||
$this->markTestSkipped('The ContextErrorException class is already loaded.');
|
||||
}
|
||||
|
||||
$handler = ErrorHandler::register(E_ALL | E_STRICT);
|
||||
$displayErrors = ini_get('display_errors');
|
||||
ini_set('display_errors', '1');
|
||||
$exceptionHandler = $this->getMock('Symfony\Component\Debug\ExceptionHandler', array('handle'));
|
||||
|
||||
// the following code forces some PHPUnit classes to be loaded
|
||||
// so that they will be available in the exception handler
|
||||
// as they won't be autoloaded by PHP
|
||||
class_exists('PHPUnit_Framework_MockObject_Invocation_Object');
|
||||
$this->assertInstanceOf('stdClass', new \stdClass());
|
||||
$this->assertEquals(1, 1);
|
||||
$this->assertStringStartsWith('foo', 'foobar');
|
||||
$this->assertArrayHasKey('bar', array('bar' => 'foo'));
|
||||
|
||||
$that = $this;
|
||||
$exceptionCheck = function ($exception) use ($that) {
|
||||
$that->assertInstanceOf('Symfony\Component\Debug\Exception\ContextErrorException', $exception);
|
||||
$that->assertEquals(E_STRICT, $exception->getSeverity());
|
||||
$that->assertEquals(2, $exception->getLine());
|
||||
$that->assertStringStartsWith('Runtime Notice: Declaration of _CompileTimeError::foo() should be compatible with', $exception->getMessage());
|
||||
$that->assertArrayHasKey('bar', $exception->getContext());
|
||||
};
|
||||
|
||||
$exceptionHandler->expects($this->once())
|
||||
->method('handle')
|
||||
->will($this->returnCallback($exceptionCheck))
|
||||
;
|
||||
|
||||
ErrorHandler::register();
|
||||
set_exception_handler(array($exceptionHandler, 'handle'));
|
||||
|
||||
// dummy variable to check for in error handler.
|
||||
$bar = 123;
|
||||
|
||||
try {
|
||||
// trigger compile time error
|
||||
eval(<<<'PHP'
|
||||
class _BaseCompileTimeError { function foo() {} }
|
||||
class _CompileTimeError extends _BaseCompileTimeError { function foo($invalid) {} }
|
||||
PHP
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
// if an exception is thrown, the test passed
|
||||
|
||||
restore_error_handler();
|
||||
restore_exception_handler();
|
||||
}
|
||||
|
||||
ini_set('display_errors', $displayErrors);
|
||||
public function testNotice()
|
||||
{
|
||||
$exceptionHandler = $this->getMock('Symfony\Component\Debug\ExceptionHandler', array('handle'));
|
||||
set_exception_handler(array($exceptionHandler, 'handle'));
|
||||
|
||||
$that = $this;
|
||||
$exceptionCheck = function($exception) use ($that) {
|
||||
$that->assertInstanceOf('Symfony\Component\Debug\Exception\ContextErrorException', $exception);
|
||||
$that->assertEquals(E_NOTICE, $exception->getSeverity());
|
||||
$that->assertEquals(__LINE__ + 36, $exception->getLine());
|
||||
$that->assertEquals(__FILE__, $exception->getFile());
|
||||
$that->assertRegexp('/^Notice: Undefined variable: (foo|bar)/', $exception->getMessage());
|
||||
$that->assertArrayHasKey('foobar', $exception->getContext());
|
||||
|
||||
$trace = $exception->getTrace();
|
||||
$that->assertEquals(__FILE__, $trace[0]['file']);
|
||||
$that->assertEquals('Symfony\Component\Debug\ErrorHandler', $trace[0]['class']);
|
||||
$that->assertEquals('handle', $trace[0]['function']);
|
||||
$that->assertEquals('->', $trace[0]['type']);
|
||||
|
||||
$that->assertEquals(__FILE__, $trace[1]['file']);
|
||||
$that->assertEquals(__CLASS__, $trace[1]['class']);
|
||||
$that->assertEquals('triggerNotice', $trace[1]['function']);
|
||||
$that->assertEquals('::', $trace[1]['type']);
|
||||
|
||||
$that->assertEquals(__CLASS__, $trace[2]['class']);
|
||||
$that->assertEquals('testNotice', $trace[2]['function']);
|
||||
$that->assertEquals('->', $trace[2]['type']);
|
||||
};
|
||||
|
||||
$exceptionHandler->expects($this->exactly(3))
|
||||
->method('handle')
|
||||
->will($this->returnCallback($exceptionCheck));
|
||||
ErrorHandler::register();
|
||||
|
||||
self::triggerNotice($this);
|
||||
|
||||
restore_error_handler();
|
||||
}
|
||||
|
||||
// dummy function to test trace in error handler.
|
||||
private static function triggerNotice($that)
|
||||
{
|
||||
// dummy variable to check for in error handler.
|
||||
$foobar = 123;
|
||||
$that->assertSame('', $foo.$foo.$bar);
|
||||
}
|
||||
|
||||
public function testConstruct()
|
||||
{
|
||||
$handler = ErrorHandler::register(3);
|
||||
|
@ -46,7 +46,7 @@ class EventTest extends \PHPUnit_Framework_TestCase
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->event = null;
|
||||
$this->eventDispatcher = null;
|
||||
$this->dispatcher = null;
|
||||
}
|
||||
|
||||
public function testIsPropagationStopped()
|
||||
|
@ -36,8 +36,10 @@ class Lexer
|
||||
$end = strlen($expression);
|
||||
|
||||
while ($cursor < $end) {
|
||||
while (' ' == $expression[$cursor]) {
|
||||
if (' ' == $expression[$cursor]) {
|
||||
++$cursor;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (preg_match('/[0-9]+(?:\.[0-9]+)?/A', $expression, $match, null, $cursor)) {
|
||||
|
@ -30,6 +30,10 @@ class LexerTest extends \PHPUnit_Framework_TestCase
|
||||
public function getTokenizeData()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array(new Token('name', 'a', 3)),
|
||||
' a ',
|
||||
),
|
||||
array(
|
||||
array(new Token('name', 'a', 1)),
|
||||
'a',
|
||||
|
@ -279,7 +279,9 @@ class DateType extends AbstractType
|
||||
$result = array();
|
||||
|
||||
foreach ($years as $year) {
|
||||
$result[$year] = gmmktime(0, 0, 0, 6, 15, $year);
|
||||
if (false !== $y = gmmktime(0, 0, 0, 6, 15, $year)) {
|
||||
$result[$year] = $y;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
@ -778,4 +778,25 @@ class DateTypeTest extends TypeTestCase
|
||||
$this->assertSame(array(), $form['day']->getErrors());
|
||||
$this->assertSame(array($error), $form->getErrors());
|
||||
}
|
||||
|
||||
public function testYearsFor32BitsMachines()
|
||||
{
|
||||
if (4 !== PHP_INT_SIZE) {
|
||||
$this->markTestSkipped(
|
||||
'PHP must be compiled in 32 bit mode to run this test');
|
||||
}
|
||||
|
||||
$form = $this->factory->create('date', null, array(
|
||||
'years' => range(1900, 2040),
|
||||
));
|
||||
|
||||
$view = $form->createView();
|
||||
|
||||
$listChoices = array();
|
||||
foreach(range(1902, 2037) as $y) {
|
||||
$listChoices[] = new ChoiceView($y, $y, $y);
|
||||
}
|
||||
|
||||
$this->assertEquals($listChoices, $view['year']->vars['choices']);
|
||||
}
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ class NativeSessionStorage implements SessionStorageInterface
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
if (!$this->started) {
|
||||
if (!$this->started && !$this->closed) {
|
||||
return ''; // returning empty is consistent with session_id() behaviour
|
||||
}
|
||||
|
||||
|
@ -85,8 +85,12 @@ class NativeSessionStorageTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$storage = $this->getStorage();
|
||||
$this->assertEquals('', $storage->getId());
|
||||
|
||||
$storage->start();
|
||||
$this->assertNotEquals('', $storage->getId());
|
||||
|
||||
$storage->save();
|
||||
$this->assertNotEquals('', $storage->getId());
|
||||
}
|
||||
|
||||
public function testRegenerate()
|
||||
|
@ -125,7 +125,8 @@ class ProfilerListener implements EventSubscriberInterface
|
||||
{
|
||||
// attach children to parents
|
||||
foreach ($this->profiles as $request) {
|
||||
if ($parentRequest = $this->parents[$request]) {
|
||||
// isset call should be removed when requestStack is required
|
||||
if (isset($this->parents[$request]) && null !== $parentRequest = $this->parents[$request]) {
|
||||
$this->profiles[$parentRequest]->addChild($this->profiles[$request]);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\EventListener;
|
||||
|
||||
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
|
||||
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
|
||||
use Symfony\Component\HttpKernel\EventListener\ProfilerListener;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
||||
use Symfony\Component\HttpKernel\Kernel;
|
||||
|
||||
class ProfilerListenerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Test to ensure BC without RequestStack
|
||||
*
|
||||
* @deprecated Deprecated since version 2.4, to be removed in 3.0.
|
||||
*/
|
||||
public function testEventsWithoutRequestStack()
|
||||
{
|
||||
$profile = $this->getMockBuilder('Symfony\Component\HttpKernel\Profiler\Profile')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$profiler = $this->getMockBuilder('Symfony\Component\HttpKernel\Profiler\Profiler')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$profiler->expects($this->once())
|
||||
->method('collect')
|
||||
->will($this->returnValue($profile));
|
||||
|
||||
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
|
||||
|
||||
$request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$response = $this->getMockBuilder('Symfony\Component\HttpFoundation\Response')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$listener = new ProfilerListener($profiler);
|
||||
$listener->onKernelRequest(new GetResponseEvent($kernel, $request, Kernel::MASTER_REQUEST));
|
||||
$listener->onKernelResponse(new FilterResponseEvent($kernel, $request, Kernel::MASTER_REQUEST, $response));
|
||||
$listener->onKernelTerminate(new PostResponseEvent($kernel, $request, $response));
|
||||
}
|
||||
}
|
@ -11,11 +11,10 @@
|
||||
|
||||
namespace Symfony\Component\Translation\Test\Catalogue;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
|
||||
use Symfony\Component\Translation\MessageCatalogue;
|
||||
use Symfony\Component\Translation\MessageCatalogueInterface;
|
||||
|
||||
abstract class AbstractOperationTest extends TestCase
|
||||
abstract class AbstractOperationTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testGetEmptyDomains()
|
||||
{
|
||||
|
@ -11,15 +11,28 @@
|
||||
|
||||
namespace Symfony\Component\Validator\Mapping;
|
||||
|
||||
use Symfony\Component\Validator\MetadataFactoryInterface;
|
||||
|
||||
/**
|
||||
* Simple implementation of ClassMetadataFactoryInterface that can be used when using ValidatorInterface::validateValue().
|
||||
* Simple implementation of MetadataFactoryInterface that can be used when using ValidatorInterface::validateValue().
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class BlackholeMetadataFactory implements ClassMetadataFactoryInterface
|
||||
class BlackholeMetadataFactory implements MetadataFactoryInterface
|
||||
{
|
||||
public function getClassMetadata($class)
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getMetadataFor($value)
|
||||
{
|
||||
throw new \LogicException('BlackholeClassMetadataFactory only works with ValidatorInterface::validateValue().');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function hasMetadataFor($value)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Tests\Mapping;
|
||||
|
||||
use Symfony\Component\Validator\Mapping\BlackholeMetadataFactory;
|
||||
|
||||
class BlackholeMetadataFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException \LogicException
|
||||
*/
|
||||
public function testGetMetadataForThrowsALogicException()
|
||||
{
|
||||
$metadataFactory = new BlackholeMetadataFactory();
|
||||
$metadataFactory->getMetadataFor('foo');
|
||||
}
|
||||
|
||||
public function testHasMetadataForReturnsFalse()
|
||||
{
|
||||
$metadataFactory = new BlackholeMetadataFactory();
|
||||
|
||||
$this->assertFalse($metadataFactory->hasMetadataFor('foo'));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user