Merge branch '2.3' into 2.7

* 2.3:
  Static code analysis
  Update AnnotationDirectoryLoader.php
  [FrameworkBundle] Fix template location for PHP templates
  [FrameworkBundle] Add path verification to the template parsing test cases
This commit is contained in:
Fabien Potencier 2016-01-27 06:09:39 +01:00
commit 1876b4f1c8
32 changed files with 78 additions and 70 deletions

View File

@ -153,7 +153,7 @@ abstract class AbstractDoctrineExtension extends Extension
*/
protected function getMappingDriverBundleConfigDefaults(array $bundleConfig, \ReflectionClass $bundle, ContainerBuilder $container)
{
$bundleDir = dirname($bundle->getFilename());
$bundleDir = dirname($bundle->getFileName());
if (!$bundleConfig['type']) {
$bundleConfig['type'] = $this->detectMetadataDriver($bundleDir, $container);

View File

@ -60,7 +60,7 @@ class DoctrineValidationPass implements CompilerPassInterface
foreach ($container->getParameter('kernel.bundles') as $bundle) {
$reflection = new \ReflectionClass($bundle);
if (is_file($file = dirname($reflection->getFilename()).'/'.$validationPath)) {
if (is_file($file = dirname($reflection->getFileName()).'/'.$validationPath)) {
$files[] = realpath($file);
$container->addResource(new FileResource($file));
}

View File

@ -117,7 +117,7 @@ build: 56
background: transparent url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAcAAAAcCAYAAACtQ6WLAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAR1JREFUeNpiPHnyZCMDA8MNID5gZmb2nAEJMH7//v3N169fX969e/cYkL8WqGAHXPLv37//QYzfv39/fvPmzbUnT56sAXInmJub/2H5/x8sx8DCwsIrISFhDmQyPX78+CmQXs70798/BmQsKipqBNTgdvz4cWkmkE5kDATMioqKZkCFdiwg1eiAi4tLGqhQF24nMmBmZuYEigth1QkEbEBxTlySYPvJkwSJ00AnjYylgU6gxB8g/oFVEphkvgLF32KNMmCCewYUv4qhEyj47+HDhyeBzIMYOoEp8CxQw56wsLAncJ1//vz5/P79+2svX74EJc2V4BT58+fPd8CE/QKYHMGJOiIiAp6oWW7evDkNSF8DZYfIyEiU7AAQYACJ2vxVdJW4eQAAAABJRU5ErkJggg==) right top no-repeat;
}
.sf-button .btn-bg {
padding: 0px 14px;
padding: 0 14px;
color: #636363;
line-height: 28px;
background: transparent url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAcCAYAAACgXdXMAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAClJREFUeNpiPnny5EKGf//+/Wf6//8/A4QAcrGzKCZwGc9sa2urBBBgAIbDUoYVp9lmAAAAAElFTkSuQmCC) repeat-x top left;

View File

@ -55,7 +55,7 @@ class TemplateNameParser extends BaseTemplateNameParser
throw new \RuntimeException(sprintf('Template name "%s" contains invalid characters.', $name));
}
if (!preg_match('/^([^:]*):([^:]*):(.+)\.([^\.]+)\.([^\.]+)$/', $name, $matches)) {
if (!preg_match('/^(?:([^:]*):)?(?:([^:]*):)?(.+)\.([^\.]+)\.([^\.]+)$/', $name, $matches)) {
return parent::parse($name);
}

View File

@ -43,30 +43,33 @@ class TemplateNameParserTest extends TestCase
}
/**
* @dataProvider getLogicalNameToTemplateProvider
* @dataProvider parseProvider
*/
public function testParse($name, $ref)
public function testParse($name, $logicalName, $path, $ref)
{
$template = $this->parser->parse($name);
$this->assertEquals($template->getLogicalName(), $ref->getLogicalName());
$this->assertEquals($template->getLogicalName(), $name);
$this->assertSame($ref->getLogicalName(), $template->getLogicalName());
$this->assertSame($logicalName, $template->getLogicalName());
$this->assertSame($path, $template->getPath());
}
public function getLogicalNameToTemplateProvider()
public function parseProvider()
{
return array(
array('FooBundle:Post:index.html.php', new TemplateReference('FooBundle', 'Post', 'index', 'html', 'php')),
array('FooBundle:Post:index.html.twig', new TemplateReference('FooBundle', 'Post', 'index', 'html', 'twig')),
array('FooBundle:Post:index.xml.php', new TemplateReference('FooBundle', 'Post', 'index', 'xml', 'php')),
array('SensioFooBundle:Post:index.html.php', new TemplateReference('SensioFooBundle', 'Post', 'index', 'html', 'php')),
array('SensioCmsFooBundle:Post:index.html.php', new TemplateReference('SensioCmsFooBundle', 'Post', 'index', 'html', 'php')),
array(':Post:index.html.php', new TemplateReference('', 'Post', 'index', 'html', 'php')),
array('::index.html.php', new TemplateReference('', '', 'index', 'html', 'php')),
array('FooBundle:Post:foo.bar.index.html.php', new TemplateReference('FooBundle', 'Post', 'foo.bar.index', 'html', 'php')),
array('/path/to/section/name.php', new BaseTemplateReference('/path/to/section/name.php', 'php')),
array('name.twig', new BaseTemplateReference('name.twig', 'twig')),
array('name', new BaseTemplateReference('name')),
array('FooBundle:Post:index.html.php', 'FooBundle:Post:index.html.php', '@FooBundle/Resources/views/Post/index.html.php', new TemplateReference('FooBundle', 'Post', 'index', 'html', 'php')),
array('FooBundle:Post:index.html.twig', 'FooBundle:Post:index.html.twig', '@FooBundle/Resources/views/Post/index.html.twig', new TemplateReference('FooBundle', 'Post', 'index', 'html', 'twig')),
array('FooBundle:Post:index.xml.php', 'FooBundle:Post:index.xml.php', '@FooBundle/Resources/views/Post/index.xml.php', new TemplateReference('FooBundle', 'Post', 'index', 'xml', 'php')),
array('SensioFooBundle:Post:index.html.php', 'SensioFooBundle:Post:index.html.php', '@SensioFooBundle/Resources/views/Post/index.html.php', new TemplateReference('SensioFooBundle', 'Post', 'index', 'html', 'php')),
array('SensioCmsFooBundle:Post:index.html.php', 'SensioCmsFooBundle:Post:index.html.php', '@SensioCmsFooBundle/Resources/views/Post/index.html.php', new TemplateReference('SensioCmsFooBundle', 'Post', 'index', 'html', 'php')),
array(':Post:index.html.php', ':Post:index.html.php', 'views/Post/index.html.php', new TemplateReference('', 'Post', 'index', 'html', 'php')),
array('::index.html.php', '::index.html.php', 'views/index.html.php', new TemplateReference('', '', 'index', 'html', 'php')),
array('index.html.php', '::index.html.php', 'views/index.html.php', new TemplateReference('', '', 'index', 'html', 'php')),
array('FooBundle:Post:foo.bar.index.html.php', 'FooBundle:Post:foo.bar.index.html.php', '@FooBundle/Resources/views/Post/foo.bar.index.html.php', new TemplateReference('FooBundle', 'Post', 'foo.bar.index', 'html', 'php')),
array('/path/to/section/name.php', '/path/to/section/name.php', '/path/to/section/name.php', new BaseTemplateReference('/path/to/section/name.php', 'php')),
array('name.twig', 'name.twig', 'name.twig', new BaseTemplateReference('name.twig', 'twig')),
array('name', 'name', 'name', new BaseTemplateReference('name')),
array('default/index.html.php', '::default/index.html.php', 'views/default/index.html.php', new TemplateReference(null, null, 'default/index', 'html', 'php')),
);
}

View File

@ -116,7 +116,7 @@ build: 56
background: transparent url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAcAAAAcCAYAAACtQ6WLAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAR1JREFUeNpiPHnyZCMDA8MNID5gZmb2nAEJMH7//v3N169fX969e/cYkL8WqGAHXPLv37//QYzfv39/fvPmzbUnT56sAXInmJub/2H5/x8sx8DCwsIrISFhDmQyPX78+CmQXs70798/BmQsKipqBNTgdvz4cWkmkE5kDATMioqKZkCFdiwg1eiAi4tLGqhQF24nMmBmZuYEigth1QkEbEBxTlySYPvJkwSJ00AnjYylgU6gxB8g/oFVEphkvgLF32KNMmCCewYUv4qhEyj47+HDhyeBzIMYOoEp8CxQw56wsLAncJ1//vz5/P79+2svX74EJc2V4BT58+fPd8CE/QKYHMGJOiIiAp6oWW7evDkNSF8DZYfIyEiU7AAQYACJ2vxVdJW4eQAAAABJRU5ErkJggg==) right top no-repeat;
}
.sf-button .btn-bg {
padding: 0px 14px;
padding: 0 14px;
color: #636363;
line-height: 28px;
background: transparent url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAcCAYAAACgXdXMAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAClJREFUeNpiPnny5EKGf//+/Wf6//8/A4QAcrGzKCZwGc9sa2urBBBgAIbDUoYVp9lmAAAAAElFTkSuQmCC) repeat-x top left;

View File

@ -63,8 +63,7 @@
<script>//<![CDATA[
function toggleMenuPanels(state, doSave) {
var menu = document.getElementById('navigation'), savedState = Sfjs.getPreference('menu/displayState'),
displayState, elem, className;
var menu = document.getElementById('navigation'), savedState = Sfjs.getPreference('menu/displayState'), displayState;
if (null === savedState) {
savedState = 'block';

View File

@ -134,7 +134,7 @@ pre, code {
}
#menu-profiler li a span.label {
display: block;
padding: 20px 0px 16px 65px;
padding: 20px 0 16px 65px;
min-height: 16px;
overflow: hidden;
}
@ -285,7 +285,6 @@ ul.alt li.scream, ul.alt li.scream strong {
color: gray;
}
ul.sf-call-stack li {
text-size: small;
padding: 0 0 0 20px;
}
td.main, td.menu {
@ -385,13 +384,12 @@ td.main, td.menu {
line-height: 1.5em;
}
.sf-profiler-timeline .legends span {
border-left-width: 10px;
border-left-style: solid;
border-left: 10px solid;
padding: 0 10px 0 5px;
}
.sf-profiler-timeline canvas {
border: 1px solid #999;
border-width: 1px 0;
border: 1px #999;
border-style: solid none;
}
.collapsed-menu-parents #resume,
.collapsed-menu-parents #collector-content {

View File

@ -104,9 +104,9 @@
}
.sf-toolbar-block .sf-toolbar-info-piece .sf-toolbar-status {
padding: 0px 5px;
padding: 0 5px;
border-radius: 5px;
margin-bottom: 0px;
margin-bottom: 0;
vertical-align: top;
}
@ -140,13 +140,11 @@
display: none;
position: absolute;
background-color: #fff;
border: 1px solid #bbb;
padding: 9px 0;
margin-left: -1px;
bottom: 38px;
border-bottom-width: 0;
border-bottom: 1px solid #bbb;
border: 1px solid #bbb;
border-radius: 4px 4px 0 0;
}
@ -205,7 +203,7 @@
}
.sf-toolbar-block .sf-toolbar-icon > a,
.sf-toolbar-block .sf-toolbar-icon > a:link
.sf-toolbar-block .sf-toolbar-icon > a:link,
.sf-toolbar-block .sf-toolbar-icon > a:hover {
color: black !important;
}

View File

@ -62,8 +62,6 @@ class ProfilerControllerTest extends \PHPUnit_Framework_TestCase
if ('found' == $token) {
return new Profile($token);
}
return;
}))
;

