Merge branch '2.3' into 2.4

* 2.3:
  Revert PHPUnit version, revert APC configuration
  removed APC on the CLI for Travis as it does not work well with PHPUnit and Composer anyway
  [Security] Replace exception mocks with actual exception instances.
  Remove an unused argument.
  Use `Filesystem::chmod` instead of `chmod` when dumping file
  [Form] Added test for disabling buttons
  [Form] Added check for parent disabled status in Button form elements
  Fixes URL validator to accept single part urls
  tweaked Travis configuration to get more tests running
  fixed float comparison in unit tests for HHVM
  upgraded PHPUnit to version 4 for better HHVM support
  [Process] fixed HHVM usage on the CLI
  Fix class names in ApcUniversalClassLoader tests.
  fixed the profiler when an uncalled listener throws an exception when instantiated
  fixed CS
  Added test case for 4c6a2d15095c13b2a35751b2b2712b183be489c4
  Fixed bug in ChoiceType triggering a warning when not using utf-8
  fixed CS
  Avoid levenshtein comparison when using ContainerBuilder.

Conflicts:
	src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php
	src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php
This commit is contained in:
Fabien Potencier 2014-04-03 07:23:50 +02:00
commit 785e82f814
25 changed files with 257 additions and 100 deletions

View File

@ -21,6 +21,7 @@ before_script:
- sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" ] && [ $(php -r "echo PHP_MINOR_VERSION;") -le 4 ]; then echo "extension = apc.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi;'
- sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then echo "extension = memcached.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi;'
- sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then echo "extension = memcache.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi;'
- sudo locale-gen fr_FR.UTF-8 && sudo update-locale
- COMPOSER_ROOT_VERSION=dev-master composer --prefer-source --dev install
script:

View File

@ -14,6 +14,7 @@ namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\Filesystem\Filesystem;
class CompilerDebugDumpPass implements CompilerPassInterface
@ -24,8 +25,11 @@ class CompilerDebugDumpPass implements CompilerPassInterface
$filesystem = new Filesystem();
$filesystem->dumpFile($filename, implode("\n", $container->getCompiler()->getLog()), null);
// discard chmod failure (some filesystem may not support it)
@chmod($filename, 0666 & ~umask());
try {
$filesystem->chmod($filename, 0666, umask());
} catch (IOException $e) {
// discard chmod failure (some filesystem may not support it)
}
}
public static function getCompilerLogFilename(ContainerInterface $container)

View File

