From cd914209bd3acbc637c4b435626f003696ebacb7 Mon Sep 17 00:00:00 2001
From: Pascal Montoya <>
Date: Fri, 6 Apr 2018 07:52:15 +0200
Subject: [PATCH 1/3] [Validator] Fix LazyLoadingMetadataFactory with PSR6Cache
for non classname if tested values isn't an existing class
---
.../Factory/LazyLoadingMetadataFactory.php | 8 ++++----
.../Factory/LazyLoadingMetadataFactoryTest.php | 15 +++++++++++++++
2 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/src/Symfony/Component/Validator/Mapping/Factory/LazyLoadingMetadataFactory.php b/src/Symfony/Component/Validator/Mapping/Factory/LazyLoadingMetadataFactory.php
index 1a4f3074b6..84375ec694 100644
--- a/src/Symfony/Component/Validator/Mapping/Factory/LazyLoadingMetadataFactory.php
+++ b/src/Symfony/Component/Validator/Mapping/Factory/LazyLoadingMetadataFactory.php
@@ -90,6 +90,10 @@ class LazyLoadingMetadataFactory implements MetadataFactoryInterface
return $this->loadedClasses[$class];
}
+ if (!class_exists($class) && !interface_exists($class)) {
+ throw new NoSuchMetadataException(sprintf('The class or interface "%s" does not exist.', $class));
+ }
+
if (null !== $this->cache && false !== ($metadata = $this->cache->read($class))) {
// Include constraints from the parent class
$this->mergeConstraints($metadata);
@@ -97,10 +101,6 @@ class LazyLoadingMetadataFactory implements MetadataFactoryInterface
return $this->loadedClasses[$class] = $metadata;
}
- if (!class_exists($class) && !interface_exists($class)) {
- throw new NoSuchMetadataException(sprintf('The class or interface "%s" does not exist.', $class));
- }
-
$metadata = new ClassMetadata($class);
if (null !== $this->loader) {
diff --git a/src/Symfony/Component/Validator/Tests/Mapping/Factory/LazyLoadingMetadataFactoryTest.php b/src/Symfony/Component/Validator/Tests/Mapping/Factory/LazyLoadingMetadataFactoryTest.php
index b5d1a9dc84..de6852271e 100644
--- a/src/Symfony/Component/Validator/Tests/Mapping/Factory/LazyLoadingMetadataFactoryTest.php
+++ b/src/Symfony/Component/Validator/Tests/Mapping/Factory/LazyLoadingMetadataFactoryTest.php
@@ -149,6 +149,21 @@ class LazyLoadingMetadataFactoryTest extends TestCase
$this->assertEquals($metadata, $factory->getMetadataFor(self::PARENT_CLASS));
}
+ /**
+ * @expectedException \Symfony\Component\Validator\Exception\NoSuchMetadataException
+ */
+ public function testNonClassNameStringValues()
+ {
+ $testedValue = 'error@example.com';
+ $loader = $this->getMockBuilder('Symfony\Component\Validator\Mapping\Loader\LoaderInterface')->getMock();
+ $cache = $this->getMockBuilder('Symfony\Component\Validator\Mapping\Cache\CacheInterface')->getMock();
+ $factory = new LazyLoadingMetadataFactory($loader, $cache);
+ $cache
+ ->expects($this->never())
+ ->method('read');
+ $factory->getMetadataFor($testedValue);
+ }
+
public function testMetadataCacheWithRuntimeConstraint()
{
$cache = $this->getMockBuilder('Symfony\Component\Validator\Mapping\Cache\CacheInterface')->getMock();
From 5198f435a047aad8d5ed119e918cf8c008ea65b7 Mon Sep 17 00:00:00 2001
From: Pascal Montoya
Date: Mon, 9 Apr 2018 10:29:56 +0200
Subject: [PATCH 2/3] Disable autoloader call on interface_exists check
---
.../Validator/Mapping/Factory/LazyLoadingMetadataFactory.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Symfony/Component/Validator/Mapping/Factory/LazyLoadingMetadataFactory.php b/src/Symfony/Component/Validator/Mapping/Factory/LazyLoadingMetadataFactory.php
index 84375ec694..e088caa897 100644
--- a/src/Symfony/Component/Validator/Mapping/Factory/LazyLoadingMetadataFactory.php
+++ b/src/Symfony/Component/Validator/Mapping/Factory/LazyLoadingMetadataFactory.php
@@ -90,7 +90,7 @@ class LazyLoadingMetadataFactory implements MetadataFactoryInterface
return $this->loadedClasses[$class];
}
- if (!class_exists($class) && !interface_exists($class)) {
+ if (!class_exists($class) && !interface_exists($class, false)) {
throw new NoSuchMetadataException(sprintf('The class or interface "%s" does not exist.', $class));
}
From adba79a6b01800bd7cc0bc9795dcb46539330f7f Mon Sep 17 00:00:00 2001
From: Nicolas Grekas
Date: Mon, 9 Apr 2018 12:07:56 -0500
Subject: [PATCH 3/3] [Console] Don't go past exact matches when autocompleting
---
.../Console/Helper/QuestionHelper.php | 2 +-
.../Tests/Helper/QuestionHelperTest.php | 24 +++++++++++++++++++
2 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/src/Symfony/Component/Console/Helper/QuestionHelper.php b/src/Symfony/Component/Console/Helper/QuestionHelper.php
index bce0534ed0..36187f8cea 100644
--- a/src/Symfony/Component/Console/Helper/QuestionHelper.php
+++ b/src/Symfony/Component/Console/Helper/QuestionHelper.php
@@ -284,7 +284,7 @@ class QuestionHelper extends Helper
foreach ($autocomplete as $value) {
// If typed characters match the beginning chunk of value (e.g. [AcmeDe]moBundle)
- if (0 === strpos($value, $ret) && $i !== strlen($value)) {
+ if (0 === strpos($value, $ret)) {
$matches[$numMatches++] = $value;
}
}
diff --git a/src/Symfony/Component/Console/Tests/Helper/QuestionHelperTest.php b/src/Symfony/Component/Console/Tests/Helper/QuestionHelperTest.php
index d9bdb606ac..9f837d0f9e 100644
--- a/src/Symfony/Component/Console/Tests/Helper/QuestionHelperTest.php
+++ b/src/Symfony/Component/Console/Tests/Helper/QuestionHelperTest.php
@@ -160,6 +160,30 @@ class QuestionHelperTest extends TestCase
$this->assertEquals('AsseticBundle', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
}
+ public function testAskWithAutocompleteWithExactMatch()
+ {
+ if (!$this->hasSttyAvailable()) {
+ $this->markTestSkipped('`stty` is required to test autocomplete functionality');
+ }
+
+ $inputStream = $this->getInputStream("b\n");
+
+ $possibleChoices = array(
+ 'a' => 'berlin',
+ 'b' => 'copenhagen',
+ 'c' => 'amsterdam',
+ );
+
+ $dialog = new QuestionHelper();
+ $dialog->setInputStream($inputStream);
+ $dialog->setHelperSet(new HelperSet(array(new FormatterHelper())));
+
+ $question = new ChoiceQuestion('Please select a city', $possibleChoices);
+ $question->setMaxAttempts(1);
+
+ $this->assertSame('b', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
+ }
+
public function testAutocompleteWithTrailingBackslash()
{
if (!$this->hasSttyAvailable()) {