View File

@ -74,7 +74,7 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
$document = simplexml_import_dom($document);
$bodies = $document->xpath('//body');
$elements = $bodies[0]->xpath($translator->cssToXPath($css));
$this->assertEquals($count, count($elements));
$this->assertCount($count, $elements);
}
public function getXpathLiteralTestData()

View File

@ -59,6 +59,18 @@ class ContainerAwareEventDispatcherTest extends AbstractEventDispatcherTest
->with($event)
;
$service
->expects($this->once())
->method('onEventWithPriority')
->with($event)
;
$service
->expects($this->once())
->method('onEventNested')
->with($event)
;
$container = new Container();
$container->set('service.subscriber', $service);
@ -66,6 +78,8 @@ class ContainerAwareEventDispatcherTest extends AbstractEventDispatcherTest
$dispatcher->addSubscriberService('service.subscriber', 'Symfony\Component\EventDispatcher\Tests\SubscriberService');
$dispatcher->dispatch('onEvent', $event);
$dispatcher->dispatch('onEventWithPriority', $event);
$dispatcher->dispatch('onEventNested', $event);
}
public function testPreventDuplicateListenerService()
@ -239,11 +253,21 @@ class SubscriberService implements EventSubscriberInterface
public static function getSubscribedEvents()
{
return array(
'onEvent' => array('onEvent'),
'onEvent' => 'onEvent',
'onEventWithPriority' => array('onEventWithPriority', 10),
'onEventNested' => array(array('onEventNested')),
);
}
public function onEvent(Event $e)
{
}
public function onEventWithPriority(Event $e)
{
}
public function onEventNested(Event $e)
{
}
}