@ -14,6 +14,7 @@ namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Dumper\XmlDumper;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\Filesystem\Filesystem;
/**
@ -31,7 +32,10 @@ class ContainerBuilderDebugDumpPass implements CompilerPassInterface
$filename = $container->getParameter('debug.container.dump');
$filesystem = new Filesystem();
$filesystem->dumpFile($filename, $dumper->dump(), null);
// discard chmod failure (some filesystem may not support it)
@chmod($filename, 0666 & ~umask());
try {
$filesystem->chmod($filename, 0666, umask());
} catch (IOException $e) {
// discard chmod failure (some filesystem may not support it)
}
}
}

View File

@ -36,9 +36,9 @@
{% endfor %}
</table>
{% if collector.notcalledlisteners %}
<h2>Not Called Listeners</h2>
<h2>Not Called Listeners</h2>
{% if collector.notcalledlisteners %}
<table>
<tr>
<th>Event name</th>
@ -52,6 +52,17 @@
</tr>
{% endfor %}
</table>
{% else %}
<p>
<strong>No uncalled listeners</strong>.
</p>
<p>
All listeners were called for this request or an error occurred
when trying to collect uncalled listeners (in which case check the
logs to get more information).
</p>
{% endif %}
{% endblock %}

View File

@ -58,10 +58,8 @@ class ApcUniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
public function getLoadClassTests()
{
return array(
array('\\Apc\\Namespaced\\Foo', '\\Apc\\Namespaced\\Foo', '->loadClass() loads Apc\Namespaced\Foo class'),
array('\\Apc\\Namespaced\\Foo', 'Apc\\Namespaced\\Foo', '->loadClass() loads Apc\Namespaced\Foo class'),
array('Apc_Pearlike_Foo', 'Apc_Pearlike_Foo', '->loadClass() loads Apc_Pearlike_Foo class'),
array('\\Apc\\Namespaced\\Bar', '\\Apc\\Namespaced\\Bar', '->loadClass() loads Apc\Namespaced\Bar class with a leading slash'),
array('Apc_Pearlike_Bar', '\\Apc_Pearlike_Bar', '->loadClass() loads Apc_Pearlike_Bar class with a leading slash'),
);
}
@ -82,9 +80,9 @@ class ApcUniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
public function getLoadClassFromFallbackTests()
{
return array(
array('\\Apc\\Namespaced\\Baz', '\\Apc\\Namespaced\\Baz', '->loadClass() loads Apc\Namespaced\Baz class'),
array('\\Apc\\Namespaced\\Baz', 'Apc\\Namespaced\\Baz', '->loadClass() loads Apc\Namespaced\Baz class'),
array('Apc_Pearlike_Baz', 'Apc_Pearlike_Baz', '->loadClass() loads Apc_Pearlike_Baz class'),
array('\\Apc\\Namespaced\\FooBar', '\\Apc\\Namespaced\\FooBar', '->loadClass() loads Apc\Namespaced\Baz class from fallback dir'),
array('\\Apc\\Namespaced\\FooBar', 'Apc\\Namespaced\\FooBar', '->loadClass() loads Apc\Namespaced\Baz class from fallback dir'),
array('Apc_Pearlike_FooBar', 'Apc_Pearlike_FooBar', '->loadClass() loads Apc_Pearlike_Baz class from fallback dir'),
);
}
@ -110,7 +108,7 @@ class ApcUniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
'Apc\\NamespaceCollision\\A' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha',
'Apc\\NamespaceCollision\\A\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/beta',
),
'\Apc\NamespaceCollision\A\Foo',
'Apc\NamespaceCollision\A\Foo',
'->loadClass() loads NamespaceCollision\A\Foo from alpha.',
),
array(
@ -118,7 +116,7 @@ class ApcUniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
'Apc\\NamespaceCollision\\A\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/beta',
'Apc\\NamespaceCollision\\A' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha',
),
'\Apc\NamespaceCollision\A\Bar',
'Apc\NamespaceCollision\A\Bar',
'->loadClass() loads NamespaceCollision\A\Bar from alpha.',
),
array(
@ -126,7 +124,7 @@ class ApcUniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
'Apc\\NamespaceCollision\\A' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha',
'Apc\\NamespaceCollision\\A\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/beta',
),
'\Apc\NamespaceCollision\A\B\Foo',
'Apc\NamespaceCollision\A\B\Foo',
'->loadClass() loads NamespaceCollision\A\B\Foo from beta.',
),
array(
@ -134,7 +132,7 @@ class ApcUniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
'Apc\\NamespaceCollision\\A\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/beta',
'Apc\\NamespaceCollision\\A' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha',
),
'\Apc\NamespaceCollision\A\B\Bar',
'Apc\NamespaceCollision\A\B\Bar',
'->loadClass() loads NamespaceCollision\A\B\Bar from beta.',
),
);

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Config;
use Symfony\Component\Config\Resource\ResourceInterface;
use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\Filesystem\Filesystem;
/**
@ -93,14 +94,23 @@ class ConfigCache
*/
public function write($content, array $metadata = null)
{
$mode = 0666 & ~umask();
$mode = 0666;
$umask = umask();
$filesystem = new Filesystem();
$filesystem->dumpFile($this->file, $content, null);
@chmod($this->file, $mode);
try {
$filesystem->chmod($this->file, $mode, $umask);
} catch (IOException $e) {
// discard chmod failure (some filesystem may not support it)
}
if (null !== $metadata && true === $this->debug) {
$filesystem->dumpFile($this->getMetaFile(), serialize($metadata), null);
@chmod($this->getMetaFile(), $mode);
try {
$filesystem->chmod($this->getMetaFile(), $mode, $umask);
} catch (IOException $e) {
// discard chmod failure (some filesystem may not support it)
}
}
}

View File

