diff --git a/composer.json b/composer.json index 9677a86460..5345b90df8 100644 --- a/composer.json +++ b/composer.json @@ -90,7 +90,8 @@ "symfony/phpunit-bridge": "~3.2", "symfony/polyfill-apcu": "~1.1", "symfony/security-acl": "~2.8|~3.0", - "phpdocumentor/reflection-docblock": "^3.0" + "phpdocumentor/reflection-docblock": "^3.0", + "sensio/framework-extra-bundle": "^3.0.2" }, "conflict": { "phpdocumentor/reflection-docblock": "<3.0", diff --git a/src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php b/src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php index 4d0c7e1f63..2881ed5f72 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php @@ -264,6 +264,23 @@ class UniqueEntityValidatorTest extends AbstractConstraintValidatorTest ->assertRaised(); } + /** + * @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException + */ + public function testAllConfiguredFieldsAreCheckedOfBeingMappedByDoctrineWithIgnoreNullEnabled() + { + $constraint = new UniqueEntity(array( + 'message' => 'myMessage', + 'fields' => array('name', 'name2'), + 'em' => self::EM_NAME, + 'ignoreNull' => true, + )); + + $entity1 = new SingleIntIdEntity(1, null); + + $this->validator->validate($entity1, $constraint); + } + public function testValidateUniquenessWithValidCustomErrorPath() { $constraint = new UniqueEntity(array( diff --git a/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php b/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php index 5f9d06f155..b079770c6b 100644 --- a/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php +++ b/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php @@ -86,12 +86,14 @@ class UniqueEntityValidator extends ConstraintValidator throw new ConstraintDefinitionException(sprintf('The field "%s" is not mapped by Doctrine, so it cannot be validated for uniqueness.', $fieldName)); } - $criteria[$fieldName] = $class->reflFields[$fieldName]->getValue($entity); + $fieldValue = $class->reflFields[$fieldName]->getValue($entity); - if ($constraint->ignoreNull && null === $criteria[$fieldName]) { - return; + if ($constraint->ignoreNull && null === $fieldValue) { + continue; } + $criteria[$fieldName] = $fieldValue; + if (null !== $criteria[$fieldName] && $class->hasAssociation($fieldName)) { /* Ensure the Proxy is initialized before using reflection to * read its identifiers. This is necessary because the wrapped @@ -101,6 +103,12 @@ class UniqueEntityValidator extends ConstraintValidator } } + // skip validation if there are no criteria (this can happen when the + // "ignoreNull" option is enabled and fields to be checked are null + if (empty($criteria)) { + return; + } + if (null !== $constraint->entityClass) { /* Retrieve repository from given entity name. * We ensure the retrieved repository can handle the entity diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AnnotatedControllerTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AnnotatedControllerTest.php new file mode 100644 index 0000000000..2fdbef8839 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AnnotatedControllerTest.php @@ -0,0 +1,39 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\FrameworkBundle\Tests\Functional; + +class AnnotatedControllerTest extends WebTestCase +{ + /** + * @dataProvider getRoutes + */ + public function testAnnotatedController($path, $expectedValue) + { + $client = $this->createClient(array('test_case' => 'AnnotatedController', 'root_config' => 'config.yml')); + $client->request('GET', '/annotated'.$path); + + $this->assertSame(200, $client->getResponse()->getStatusCode()); + $this->assertSame($expectedValue, $client->getResponse()->getContent()); + } + + public function getRoutes() + { + return array( + array('/null_request', 'Symfony\Component\HttpFoundation\Request'), + array('/null_argument', ''), + array('/null_argument_with_route_param', ''), + array('/null_argument_with_route_param/value', 'value'), + array('/argument_with_route_param_and_default', 'value'), + array('/argument_with_route_param_and_default/custom', 'custom'), + ); + } +} diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/AnnotatedController.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/AnnotatedController.php new file mode 100644 index 0000000000..98a3ace982 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/AnnotatedController.php @@ -0,0 +1,51 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller; + +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Routing\Annotation\Route; + +class AnnotatedController +{ + /** + * @Route("/null_request", name="null_request") + */ + public function requestDefaultNullAction(Request $request = null) + { + return new Response($request ? get_class($request) : null); + } + + /** + * @Route("/null_argument", name="null_argument") + */ + public function argumentDefaultNullWithoutRouteParamAction($value = null) + { + return new Response($value); + } + + /** + * @Route("/null_argument_with_route_param/{value}", name="null_argument_with_route_param") + */ + public function argumentDefaultNullWithRouteParamAction($value = null) + { + return new Response($value); + } + + /** + * @Route("/argument_with_route_param_and_default/{value}", defaults={"value": "value"}, name="argument_with_route_param_and_default") + */ + public function argumentWithoutDefaultWithRouteParamAndDefaultAction($value) + { + return new Response($value); + } +} diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AnnotatedController/bundles.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AnnotatedController/bundles.php new file mode 100644 index 0000000000..f3290d7728 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AnnotatedController/bundles.php @@ -0,0 +1,20 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestBundle; +use Symfony\Bundle\FrameworkBundle\FrameworkBundle; +use Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle; + +return array( + new FrameworkBundle(), + new TestBundle(), + new SensioFrameworkExtraBundle(), +); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AnnotatedController/config.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AnnotatedController/config.yml new file mode 100644 index 0000000000..377d3e7852 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AnnotatedController/config.yml @@ -0,0 +1,2 @@ +imports: + - { resource: ../config/default.yml } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AnnotatedController/routing.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AnnotatedController/routing.yml new file mode 100644 index 0000000000..ebd18a0a4c --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AnnotatedController/routing.yml @@ -0,0 +1,4 @@ +annotated_controller: + prefix: /annotated + resource: "@TestBundle/Controller/AnnotatedController.php" + type: annotation diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json index 34c0b2fe69..5de960f5dd 100644 --- a/src/Symfony/Bundle/FrameworkBundle/composer.json +++ b/src/Symfony/Bundle/FrameworkBundle/composer.json @@ -27,7 +27,9 @@ "symfony/polyfill-mbstring": "~1.0", "symfony/filesystem": "~2.8|~3.0", "symfony/finder": "~2.8|~3.0", - "symfony/routing": "~3.0", + "symfony/routing": "~3.1.10|~3.2.3", + "symfony/security-core": "~2.8|~3.0", + "symfony/security-csrf": "~2.8|~3.0", "symfony/stopwatch": "~2.8|~3.0", "doctrine/cache": "~1.0" }, @@ -52,7 +54,8 @@ "symfony/property-info": "~2.8|~3.0", "doctrine/annotations": "~1.0", "phpdocumentor/reflection-docblock": "^3.0", - "twig/twig": "~1.26|~2.0" + "twig/twig": "~1.26|~2.0", + "sensio/framework-extra-bundle": "^3.0.2" }, "conflict": { "phpdocumentor/reflection-docblock": "<3.0", diff --git a/src/Symfony/Component/Debug/ErrorHandler.php b/src/Symfony/Component/Debug/ErrorHandler.php index f5c842d2cc..6805ef156a 100644 --- a/src/Symfony/Component/Debug/ErrorHandler.php +++ b/src/Symfony/Component/Debug/ErrorHandler.php @@ -352,12 +352,10 @@ class ErrorHandler /** * Handles errors by filtering then logging them according to the configured bit fields. * - * @param int $type One of the E_* constants + * @param int $type One of the E_* constants * @param string $message * @param string $file * @param int $line - * @param array $context - * @param array $backtrace * * @return bool Returns false when no handling happens so that the PHP engine can handle the error itself * @@ -365,7 +363,7 @@ class ErrorHandler * * @internal */ - public function handleError($type, $message, $file, $line, array $context, array $backtrace = null) + public function handleError($type, $message, $file, $line) { // Level is the current error reporting level to manage silent error. // Strong errors are not authorized to be silenced. @@ -377,9 +375,20 @@ class ErrorHandler if (!$type || (!$log && !$throw)) { return $type && $log; } + $scope = $this->scopedErrors & $type; - if (isset($context['GLOBALS']) && ($this->scopedErrors & $type)) { - unset($context['GLOBALS']); + if (4 < $numArgs = func_num_args()) { + $context = $scope ? (func_get_arg(4) ?: array()) : array(); + $backtrace = 5 < $numArgs ? func_get_arg(5) : null; // defined on HHVM + } else { + $context = array(); + $backtrace = null; + } + + if (isset($context['GLOBALS']) && $scope) { + $e = $context; // Whatever the signature of the method, + unset($e['GLOBALS'], $context); // $context is always a reference in 5.3 + $context = $e; } if (null !== $backtrace && $type & E_ERROR) { @@ -399,7 +408,7 @@ class ErrorHandler } elseif (!$throw && !($type & $level)) { $errorAsException = new SilencedErrorContext($type, $file, $line); } else { - if ($this->scopedErrors & $type) { + if ($scope) { $errorAsException = new ContextErrorException($logMessage, 0, $type, $file, $line, $context); } else { $errorAsException = new \ErrorException($logMessage, 0, $type, $file, $line); diff --git a/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php b/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php index ae09ddab6f..fcb986383c 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php @@ -114,8 +114,10 @@ class AutowirePass implements CompilerPassInterface throw new RuntimeException(sprintf('Unable to autowire argument index %d ($%s) for the service "%s". If this is an object, give it a type-hint. Otherwise, specify this argument\'s value explicitly.', $index, $parameter->name, $id)); } - // specifically pass the default value - $arguments[$index] = $parameter->getDefaultValue(); + if (!array_key_exists($index, $arguments)) { + // specifically pass the default value + $arguments[$index] = $parameter->getDefaultValue(); + } continue; } diff --git a/src/Symfony/Component/DependencyInjection/Definition.php b/src/Symfony/Component/DependencyInjection/Definition.php index 283b0e9152..d8e954329f 100644 --- a/src/Symfony/Component/DependencyInjection/Definition.php +++ b/src/Symfony/Component/DependencyInjection/Definition.php @@ -198,6 +198,10 @@ class Definition */ public function replaceArgument($index, $argument) { + if (0 === count($this->arguments)) { + throw new OutOfBoundsException('Cannot replace arguments if none have been configured yet.'); + } + if ($index < 0 || $index > count($this->arguments) - 1) { throw new OutOfBoundsException(sprintf('The index "%d" is not in the range [0, %d].', $index, count($this->arguments) - 1)); } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php index 8fca41b603..212b93d972 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php @@ -494,6 +494,22 @@ class AutowirePassTest extends \PHPUnit_Framework_TestCase $this->assertTrue($container->hasDefinition('bar')); } + + public function testEmptyStringIsKept() + { + $container = new ContainerBuilder(); + + $container->register('a', __NAMESPACE__.'\A'); + $container->register('lille', __NAMESPACE__.'\Lille'); + $container->register('foo', __NAMESPACE__.'\MultipleArgumentsOptionalScalar') + ->setAutowired(true) + ->setArguments(array('', '')); + + $pass = new AutowirePass(); + $pass->process($container); + + $this->assertEquals(array(new Reference('a'), '', new Reference('lille')), $container->getDefinition('foo')->getArguments()); + } } class Foo diff --git a/src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php b/src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php index 6a85f8044b..9b89b33941 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php @@ -257,6 +257,7 @@ class DefinitionTest extends \PHPUnit_Framework_TestCase /** * @expectedException \OutOfBoundsException + * @expectedExceptionMessage The index "1" is not in the range [0, 0]. */ public function testReplaceArgumentShouldCheckBounds() { @@ -266,6 +267,16 @@ class DefinitionTest extends \PHPUnit_Framework_TestCase $def->replaceArgument(1, 'bar'); } + /** + * @expectedException \OutOfBoundsException + * @expectedExceptionMessage Cannot replace arguments if none have been configured yet. + */ + public function testReplaceArgumentWithoutExistingArgumentsShouldCheckBounds() + { + $def = new Definition('stdClass'); + $def->replaceArgument(0, 'bar'); + } + public function testSetGetProperties() { $def = new Definition('stdClass'); diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php index 9b33db2a65..e1f37c7aa5 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php @@ -69,10 +69,10 @@ class DateTypeTest extends TestCase public function testSubmitFromSingleTextDateTime() { - // we test against "de_AT", so we need the full implementation + // we test against "de_DE", so we need the full implementation IntlTestHelper::requireFullIntl($this, false); - \Locale::setDefault('de_AT'); + \Locale::setDefault('de_DE'); $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array( 'format' => \IntlDateFormatter::MEDIUM, @@ -90,10 +90,10 @@ class DateTypeTest extends TestCase public function testSubmitFromSingleTextString() { - // we test against "de_AT", so we need the full implementation + // we test against "de_DE", so we need the full implementation IntlTestHelper::requireFullIntl($this, false); - \Locale::setDefault('de_AT'); + \Locale::setDefault('de_DE'); $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array( 'format' => \IntlDateFormatter::MEDIUM, @@ -111,10 +111,10 @@ class DateTypeTest extends TestCase public function testSubmitFromSingleTextTimestamp() { - // we test against "de_AT", so we need the full implementation + // we test against "de_DE", so we need the full implementation IntlTestHelper::requireFullIntl($this, false); - \Locale::setDefault('de_AT'); + \Locale::setDefault('de_DE'); $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array( 'format' => \IntlDateFormatter::MEDIUM, @@ -134,10 +134,10 @@ class DateTypeTest extends TestCase public function testSubmitFromSingleTextRaw() { - // we test against "de_AT", so we need the full implementation + // we test against "de_DE", so we need the full implementation IntlTestHelper::requireFullIntl($this, false); - \Locale::setDefault('de_AT'); + \Locale::setDefault('de_DE'); $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array( 'format' => \IntlDateFormatter::MEDIUM, @@ -398,10 +398,10 @@ class DateTypeTest extends TestCase public function testSetDataWithNegativeTimezoneOffsetStringInput() { - // we test against "de_AT", so we need the full implementation + // we test against "de_DE", so we need the full implementation IntlTestHelper::requireFullIntl($this, false); - \Locale::setDefault('de_AT'); + \Locale::setDefault('de_DE'); $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array( 'format' => \IntlDateFormatter::MEDIUM, @@ -420,10 +420,10 @@ class DateTypeTest extends TestCase public function testSetDataWithNegativeTimezoneOffsetDateTimeInput() { - // we test against "de_AT", so we need the full implementation + // we test against "de_DE", so we need the full implementation IntlTestHelper::requireFullIntl($this, false); - \Locale::setDefault('de_AT'); + \Locale::setDefault('de_DE'); $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\DateType', null, array( 'format' => \IntlDateFormatter::MEDIUM, diff --git a/src/Symfony/Component/Intl/Util/IntlTestHelper.php b/src/Symfony/Component/Intl/Util/IntlTestHelper.php index 71fb4acdd7..c1e37a72ec 100644 --- a/src/Symfony/Component/Intl/Util/IntlTestHelper.php +++ b/src/Symfony/Component/Intl/Util/IntlTestHelper.php @@ -41,7 +41,7 @@ class IntlTestHelper // * the intl extension is loaded with version Intl::getIcuStubVersion() // * the intl extension is not loaded - if (($minimumIcuVersion || defined('HHVM_VERSION_ID')) && IcuVersion::compare(Intl::getIcuVersion(), $minimumIcuVersion, '!=', 1)) { + if (($minimumIcuVersion || defined('HHVM_VERSION_ID')) && IcuVersion::compare(Intl::getIcuVersion(), $minimumIcuVersion, '<', 1)) { $testCase->markTestSkipped('ICU version '.$minimumIcuVersion.' is required.'); } diff --git a/src/Symfony/Component/PropertyAccess/PropertyAccessor.php b/src/Symfony/Component/PropertyAccess/PropertyAccessor.php index 618007ef59..6019544a19 100644 --- a/src/Symfony/Component/PropertyAccess/PropertyAccessor.php +++ b/src/Symfony/Component/PropertyAccess/PropertyAccessor.php @@ -267,7 +267,7 @@ class PropertyAccessor implements PropertyAccessorInterface private static function throwInvalidArgumentException($message, $trace, $i) { if (isset($trace[$i]['file']) && __FILE__ === $trace[$i]['file']) { - $pos = strpos($message, $delim = 'must be of the type ') ?: strpos($message, $delim = 'must be an instance of '); + $pos = strpos($message, $delim = 'must be of the type ') ?: (strpos($message, $delim = 'must be an instance of ') ?: strpos($message, $delim = 'must implement interface ')); $pos += strlen($delim); $type = $trace[$i]['args'][0]; $type = is_object($type) ? get_class($type) : gettype($type); diff --git a/src/Symfony/Component/PropertyAccess/Tests/Fixtures/TypeHinted.php b/src/Symfony/Component/PropertyAccess/Tests/Fixtures/TypeHinted.php index ca4c5745ae..ce0f3d89aa 100644 --- a/src/Symfony/Component/PropertyAccess/Tests/Fixtures/TypeHinted.php +++ b/src/Symfony/Component/PropertyAccess/Tests/Fixtures/TypeHinted.php @@ -18,6 +18,11 @@ class TypeHinted { private $date; + /** + * @var \Countable + */ + private $countable; + public function setDate(\DateTime $date) { $this->date = $date; @@ -27,4 +32,20 @@ class TypeHinted { return $this->date; } + + /** + * @return \Countable + */ + public function getCountable() + { + return $this->countable; + } + + /** + * @param \Countable $countable + */ + public function setCountable(\Countable $countable) + { + $this->countable = $countable; + } } diff --git a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php index a3a82b0b63..33d4085b07 100644 --- a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php +++ b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php @@ -566,4 +566,15 @@ class PropertyAccessorTest extends \PHPUnit_Framework_TestCase $propertyAccessor->setValue($obj, 'publicGetSetter', 'baz'); $this->assertEquals('baz', $propertyAccessor->getValue($obj, 'publicGetSetter')); } + + /** + * @expectedException \Symfony\Component\PropertyAccess\Exception\InvalidArgumentException + * @expectedExceptionMessage Expected argument of type "Countable", "string" given + */ + public function testThrowTypeErrorWithInterface() + { + $object = new TypeHinted(); + + $this->propertyAccessor->setValue($object, 'countable', 'This is a string, \Countable expected.'); + } } diff --git a/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php b/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php index a7fc3259cd..8463673e2d 100644 --- a/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php +++ b/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php @@ -138,6 +138,11 @@ abstract class AnnotationClassLoader implements LoaderInterface } $defaults = array_replace($globals['defaults'], $annot->getDefaults()); + foreach ($method->getParameters() as $param) { + if (false !== strpos($globals['path'].$annot->getPath(), sprintf('{%s}', $param->getName())) && !isset($defaults[$param->getName()]) && $param->isDefaultValueAvailable()) { + $defaults[$param->getName()] = $param->getDefaultValue(); + } + } $requirements = array_replace($globals['requirements'], $annot->getRequirements()); $options = array_replace($globals['options'], $annot->getOptions()); $schemes = array_merge($globals['schemes'], $annot->getSchemes());