View File

@ -94,7 +94,7 @@ abstract class AbstractFindAdapter extends AbstractAdapter
$command->setErrorHandler(
$this->ignoreUnreadableDirs
// If directory is unreadable and finder is set to ignore it, `stderr` is ignored.
? function ($stderr) { return; }
? function ($stderr) { }
: function ($stderr) { throw new AccessDeniedException($stderr); }
);

View File

@ -64,7 +64,7 @@ abstract class BaseValidatorExtensionTest extends TypeTestCase
public function testValidationGroupsCanBeSetToClosure()
{
$form = $this->createForm(array(
'validation_groups' => function (FormInterface $form) { return; },
'validation_groups' => function (FormInterface $form) { },
));
$this->assertTrue(is_callable($form->getConfig()->getOption('validation_groups')));

View File

@ -482,6 +482,6 @@ class OrderedHashMapTest extends \PHPUnit_Framework_TestCase
unset($map[0]);
$map[] = 3;
$this->assertSame(2, count($map));
$this->assertCount(2, $map);
}
}

View File

@ -1828,8 +1828,6 @@ class Request
return '/';
}
$pathInfo = '/';
// Remove the query string from REQUEST_URI
if ($pos = strpos($requestUri, '?')) {
$requestUri = substr($requestUri, 0, $pos);

View File

@ -277,7 +277,7 @@ class HttpCache implements HttpKernelInterface, TerminableInterface
// invalidate only when the response is successful
if ($response->isSuccessful() || $response->isRedirect()) {
try {
$this->store->invalidate($request, $catch);
$this->store->invalidate($request);
// As per the RFC, invalidate Location and Content-Location URLs if present
foreach (array('Location', 'Content-Location') as $header) {
@ -503,7 +503,7 @@ class HttpCache implements HttpKernelInterface, TerminableInterface
$this->processResponseBody($request, $response);
if ($this->isPrivateRequest($request) && !$response->headers->hasCacheControlDirective('public')) {
$response->setPrivate(true);
$response->setPrivate();
} elseif ($this->options['default_ttl'] > 0 && null === $response->getTtl() && !$response->headers->getCacheControlDirective('must-revalidate')) {
$response->setTtl($this->options['default_ttl']);
}

View File

@ -77,7 +77,7 @@ class SqliteProfilerStorage extends PdoProfilerStorage
$return = array();
if ($db instanceof \SQLite3) {
$stmt = $this->prepareStatement($db, $query, true);
$stmt = $this->prepareStatement($db, $query);
foreach ($args as $arg => $val) {
$stmt->bindValue($arg, $val, is_int($val) ? \SQLITE3_INTEGER : \SQLITE3_TEXT);
}

View File

@ -121,8 +121,6 @@ class CurrencyDataGenerator extends AbstractDataGenerator
return $data;
}
return;
}
/**

View File

@ -133,8 +133,6 @@ class LanguageDataGenerator extends AbstractDataGenerator
return $data;
}
return;
}
/**
@ -142,7 +140,6 @@ class LanguageDataGenerator extends AbstractDataGenerator
*/
protected function generateDataForRoot(BundleReaderInterface $reader, $tempDir)
{
return;
}
/**

View File

@ -67,7 +67,7 @@ class LocaleScanner
*/
public function scanAliases($sourceDir)
{
$locales = $this->scanLocales($sourceDir, '.txt');
$locales = $this->scanLocales($sourceDir);
$aliases = array();
// Delete locales that are no aliases

View File

@ -638,8 +638,7 @@ class IntlDateFormatter
if (self::NONE !== $this->timetype) {
$patternParts[] = $this->defaultTimeFormats[$this->timetype];
}
$pattern = implode(', ', $patternParts);
return $pattern;
return implode(', ', $patternParts);
}
}

View File

@ -12,7 +12,6 @@
namespace Symfony\Component\Intl\Tests\Data\Bundle\Reader;
use Symfony\Component\Intl\Data\Bundle\Reader\IntlBundleReader;
use Symfony\Component\Intl\Intl;
/**
* @author Bernhard Schussek <bschussek@gmail.com>

View File

@ -13,7 +13,6 @@ namespace Symfony\Component\Intl\Tests\Data\Bundle\Writer;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Intl\Data\Bundle\Writer\JsonBundleWriter;
use Symfony\Component\Intl\Intl;
/**
* @author Bernhard Schussek <bschussek@gmail.com>

View File

@ -13,7 +13,6 @@ namespace Symfony\Component\Intl\Tests\Data\Bundle\Writer;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Intl\Data\Bundle\Writer\PhpBundleWriter;
use Symfony\Component\Intl\Intl;
/**
* @author Bernhard Schussek <bschussek@gmail.com>

View File

@ -64,13 +64,13 @@ class LocaleScannerTest extends \PHPUnit_Framework_TestCase
{
$sortedLocales = array('de', 'de_alias', 'en', 'en_alias', 'fr', 'fr_alias');
$this->assertSame($sortedLocales, $this->scanner->scanLocales($this->directory, '.txt'));
$this->assertSame($sortedLocales, $this->scanner->scanLocales($this->directory));
}
public function testScanAliases()
{
$sortedAliases = array('de_alias' => 'de', 'en_alias' => 'en', 'fr_alias' => 'fr');
$this->assertSame($sortedAliases, $this->scanner->scanAliases($this->directory, '.txt'));
$this->assertSame($sortedAliases, $this->scanner->scanAliases($this->directory));
}
}

View File

@ -66,12 +66,16 @@ class AnnotationDirectoryLoader extends AnnotationFileLoader
*/
public function supports($resource, $type = null)
{
if (!is_string($resource)) {
return false;
}
try {
$path = $this->locator->locate($resource);
} catch (\Exception $e) {
return false;
}
return is_string($resource) && is_dir($path) && (!$type || 'annotation' === $type);
return is_dir($path) && (!$type || 'annotation' === $type);
}
}

View File

@ -650,9 +650,8 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase
$method = 'set'.$key;
$context->$method($value);
}
$generator = new UrlGenerator($routes, $context, $logger);
return $generator;
return new UrlGenerator($routes, $context, $logger);
}
protected function getRoutes($name, Route $route)