@ -460,51 +460,45 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
{
$id = strtolower($id);
if ($service = parent::get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE)) {
return $service;
}
if (isset($this->loading[$id])) {
throw new LogicException(sprintf('The service "%s" has a circular reference to itself.', $id), 0, $e);
}
if (!$this->hasDefinition($id) && isset($this->aliasDefinitions[$id])) {
return $this->get($this->aliasDefinitions[$id]);
}
try {
return parent::get($id, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE);
} catch (InactiveScopeException $e) {
$definition = $this->getDefinition($id);
} catch (InvalidArgumentException $e) {
if (ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) {
return null;
}
throw $e;
} catch (InvalidArgumentException $e) {
if (isset($this->loading[$id])) {
throw new LogicException(sprintf('The service "%s" has a circular reference to itself.', $id), 0, $e);
}
}
if (!$this->hasDefinition($id) && isset($this->aliasDefinitions[$id])) {
return $this->get($this->aliasDefinitions[$id]);
}
try {
$definition = $this->getDefinition($id);
} catch (InvalidArgumentException $e) {
if (ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) {
return null;
}
throw $e;
}
$this->loading[$id] = true;
try {
$service = $this->createService($definition, $id);
} catch (\Exception $e) {
unset($this->loading[$id]);
if ($e instanceof InactiveScopeException && self::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) {
return null;
}
throw $e;
}
$this->loading[$id] = true;
try {
$service = $this->createService($definition, $id);
} catch (\Exception $e) {
unset($this->loading[$id]);
return $service;
if ($e instanceof InactiveScopeException && self::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) {
return null;
}
throw $e;
}
unset($this->loading[$id]);
return $service;
}
/**

View File

@ -142,8 +142,19 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface
*/
public function getNotCalledListeners()
{
try {
$allListeners = $this->getListeners();
} catch (\Exception $e) {
if (null !== $this->logger) {
$this->logger->info(sprintf('An exception was thrown while getting the uncalled listeners (%s)', $e->getMessage()), array('exception' => $e));
}
// unable to retrieve the uncalled listeners
return array();
}
$notCalled = array();
foreach ($this->getListeners() as $eventName => $listeners) {
foreach ($allListeners as $eventName => $listeners) {
foreach ($listeners as $listener) {
$called = false;
if (isset($this->called[$eventName])) {

View File

@ -321,7 +321,11 @@ class Button implements \IteratorAggregate, FormInterface
*/
public function isDisabled()
{
return $this->config->getDisabled();
if (null === $this->parent || !$this->parent->isDisabled()) {
return $this->config->getDisabled();
}
return true;
}
/**

View File

@ -252,6 +252,8 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
public function setAttribute($name, $value)
{
$this->attributes[$name] = $value;
return $this;
}
/**
@ -260,6 +262,8 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
public function setAttributes(array $attributes)
{
$this->attributes = $attributes;
return $this;
}
/**
@ -286,6 +290,8 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
public function setDisabled($disabled)
{
$this->disabled = $disabled;
return $this;
}
/**
@ -410,6 +416,8 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
public function setType(ResolvedFormTypeInterface $type)
{
$this->type = $type;
return $this;
}
/**

View File

@ -166,7 +166,7 @@ class ChoiceType extends AbstractType
$choices = null !== $options['choices'] ? $options['choices'] : array();
// Reuse existing choice lists in order to increase performance
$hash = hash('sha256', json_encode(array($choices, $options['preferred_choices'])));
$hash = hash('sha256', serialize(array($choices, $options['preferred_choices'])));
if (!isset($choiceListCache[$hash])) {
$choiceListCache[$hash] = new SimpleChoiceList($choices, $options['preferred_choices']);

View File

@ -0,0 +1,70 @@
<?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\Form\Tests;
use Symfony\Component\Form\ButtonBuilder;
use Symfony\Component\Form\FormBuilder;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class ButtonTest extends \PHPUnit_Framework_TestCase
{
private $dispatcher;
private $factory;
protected function setUp()
{
$this->dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
$this->factory = $this->getMock('Symfony\Component\Form\FormFactoryInterface');
}
/**
* @dataProvider getDisabledStates
*/
public function testDisabledIfParentIsDisabled($parentDisabled, $buttonDisabled, $result)
{
$form = $this->getFormBuilder('form')
->setDisabled($parentDisabled)
->getForm();
$button = $this->getButtonBuilder('button')
->setDisabled($buttonDisabled)
->getForm();
$button->setParent($form);
$this->assertSame($result, $button->isDisabled());
}
public function getDisabledStates()
{
return array(
// parent, button, result
array(true, true, true),
array(true, false, true),
array(false, true, true),
array(false, false, false),
);
}
private function getButtonBuilder($name)
{
return new ButtonBuilder($name);
}
private function getFormBuilder($name)
{
return new FormBuilder($name, null, $this->dispatcher, $this->factory);
}
}

View File

@ -380,7 +380,7 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
$form->submit('foobar');
$this->assertSame(null, $form->getData());
$this->assertNull($form->getData());
$this->assertSame('foobar', $form->getViewData());
$this->assertEmpty($form->getExtraData());
$this->assertFalse($form->isSynchronized());
@ -445,7 +445,7 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
$form->submit('foobar');
$this->assertSame(null, $form->getData());
$this->assertNull($form->getData());
$this->assertSame('foobar', $form->getViewData());
$this->assertEmpty($form->getExtraData());
$this->assertFalse($form->isSynchronized());
@ -1216,6 +1216,47 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
));
}
// https://github.com/symfony/symfony/issues/10409
public function testReuseNonUtf8ChoiceLists()
{
$form1 = $this->factory->createNamed('name', 'choice', null, array(
'choices' => array(
'meter' => 'm',
'millimeter' => 'mm',
'micrometer' => chr(181).'meter',
),
));
$form2 = $this->factory->createNamed('name', 'choice', null, array(
'choices' => array(
'meter' => 'm',
'millimeter' => 'mm',
'micrometer' => chr(181).'meter',
),
));
$form3 = $this->factory->createNamed('name', 'choice', null, array(
'choices' => array(
'meter' => 'm',
'millimeter' => 'mm',
'micrometer' => null,
),
));
// $form1 and $form2 use the same ChoiceList
$this->assertSame(
$form1->getConfig()->getOption('choice_list'),
$form2->getConfig()->getOption('choice_list')
);
// $form3 doesn't, but used to use the same when using json_encode()
// instead of serialize for the hashing algorithm
$this->assertNotSame(
$form1->getConfig()->getOption('choice_list'),
$form3->getConfig()->getOption('choice_list')
);
}
public function testInitializeWithDefaultObjectChoice()
{
$obj1 = (object) array('value' => 'a', 'label' => 'A');

View File

@ -170,34 +170,28 @@ class SimpleFormTest extends AbstractFormTest
$this->assertFalse($child->isRequired());
}
public function testAlwaysDisabledIfParentDisabled()
/**
* @dataProvider getDisabledStates
*/
public function testAlwaysDisabledIfParentDisabled($parentDisabled, $disabled, $result)
{
$parent = $this->getBuilder()->setDisabled(true)->getForm();
$child = $this->getBuilder()->setDisabled(false)->getForm();
$parent = $this->getBuilder()->setDisabled($parentDisabled)->getForm();
$child = $this->getBuilder()->setDisabled($disabled)->getForm();
$child->setParent($parent);
$this->assertTrue($child->isDisabled());
$this->assertSame($result, $child->isDisabled());
}
public function testDisabled()
public function getDisabledStates()
{
$parent = $this->getBuilder()->setDisabled(false)->getForm();
$child = $this->getBuilder()->setDisabled(true)->getForm();
$child->setParent($parent);
$this->assertTrue($child->isDisabled());
}
public function testNotDisabled()
{
$parent = $this->getBuilder()->setDisabled(false)->getForm();
$child = $this->getBuilder()->setDisabled(false)->getForm();
$child->setParent($parent);
$this->assertFalse($child->isDisabled());
return array(
// parent, button, result
array(true, true, true),
array(true, false, true),
array(false, true, true),
array(false, false, false),
);
}
public function testGetRootReturnsRootOfParent()

View File

@ -522,7 +522,7 @@ class HttpCache implements HttpKernelInterface, TerminableInterface
protected function lock(Request $request, Response $entry)
{
// try to acquire a lock to call the backend
$lock = $this->store->lock($request, $entry);
$lock = $this->store->lock($request);
// there is already another process calling the backend
if (true !== $lock) {

View File

@ -780,7 +780,7 @@ abstract class AbstractNumberFormatterTest extends \PHPUnit_Framework_TestCase
{
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
$parsedValue = $formatter->parse($value, NumberFormatter::TYPE_DOUBLE);
$this->assertSame($expectedValue, $parsedValue);
$this->assertEquals($expectedValue, $parsedValue, '', 0.001);
}
public function parseTypeDoubleProvider()

View File

@ -34,8 +34,8 @@ class PhpExecutableFinder
public function find()
{
// HHVM support
if (defined('HHVM_VERSION') && false !== $hhvm = getenv('PHP_BINARY')) {
return $hhvm;
if (defined('HHVM_VERSION')) {
return (false !== ($hhvm = getenv('PHP_BINARY')) ? $hhvm : PHP_BINARY).' --php';
}
// PHP_BINARY return the current sapi executable

View File

@ -64,7 +64,7 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
$this->assertSame('MyBundle:Blog:show', $route->getDefault('_controller'));
$this->assertSame('\w+', $route->getRequirement('slug'));
$this->assertSame('en|fr|de', $route->getRequirement('_locale'));
$this->assertSame(null, $route->getDefault('slug'));
$this->assertNull($route->getDefault('slug'));
$this->assertSame('RouteCompiler', $route->getOption('compiler_class'));
}

View File

@ -129,7 +129,7 @@ class AuthenticationProviderManagerTest extends \PHPUnit_Framework_TestCase
} elseif (null !== $exception) {
$provider->expects($this->once())
->method('authenticate')
->will($this->throwException($this->getMock($exception, null, array(), '', false)))
->will($this->throwException($this->getMock($exception, null, array(), '', true)))
;
}

View File

@ -14,6 +14,7 @@ namespace Symfony\Component\Security\Core\Tests\Authentication\Provider;
use Symfony\Component\Security\Core\Encoder\PlaintextPasswordEncoder;
use Symfony\Component\Security\Core\Authentication\Provider\DaoAuthenticationProvider;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
class DaoAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
{
@ -37,7 +38,7 @@ class DaoAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
$userProvider = $this->getMock('Symfony\\Component\\Security\\Core\\User\\UserProviderInterface');
$userProvider->expects($this->once())
->method('loadUserByUsername')
->will($this->throwException($this->getMock('Symfony\\Component\\Security\\Core\\Exception\\UsernameNotFoundException', null, array(), '', false)))
->will($this->throwException(new UsernameNotFoundException()))
;
$provider = new DaoAuthenticationProvider($userProvider, $this->getMock('Symfony\\Component\\Security\\Core\\User\\UserCheckerInterface'), 'key', $this->getMock('Symfony\\Component\\Security\\Core\\Encoder\\EncoderFactoryInterface'));
@ -55,7 +56,7 @@ class DaoAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
$userProvider = $this->getMock('Symfony\\Component\\Security\\Core\\User\\UserProviderInterface');
$userProvider->expects($this->once())
->method('loadUserByUsername')
->will($this->throwException($this->getMock('RuntimeException', null, array(), '', false)))
->will($this->throwException(new \RuntimeException()))
;
$provider = new DaoAuthenticationProvider($userProvider, $this->getMock('Symfony\\Component\\Security\\Core\\User\\UserCheckerInterface'), 'key', $this->getMock('Symfony\\Component\\Security\\Core\\Encoder\\EncoderFactoryInterface'));

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Security\Core\Tests\Authentication\Provider;
use Symfony\Component\Security\Core\Authentication\Provider\PreAuthenticatedAuthenticationProvider;
use Symfony\Component\Security\Core\Exception\LockedException;
class PreAuthenticatedAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
{
@ -79,7 +80,7 @@ class PreAuthenticatedAuthenticationProviderTest extends \PHPUnit_Framework_Test
$userChecker = $this->getMock('Symfony\Component\Security\Core\User\UserCheckerInterface');
$userChecker->expects($this->once())
->method('checkPostAuth')
->will($this->throwException($this->getMock('Symfony\Component\Security\Core\Exception\LockedException', null, array(), '', false)))
->will($this->throwException(new LockedException()))
;
$provider = $this->getProvider($user, $userChecker);

View File

@ -12,7 +12,7 @@
namespace Symfony\Component\Security\Core\Tests\Authentication\Provider;
use Symfony\Component\Security\Core\Authentication\Provider\RememberMeAuthenticationProvider;
use Symfony\Component\Security\Core\Authentication\Token\RememberMeToken;
use Symfony\Component\Security\Core\Exception\AccountExpiredException;
use Symfony\Component\Security\Core\Role\Role;
class RememberMeAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
@ -52,7 +52,7 @@ class RememberMeAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
$userChecker = $this->getMock('Symfony\Component\Security\Core\User\UserCheckerInterface');
$userChecker->expects($this->once())
->method('checkPostAuth')
->will($this->throwException($this->getMock('Symfony\Component\Security\Core\Exception\AccountExpiredException', null, array(), '', false)))
->will($this->throwException(new AccountExpiredException()))
;
$provider = $this->getProvider($userChecker);

View File

@ -11,10 +11,12 @@
namespace Symfony\Component\Security\Core\Tests\Authentication\Provider;
use Symfony\Component\Security\Core\Authentication\Provider\UserAuthenticationProvider;
use Symfony\Component\Security\Core\Exception\AccountExpiredException;
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
use Symfony\Component\Security\Core\Exception\CredentialsExpiredException;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\Role\Role;
use Symfony\Component\Security\Core\Role\SwitchUserRole;
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
class UserAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
{
@ -41,7 +43,7 @@ class UserAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
$provider = $this->getProvider(false, false);
$provider->expects($this->once())
->method('retrieveUser')
->will($this->throwException($this->getMock('Symfony\Component\Security\Core\Exception\UsernameNotFoundException', null, array(), '', false)))
->will($this->throwException(new UsernameNotFoundException()))
;
$provider->authenticate($this->getSupportedToken());
@ -55,7 +57,7 @@ class UserAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
$provider = $this->getProvider(false, true);
$provider->expects($this->once())
->method('retrieveUser')
->will($this->throwException($this->getMock('Symfony\Component\Security\Core\Exception\UsernameNotFoundException', null, array(), '', false)))
->will($this->throwException(new UsernameNotFoundException()))
;
$provider->authenticate($this->getSupportedToken());
@ -83,7 +85,7 @@ class UserAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
$userChecker = $this->getMock('Symfony\Component\Security\Core\User\UserCheckerInterface');
$userChecker->expects($this->once())
->method('checkPreAuth')
->will($this->throwException($this->getMock('Symfony\Component\Security\Core\Exception\CredentialsExpiredException', null, array(), '', false)))
->will($this->throwException(new CredentialsExpiredException()))
;
$provider = $this->getProvider($userChecker);
@ -103,7 +105,7 @@ class UserAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
$userChecker = $this->getMock('Symfony\Component\Security\Core\User\UserCheckerInterface');
$userChecker->expects($this->once())
->method('checkPostAuth')
->will($this->throwException($this->getMock('Symfony\Component\Security\Core\Exception\AccountExpiredException', null, array(), '', false)))
->will($this->throwException(new AccountExpiredException()))
;
$provider = $this->getProvider($userChecker);
@ -128,7 +130,7 @@ class UserAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
;
$provider->expects($this->once())
->method('checkAuthentication')
->will($this->throwException($this->getMock('Symfony\Component\Security\Core\Exception\BadCredentialsException', null, array(), '', false)))
->will($this->throwException(new BadCredentialsException()))
;
$provider->authenticate($this->getSupportedToken());

View File

@ -25,10 +25,10 @@ class UrlValidator extends ConstraintValidator
const PATTERN = '~^
(%s):// # protocol
(
([\pL\pN\pS-]+\.)+([\pL]|xn\-\-[\pL\pN-]+)+ # a domain name
| # or
\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} # a IP address
| # or
([\pL\pN\pS-\.])+(\.?([\pL]|xn\-\-[\pL\pN-]+)+\.?) # a domain name
| # or
\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} # a IP address
| # or
\[
(?:(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){6})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:::(?:(?:(?:[0-9a-f]{1,4})):){5})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:[0-9a-f]{1,4})))?::(?:(?:(?:[0-9a-f]{1,4})):){4})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,1}(?:(?:[0-9a-f]{1,4})))?::(?:(?:(?:[0-9a-f]{1,4})):){3})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,2}(?:(?:[0-9a-f]{1,4})))?::(?:(?:(?:[0-9a-f]{1,4})):){2})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,3}(?:(?:[0-9a-f]{1,4})))?::(?:(?:[0-9a-f]{1,4})):)(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,4}(?:(?:[0-9a-f]{1,4})))?::)(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,5}(?:(?:[0-9a-f]{1,4})))?::)(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,6}(?:(?:[0-9a-f]{1,4})))?::))))
\] # a IPv6 address

View File

@ -72,6 +72,7 @@ class UrlValidatorTest extends \PHPUnit_Framework_TestCase
return array(
array('http://a.pl'),
array('http://www.google.com'),
array('http://www.google.com.'),
array('http://www.google.museum'),
array('https://google.com/'),
array('https://google.com:80/'),
@ -85,6 +86,7 @@ class UrlValidatorTest extends \PHPUnit_Framework_TestCase
array('http://symfony.com/#?'),
array('http://www.symfony.com/doc/current/book/validation.html#supported-constraints'),
array('http://very.long.domain.name.com/'),
array('http://localhost/'),
array('http://127.0.0.1/'),
array('http://127.0.0.1:80/'),
array('http://[::1]/'),
@ -152,6 +154,7 @@ class UrlValidatorTest extends \PHPUnit_Framework_TestCase
array('http://127.0.0.1:aa/'),
array('ftp://[::1]/'),
array('http://[::1'),
array('http://hello.☎/'),
);
}