Merge branch '2.3' into 2.4

* 2.3:
  fixed various inconsistencies
  reduced recursion when building DumperPrefixCollection
  renamed variables - making next change more readable
  removing dead code.
  [DomCrawler] Fixed filterXPath() chaining
  [DomCrawler] Fixed incorrect handling of image inputs

Conflicts:
	src/Symfony/Component/DomCrawler/Crawler.php
	src/Symfony/Component/EventDispatcher/Tests/EventDispatcherTest.php
	src/Symfony/Component/Form/Extension/DependencyInjection/DependencyInjectionExtension.php
	src/Symfony/Component/Serializer/Tests/Normalizer/CustomNormalizerTest.php
	src/Symfony/Component/Templating/Tests/Loader/CacheLoaderTest.php
	src/Symfony/Component/Templating/Tests/Loader/LoaderTest.php
This commit is contained in:
Fabien Potencier 2014-02-11 14:52:09 +01:00
commit e2ac5dfc78
53 changed files with 129 additions and 134 deletions

View File

@ -92,7 +92,8 @@ class EntityUserProvider implements UserProviderInterface
);
}
if (null === $refreshedUser = $this->repository->find($id)) {
$refreshedUser = $this->repository->find($id);
if (null === $refreshedUser) {
throw new UsernameNotFoundException(sprintf('User with id %s not found', json_encode($id)));
}
}

View File

@ -11,7 +11,7 @@
namespace Symfony\Bridge\Doctrine\Tests\Fixtures;
use Doctrine\ORM\Mapping AS ORM;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity

View File