View File

@ -924,7 +924,7 @@ QUERY;
*/
private function updateNewAceProperty($name, array $changes)
{
list($old, $new) = $changes;
list(, $new) = $changes;
$sids = new \SplObjectStorage();
$classIds = new \SplObjectStorage();

View File

@ -172,9 +172,8 @@ class TokenBasedRememberMeServicesTest extends \PHPUnit_Framework_TestCase
{
$service = $this->getService(null, array('name' => 'foo', 'path' => '/foo', 'domain' => 'foodomain.foo'));
$request = new Request();
$response = new Response();
$service->loginFail($request, $response);
$service->loginFail($request);
$cookie = $request->attributes->get(RememberMeServicesInterface::COOKIE_ATTR_NAME);
$this->assertTrue($cookie->isCleared());

View File

@ -420,7 +420,6 @@ class GetSetMethodNormalizerTest extends \PHPUnit_Framework_TestCase
array(
array(
'bar' => function ($bar) {
return;
},
),
'baz',

View File

@ -25,9 +25,7 @@ class PhpFileDumper extends FileDumper
*/
protected function format(MessageCatalogue $messages, $domain)
{
$output = "<?php\n\nreturn ".var_export($messages->all($domain), true).";\n";
return $output;
return "<?php\n\nreturn ".var_export($messages->all($domain), true).";\n";
}
/**