@ -22,7 +22,7 @@ class CompilerDebugDumpPass implements CompilerPassInterface
{
$filesystem = new Filesystem();
$filesystem->dumpFile(
$this->getCompilerLogFilename($container),
self::getCompilerLogFilename($container),
implode("\n", $container->getCompiler()->getLog()),
0666 & ~umask()
);

View File

@ -37,7 +37,7 @@ class TemplateFinderTest extends TestCase
->will($this->returnValue(array('BaseBundle' => new BaseBundle())))
;
$parser = new TemplateFilenameParser($kernel);
$parser = new TemplateFilenameParser();
$finder = new TemplateFinder($kernel, $parser, __DIR__.'/../Fixtures/Resources');

View File

@ -33,7 +33,7 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
public function testValidTrustedProxies($trustedProxies, $processedProxies)
{
$processor = new Processor();
$configuration = new Configuration(array());
$configuration = new Configuration();
$config = $processor->processConfiguration($configuration, array(array(
'secret' => 's3cr3t',
'trusted_proxies' => $trustedProxies
@ -62,7 +62,7 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
public function testInvalidTypeTrustedProxies()
{
$processor = new Processor();
$configuration = new Configuration(array());
$configuration = new Configuration();
$processor->processConfiguration($configuration, array(
array(
'secret' => 's3cr3t',
@ -77,7 +77,7 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
public function testInvalidValueTrustedProxies()
{
$processor = new Processor();
$configuration = new Configuration(array());
$configuration = new Configuration();
$processor->processConfiguration($configuration, array(
array(
'secret' => 's3cr3t',

View File

@ -37,7 +37,7 @@ class WebTestCase extends BaseWebTestCase
{
require_once __DIR__.'/app/AppKernel.php';
return 'Symfony\Bundle\FrameworkBundle\Tests\Functional\AppKernel';
return 'Symfony\Bundle\FrameworkBundle\Tests\Functional\app\AppKernel';
}
protected static function createKernel(array $options = array())

View File

@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\app;
// get the autoload file
$dir = __DIR__;

View File

@ -37,7 +37,7 @@ class WebTestCase extends BaseWebTestCase
{
require_once __DIR__.'/app/AppKernel.php';
return 'Symfony\Bundle\SecurityBundle\Tests\Functional\AppKernel';
return 'Symfony\Bundle\SecurityBundle\Tests\Functional\app\AppKernel';
}
protected static function createKernel(array $options = array())

View File

@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\SecurityBundle\Tests\Functional;
namespace Symfony\Bundle\SecurityBundle\Tests\Functional\app;
// get the autoload file
$dir = __DIR__;

View File

@ -22,7 +22,7 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
public function testConfigTree($options, $results)
{
$processor = new Processor();
$configuration = new Configuration(array());
$configuration = new Configuration();
$config = $processor->processConfiguration($configuration, array($options));
$this->assertEquals($results, $config);

View File

@ -116,7 +116,8 @@ class XcacheClassLoader
if (xcache_isset($this->prefix.$class)) {
$file = xcache_get($this->prefix.$class);
} else {
xcache_set($this->prefix.$class, $file = $this->classFinder->findFile($class));
$file = $this->classFinder->findFile($class);
xcache_set($this->prefix.$class, $file);
}
return $file;

View File

@ -349,7 +349,7 @@ class ProgressHelper extends Helper
$vars = array();
$percent = 0;
if ($this->max > 0) {
$percent = (double) $this->current / $this->max;
$percent = (float) $this->current / $this->max;
}
if (isset($this->formatVars['bar'])) {

View File

@ -471,7 +471,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
public function testAsText()
{
$application = new Application();
$application->add(new \FooCommand);
$application->add(new \FooCommand());
$this->ensureStaticCommandHelp($application);
$this->assertStringEqualsFile(self::$fixturesPath.'/application_astext1.txt', $this->normalizeLineBreaks($application->asText()), '->asText() returns a text representation of the application');
$this->assertStringEqualsFile(self::$fixturesPath.'/application_astext2.txt', $this->normalizeLineBreaks($application->asText('foo')), '->asText() returns a text representation of the application');
@ -480,7 +480,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
public function testAsXml()
{
$application = new Application();
$application->add(new \FooCommand);
$application->add(new \FooCommand());
$this->ensureStaticCommandHelp($application);
$this->assertXmlStringEqualsXmlFile(self::$fixturesPath.'/application_asxml1.txt', $application->asXml(), '->asXml() returns an XML representation of the application');
$this->assertXmlStringEqualsXmlFile(self::$fixturesPath.'/application_asxml2.txt', $application->asXml('foo'), '->asXml() returns an XML representation of the application');
@ -504,7 +504,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$tester->run(array('command' => 'list', '--foo' => true), array('decorated' => false));
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception2.txt', $tester->getDisplay(true), '->renderException() renders the command synopsis when an exception occurs in the context of a command');
$application->add(new \Foo3Command);
$application->add(new \Foo3Command());
$tester = new ApplicationTester($application);
$tester->run(array('command' => 'foo3:bar'), array('decorated' => false));
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception3.txt', $tester->getDisplay(true), '->renderException() renders a pretty exceptions with previous exceptions');

View File

@ -14,7 +14,6 @@ namespace Symfony\Component\CssSelector\Tests\Parser\Handler;
use Symfony\Component\CssSelector\Parser\Handler\NumberHandler;
use Symfony\Component\CssSelector\Parser\Token;
use Symfony\Component\CssSelector\Parser\Tokenizer\TokenizerPatterns;
use Symfony\Component\CssSelector\Parser\Tokenizer\TokenizerEscaping;
class NumberHandlerTest extends AbstractHandlerTest
{
@ -46,6 +45,6 @@ class NumberHandlerTest extends AbstractHandlerTest
{
$patterns = new TokenizerPatterns();
return new NumberHandler($patterns, new TokenizerEscaping($patterns));
return new NumberHandler($patterns);
}
}

View File

@ -57,6 +57,6 @@ class ExceptionHandlerTest extends \PHPUnit_Framework_TestCase
public function testNestedExceptions()
{
$handler = new ExceptionHandler(true);
$response = $handler->createResponse(new \RuntimeException('Foo', null, new \RuntimeException('Bar')));
$response = $handler->createResponse(new \RuntimeException('Foo', 0, new \RuntimeException('Bar')));
}
}

View File

@ -69,7 +69,7 @@ class PhpDumper extends Dumper
{
parent::__construct($container);
$this->inlinedDefinitions = new \SplObjectStorage;
$this->inlinedDefinitions = new \SplObjectStorage();
}
/**

View File

@ -454,7 +454,7 @@ class Crawler extends \SplObjectStorage
$nodes = array();
while ($node = $node->parentNode) {
if (1 === $node->nodeType && '_root' !== $node->nodeName) {
if (1 === $node->nodeType) {
$nodes[] = $node;
}
}
@ -599,16 +599,14 @@ class Crawler extends \SplObjectStorage
*/
public function filterXPath($xpath)
{
$document = new \DOMDocument('1.0', 'UTF-8');
$root = $document->appendChild($document->createElement('_root'));
$crawler = new static(null, $this->uri);
$prefixes = $this->findNamespacePrefixes($xpath);
foreach ($this as $node) {
$root->appendChild($document->importNode($node, true));
$domxpath = $this->createDOMXPath($node->ownerDocument, $prefixes);
$crawler->add($domxpath->query($xpath, $node));
}
$prefixes = $this->findNamespacePrefixes($xpath);
$domxpath = $this->createDOMXPath($document, $prefixes);
return new static($domxpath->query($xpath), $this->uri);
return $crawler;
}
/**

View File

@ -52,13 +52,7 @@ abstract class FormField
{
$this->node = $node;
$this->name = $node->getAttribute('name');
$this->document = new \DOMDocument('1.0', 'UTF-8');
$this->node = $this->document->importNode($this->node, true);
$root = $this->document->appendChild($this->document->createElement('_root'));
$root->appendChild($this->node);
$this->xpath = new \DOMXPath($this->document);
$this->xpath = new \DOMXPath($node->ownerDocument);
$this->initialize();
}

View File

@ -394,34 +394,43 @@ class Form extends Link implements \ArrayAccess
{
$this->fields = new FormFieldRegistry();
$document = new \DOMDocument('1.0', 'UTF-8');
$xpath = new \DOMXPath($document);
$root = $document->appendChild($document->createElement('_root'));
$xpath = new \DOMXPath($this->node->ownerDocument);
// add submitted button if it has a valid name
if ('form' !== $this->button->nodeName && $this->button->hasAttribute('name') && $this->button->getAttribute('name')) {
$this->set(new Field\InputFormField($document->importNode($this->button, true)));
if ('input' == $this->button->nodeName && 'image' == $this->button->getAttribute('type')) {
$name = $this->button->getAttribute('name');
$this->button->setAttribute('value', '0');
// temporarily change the name of the input node for the x coordinate
$this->button->setAttribute('name', $name.'.x');
$this->set(new Field\InputFormField($this->button));
// temporarily change the name of the input node for the y coordinate
$this->button->setAttribute('name', $name.'.y');
$this->set(new Field\InputFormField($this->button));
// restore the original name of the input node
$this->button->setAttribute('name', $name);
} else {
$this->set(new Field\InputFormField($this->button));
}
}
// find form elements corresponding to the current form
if ($this->node->hasAttribute('id')) {
// traverse through the whole document
$node = $document->importNode($this->node->ownerDocument->documentElement, true);
$root->appendChild($node);
// corresponding elements are either descendants or have a matching HTML5 form attribute
$formId = Crawler::xpathLiteral($this->node->getAttribute('id'));
$fieldNodes = $xpath->query(sprintf('descendant::input[@form=%s] | descendant::button[@form=%s] | descendant::textarea[@form=%s] | descendant::select[@form=%s] | //form[@id=%s]//input[not(@form)] | //form[@id=%s]//button[not(@form)] | //form[@id=%s]//textarea[not(@form)] | //form[@id=%s]//select[not(@form)]', $formId, $formId, $formId, $formId, $formId, $formId, $formId, $formId), $root);
// do the xpath query without $this->node as the context node (i.e. traverse through the whole document)
$fieldNodes = $xpath->query(sprintf('descendant::input[@form=%s] | descendant::button[@form=%s] | descendant::textarea[@form=%s] | descendant::select[@form=%s] | //form[@id=%s]//input[not(@form)] | //form[@id=%s]//button[not(@form)] | //form[@id=%s]//textarea[not(@form)] | //form[@id=%s]//select[not(@form)]', $formId, $formId, $formId, $formId, $formId, $formId, $formId, $formId));
foreach ($fieldNodes as $node) {
$this->addField($node);
}
} else {
// parent form has no id, add descendant elements only
$node = $document->importNode($this->node, true);
$root->appendChild($node);
// descendant elements with form attribute are not part of this form
$fieldNodes = $xpath->query('descendant::input[not(@form)] | descendant::button[not(@form)] | descendant::textarea[not(@form)] | descendant::select[not(@form)]', $root);
// do the xpath query with $this->node as the context node, to only find descendant elements
// however, descendant elements with form attribute are not part of this form
$fieldNodes = $xpath->query('descendant::input[not(@form)] | descendant::button[not(@form)] | descendant::textarea[not(@form)] | descendant::select[not(@form)]', $this->node);
foreach ($fieldNodes as $node) {
$this->addField($node);
}

View File

@ -390,8 +390,10 @@ EOF
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler, '->filterXPath() returns a new instance of a crawler');
$crawler = $this->createTestCrawler()->filterXPath('//ul');
$this->assertCount(6, $crawler->filterXPath('//li'), '->filterXPath() filters the node list with the XPath expression');
$crawler = $this->createTestCrawler();
$this->assertCount(3, $crawler->filterXPath('//body')->filterXPath('//button')->parents(), '->filterXpath() preserves parents when chained');
}
public function testFilterXPathWithDefaultNamespace()

View File

@ -223,6 +223,11 @@ class FormTest extends \PHPUnit_Framework_TestCase
<input type="submit" name="foobar" value="foobar" />',
array('foobar' => array('InputFormField', 'foobar')),
),
array(
'turns an image input into x and y fields',
'<input type="image" name="bar" />',
array('bar.x' => array('InputFormField', '0'), 'bar.y' => array('InputFormField', '0')),
),
array(
'returns textareas',
'<textarea name="foo">foo</textarea>

View File

@ -175,8 +175,6 @@ class ContainerAwareEventDispatcherTest extends \PHPUnit_Framework_TestCase
public function testGetListenersOnLazyLoad()
{
$event = new Event();
$service = $this->getMock('Symfony\Component\EventDispatcher\Tests\Service');
$container = new Container();
@ -194,8 +192,6 @@ class ContainerAwareEventDispatcherTest extends \PHPUnit_Framework_TestCase
public function testRemoveAfterDispatch()
{
$event = new Event();
$service = $this->getMock('Symfony\Component\EventDispatcher\Tests\Service');
$container = new Container();
@ -211,8 +207,6 @@ class ContainerAwareEventDispatcherTest extends \PHPUnit_Framework_TestCase
public function testRemoveBeforeDispatch()
{
$event = new Event();
$service = $this->getMock('Symfony\Component\EventDispatcher\Tests\Service');
$container = new Container();

View File

@ -240,6 +240,7 @@ class EventDispatcherTest extends \PHPUnit_Framework_TestCase
public function testEventReceivesTheDispatcherInstance()
{
$dispatcher = null;
$this->dispatcher->addListener('test', function ($event) use (&$dispatcher) {
$dispatcher = $event->getDispatcher();
});

View File

@ -13,7 +13,6 @@ namespace Symfony\Component\EventDispatcher\Tests;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\ImmutableEventDispatcher;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* @author Bernhard Schussek <bschussek@gmail.com>

View File

@ -19,15 +19,10 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
class DependencyInjectionExtension implements FormExtensionInterface
{
private $container;
private $typeServiceIds;
private $typeExtensionServiceIds;
private $guesserServiceIds;
private $guesser;
private $guesserLoaded = false;
public function __construct(ContainerInterface $container,

View File

@ -55,7 +55,7 @@ abstract class FormPerformanceTestCase extends FormIntegrationTestCase
if (is_integer($maxRunningTime) && $maxRunningTime >= 0) {
$this->maxRunningTime = $maxRunningTime;
} else {
throw new \InvalidArgumentException;
throw new \InvalidArgumentException();
}
}

View File

@ -82,18 +82,15 @@ class ExtensionGuesser implements ExtensionGuesserInterface
* value.
*
* @param string $mimeType The mime type
*
* @return string The guessed extension or NULL, if none could be guessed
*/
public function guess($mimeType)
{
foreach ($this->guessers as $guesser) {
$extension = $guesser->guess($mimeType);
if (null !== $extension) {
break;
if (null !== $extension = $guesser->guess($mimeType)) {
return $extension;
}
}
return $extension;
}
}

View File

@ -742,7 +742,7 @@ class ResponseTest extends ResponseTestCase
'setCharset' => 'UTF-8',
'setPublic' => null,
'setPrivate' => null,
'setDate' => new \DateTime,
'setDate' => new \DateTime(),
'expire' => null,
'setMaxAge' => 1,
'setSharedMaxAge' => 1,

View File

@ -158,7 +158,7 @@ class NativeSessionStorageTest extends \PHPUnit_Framework_TestCase
public function testSetSaveHandlerException()
{
$storage = $this->getStorage();
$storage->setSaveHandler(new \stdClass);
$storage->setSaveHandler(new \stdClass());
}
public function testSetSaveHandler53()

View File

@ -63,7 +63,7 @@ class ControllerResolver implements ControllerResolverInterface
if (false === strpos($controller, ':')) {
if (method_exists($controller, '__invoke')) {
return new $controller;
return new $controller();
} elseif (function_exists($controller)) {
return $controller;
}

View File

@ -214,7 +214,7 @@ class RedisProfilerStorage implements ProfilerStorageInterface
throw new \RuntimeException('RedisProfilerStorage requires that the redis extension is loaded.');
}
$redis = new \Redis;
$redis = new \Redis();
$redis->connect($data['host'], $data['port']);
if (isset($data['path'])) {

View File

@ -106,6 +106,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
new UploadedFile($source, 'original', 'mime/original', 123, UPLOAD_ERR_OK, true),
);
$file = null;
foreach ($files as $file) {
$client->request('POST', '/', array(), array('foo' => $file));

View File

@ -347,6 +347,7 @@ abstract class AbstractNumberFormatterTest extends \PHPUnit_Framework_TestCase
{
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
$attributeRet = null;
if (null !== $fractionDigits) {
$attributeRet = $formatter->setAttribute(NumberFormatter::FRACTION_DIGITS, $fractionDigits);
}
@ -355,7 +356,7 @@ abstract class AbstractNumberFormatterTest extends \PHPUnit_Framework_TestCase
$this->assertSame($expected, $formattedValue);
$this->assertSame($expectedFractionDigits, $formatter->getAttribute(NumberFormatter::FRACTION_DIGITS));
if (isset($attributeRet)) {
if (null !== $attributeRet) {
$this->assertTrue($attributeRet);
}
}
@ -379,6 +380,7 @@ abstract class AbstractNumberFormatterTest extends \PHPUnit_Framework_TestCase
{
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
$attributeRet = null;
if (null !== $groupingUsed) {
$attributeRet = $formatter->setAttribute(NumberFormatter::GROUPING_USED, $groupingUsed);
}
@ -387,7 +389,7 @@ abstract class AbstractNumberFormatterTest extends \PHPUnit_Framework_TestCase
$this->assertSame($expected, $formattedValue);
$this->assertSame($expectedGroupingUsed, $formatter->getAttribute(NumberFormatter::GROUPING_USED));
if (isset($attributeRet)) {
if (null !== $attributeRet) {
$this->assertTrue($attributeRet);
}
}

View File

@ -25,7 +25,7 @@ function handleSignal($signal)
echo "received signal $name\n";
}
declare(ticks=1);
declare(ticks = 1);
pcntl_signal(SIGTERM, 'handleSignal');
pcntl_signal(SIGINT, 'handleSignal');

View File

@ -31,17 +31,16 @@ class AnnotationFileLoader extends FileLoader
*
* @param FileLocatorInterface $locator A FileLocator instance
* @param AnnotationClassLoader $loader An AnnotationClassLoader instance
* @param string|array $paths A path or an array of paths where to look for resources
*
* @throws \RuntimeException
*/
public function __construct(FileLocatorInterface $locator, AnnotationClassLoader $loader, $paths = array())
public function __construct(FileLocatorInterface $locator, AnnotationClassLoader $loader)
{
if (!function_exists('token_get_all')) {
throw new \RuntimeException('The Tokenizer extension is required for the routing annotation loaders.');
}
parent::__construct($locator, $paths);
parent::__construct($locator);
$this->loader = $loader;
}

View File

@ -56,29 +56,27 @@ class DumperPrefixCollection extends DumperCollection
{
$prefix = $route->getRoute()->compile()->getStaticPrefix();
// Same prefix, add to current leave
if ($this->prefix === $prefix) {
$this->add($route);
for ($collection = $this; null !== $collection; $collection = $collection->getParent()) {
return $this;
// Same prefix, add to current leave
if ($collection->prefix === $prefix) {
$collection->add($route);
return $collection;
}
// Prefix starts with route's prefix
if ('' === $collection->prefix || 0 === strpos($prefix, $collection->prefix)) {
$child = new DumperPrefixCollection();
$child->setPrefix(substr($prefix, 0, strlen($collection->prefix)+1));
$collection->add($child);
return $child->addPrefixRoute($route);
}
}
// Prefix starts with route's prefix
if ('' === $this->prefix || 0 === strpos($prefix, $this->prefix)) {
$collection = new DumperPrefixCollection();
$collection->setPrefix(substr($prefix, 0, strlen($this->prefix)+1));
$this->add($collection);
return $collection->addPrefixRoute($route);
}
// No match, fallback to parent (recursively)
if (null === $parent = $this->getParent()) {
throw new \LogicException("The collection root must not have a prefix");
}
return $parent->addPrefixRoute($route);
// Reached only if the root has a non empty prefix
throw new \LogicException("The collection root must not have a prefix");
}
/**

View File

@ -115,7 +115,7 @@ class DaoAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
->method('isPasswordValid')
;
$provider = $this->getProvider(false, false, $encoder);
$provider = $this->getProvider(null, null, $encoder);
$method = new \ReflectionMethod($provider, 'checkAuthentication');
$method->setAccessible(true);
@ -142,7 +142,7 @@ class DaoAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue(true))
;
$provider = $this->getProvider(false, false, $encoder);
$provider = $this->getProvider(null, null, $encoder);
$method = new \ReflectionMethod($provider, 'checkAuthentication');
$method->setAccessible(true);
@ -171,7 +171,7 @@ class DaoAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue(false))
;
$provider = $this->getProvider(false, false, $encoder);
$provider = $this->getProvider(null, null, $encoder);
$method = new \ReflectionMethod($provider, 'checkAuthentication');
$method->setAccessible(true);
@ -206,7 +206,7 @@ class DaoAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue('newFoo'))
;
$provider = $this->getProvider(false, false, null);
$provider = $this->getProvider();
$reflection = new \ReflectionMethod($provider, 'checkAuthentication');
$reflection->setAccessible(true);
$reflection->invoke($provider, $dbUser, $token);
@ -231,7 +231,7 @@ class DaoAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue('foo'))
;
$provider = $this->getProvider(false, false, null);
$provider = $this->getProvider();
$reflection = new \ReflectionMethod($provider, 'checkAuthentication');
$reflection->setAccessible(true);
$reflection->invoke($provider, $dbUser, $token);
@ -245,7 +245,7 @@ class DaoAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue(true))
;
$provider = $this->getProvider(false, false, $encoder);
$provider = $this->getProvider(null, null, $encoder);
$method = new \ReflectionMethod($provider, 'checkAuthentication');
$method->setAccessible(true);
@ -270,17 +270,17 @@ class DaoAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
return $mock;
}
protected function getProvider($user = false, $userChecker = false, $passwordEncoder = null)
protected function getProvider($user = null, $userChecker = null, $passwordEncoder = null)
{
$userProvider = $this->getMock('Symfony\\Component\\Security\\Core\\User\\UserProviderInterface');
if (false !== $user) {
if (null !== $user) {
$userProvider->expects($this->once())
->method('loadUserByUsername')
->will($this->returnValue($user))
;
}
if (false === $userChecker) {
if (null === $userChecker) {
$userChecker = $this->getMock('Symfony\\Component\\Security\\Core\\User\\UserCheckerInterface');
}

View File

@ -114,17 +114,17 @@ class PreAuthenticatedAuthenticationProviderTest extends \PHPUnit_Framework_Test
return $token;
}
protected function getProvider($user = false, $userChecker = false)
protected function getProvider($user = null, $userChecker = null)
{
$userProvider = $this->getMock('Symfony\Component\Security\Core\User\UserProviderInterface');
if (false !== $user) {
if (null !== $user) {
$userProvider->expects($this->once())
->method('loadUserByUsername')
->will($this->returnValue($user))
;
}
if (false === $userChecker) {
if (null === $userChecker) {
$userChecker = $this->getMock('Symfony\Component\Security\Core\User\UserCheckerInterface');
}

View File

@ -111,8 +111,8 @@ class SecureRandomTest extends \PHPUnit_Framework_TestCase
{
$b = $this->getBitSequence($secureRandom, 20000);
$longestRun = 0;
$currentRun = $lastBit = null;
$longestRun = $currentRun = 0;
$lastBit = null;
for ($i = 0; $i < 20000; $i++) {
if ($lastBit === $b[$i]) {
$currentRun += 1;

View File

@ -49,7 +49,7 @@ class ResponseListenerTest extends \PHPUnit_Framework_TestCase
{
$listener = new ResponseListener();
$this->assertSame(array(KernelEvents::RESPONSE => 'onKernelResponse'), $listener->getSubscribedEvents());
$this->assertSame(array(KernelEvents::RESPONSE => 'onKernelResponse'), ResponseListener::getSubscribedEvents());
}
private function getRequest(array $attributes = array())

View File

@ -32,7 +32,7 @@ class TokenBasedRememberMeServicesTest extends \PHPUnit_Framework_TestCase
public function testAutoLoginThrowsExceptionOnInvalidCookie()
{
$service = $this->getService(null, array('name' => 'foo', 'path' => null, 'domain' => null, 'always_remember_me' => false, 'remember_me_parameter' => 'foo'));
$request = new Request;
$request = new Request();
$request->request->set('foo', 'true');
$request->cookies->set('foo', 'foo');

View File

@ -29,7 +29,7 @@ class CustomNormalizer extends SerializerAwareNormalizer implements NormalizerIn
*/
public function denormalize($data, $class, $format = null, array $context = array())
{
$object = new $class;
$object = new $class();
$object->denormalize($this->serializer, $data, $format, $context);
return $object;

View File

@ -25,7 +25,7 @@ class JsonEncoderTest extends \PHPUnit_Framework_TestCase
public function testEncodeScalar()
{
$obj = new \stdClass;
$obj = new \stdClass();
$obj->foo = "foo";
$expected = '{"foo":"foo"}';
@ -68,7 +68,7 @@ class JsonEncoderTest extends \PHPUnit_Framework_TestCase
protected function getObject()
{
$obj = new \stdClass;
$obj = new \stdClass();
$obj->foo = 'foo';
$obj->bar = array('a', 'b');
$obj->baz = array('key' => 'val', 'key2' => 'val', 'A B' => 'bar', 'item' => array(array('title' => 'title1'), array('title' => 'title2')), 'Barry' => array('FooBar' => array('Baz' => 'Ed', '@id' => 1)));

View File

@ -46,7 +46,7 @@ class CustomNormalizerTest extends \PHPUnit_Framework_TestCase
public function testSupportsNormalization()
{
$this->assertTrue($this->normalizer->supportsNormalization(new ScalarDummy()));
$this->assertFalse($this->normalizer->supportsNormalization(new \stdClass));
$this->assertFalse($this->normalizer->supportsNormalization(new \stdClass()));
}
public function testSupportsDenormalization()

View File

@ -28,7 +28,7 @@ class SerializerTest extends \PHPUnit_Framework_TestCase
public function testNormalizeNoMatch()
{
$this->serializer = new Serializer(array($this->getMock('Symfony\Component\Serializer\Normalizer\CustomNormalizer')));
$this->serializer->normalize(new \stdClass, 'xml');
$this->serializer->normalize(new \stdClass(), 'xml');
}
public function testNormalizeTraversable()
@ -51,7 +51,7 @@ class SerializerTest extends \PHPUnit_Framework_TestCase
public function testNormalizeOnDenormalizer()
{
$this->serializer = new Serializer(array(new TestDenormalizer()), array());
$this->assertTrue($this->serializer->normalize(new \stdClass, 'json'));
$this->assertTrue($this->serializer->normalize(new \stdClass(), 'json'));
}
/**

View File

@ -161,7 +161,9 @@ class StopwatchEvent
*/
public function getEndTime()
{
return ($count = count($this->periods)) ? $this->periods[$count - 1]->getEndTime() : 0;
$count = count($this->periods);
return $count ? $this->periods[$count - 1]->getEndTime() : 0;
}
/**

View File

@ -27,7 +27,7 @@ class Package implements PackageInterface
* @param string $version The package version
* @param string $format The format used to apply the version
*/
public function __construct($version = null, $format = null)
public function __construct($version = null, $format = '')
{
$this->version = $version;
$this->format = $format ?: '%s?%s';

View File

@ -14,7 +14,6 @@ namespace Symfony\Component\Templating\Tests\Loader;
use Symfony\Component\Templating\Loader\Loader;
use Symfony\Component\Templating\Loader\CacheLoader;
use Symfony\Component\Templating\Storage\StringStorage;
use Symfony\Component\Templating\TemplateNameParser;
use Symfony\Component\Templating\TemplateReferenceInterface;
use Symfony\Component\Templating\TemplateReference;
@ -22,7 +21,7 @@ class CacheLoaderTest extends \PHPUnit_Framework_TestCase
{
public function testConstructor()
{
$loader = new ProjectTemplateLoader($varLoader = new ProjectTemplateLoaderVar(new TemplateNameParser()), sys_get_temp_dir());
$loader = new ProjectTemplateLoader($varLoader = new ProjectTemplateLoaderVar(), sys_get_temp_dir());
$this->assertTrue($loader->getLoader() === $varLoader, '__construct() takes a template loader as its first argument');
$this->assertEquals(sys_get_temp_dir(), $loader->getDir(), '__construct() takes a directory where to store the cache as its second argument');
}
@ -32,7 +31,7 @@ class CacheLoaderTest extends \PHPUnit_Framework_TestCase
$dir = sys_get_temp_dir().DIRECTORY_SEPARATOR.rand(111111, 999999);
mkdir($dir, 0777, true);
$loader = new ProjectTemplateLoader($varLoader = new ProjectTemplateLoaderVar(new TemplateNameParser()), $dir);
$loader = new ProjectTemplateLoader($varLoader = new ProjectTemplateLoaderVar(), $dir);
$this->assertFalse($loader->load(new TemplateReference('foo', 'php')), '->load() returns false if the embed loader is not able to load the template');
$logger = $this->getMock('Psr\Log\LoggerInterface');

View File

@ -12,7 +12,6 @@
namespace Symfony\Component\Templating\Tests\Loader;
use Symfony\Component\Templating\Loader\Loader;
use Symfony\Component\Templating\TemplateNameParser;
use Symfony\Component\Templating\TemplateReferenceInterface;
class LoaderTest extends \PHPUnit_Framework_TestCase
@ -27,7 +26,7 @@ class LoaderTest extends \PHPUnit_Framework_TestCase
public function testGetSetDebugger()
{
$loader = new ProjectTemplateLoader4(new TemplateNameParser());
$loader = new ProjectTemplateLoader4();
$debugger = $this->getMock('Symfony\Component\Templating\DebuggerInterface');
$loader->setDebugger($debugger);
$this->assertSame($debugger, $loader->getDebugger(), '->setDebugger() sets the debugger instance');

View File

@ -29,7 +29,7 @@ abstract class AbstractComparison extends Constraint
*/
public function __construct($options = null)
{
if (!isset($options['value'])) {
if (is_array($options) && !isset($options['value'])) {
throw new ConstraintDefinitionException(sprintf(
'The %s constraint requires the "value" option to be set.',
get_class($this)

View File

@ -30,7 +30,7 @@ abstract class AbstractComparisonValidator extends ConstraintValidator
return;
}
if (!$this->compareValues($value, $constraint->value, $constraint)) {
if (!$this->compareValues($value, $constraint->value)) {
$this->context->addViolation($constraint->message, array(
'{{ value }}' => $this->valueToString($constraint->value),
'{{ compared_value }}' => $this->valueToString($constraint->value),

View File

@ -21,7 +21,7 @@ class ElementMetadataTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
$this->metadata = new TestElementMetadata('Symfony\Component\Validator\Tests\Fixtures\Entity');
$this->metadata = new TestElementMetadata();
}
protected function tearDown()

View File

@ -108,7 +108,7 @@ class Validator implements ValidatorInterface
? '"'.$containingValue.'"'
: 'the value of type '.gettype($containingValue);
throw new ValidatorException(sprintf('The metadata for '.$valueAsString.' does not support properties.'));
throw new ValidatorException(sprintf('The metadata for %s does not support properties.', $valueAsString));
}
foreach ($this->resolveGroups($groups) as $group) {