Skip to content

Commit

Permalink
Merge branch '7.1' into 7.2
Browse files Browse the repository at this point in the history
* 7.1:
  fix: ignore missing directory in isVendor()
  [OptionsResolver] Allow Union/Intersection Types in Resolved Closures
  Issue #58821: [DependencyInjection] Support interfaces in ContainerBuilder::getReflectionClass().
  Dynamically fix compatibility with doctrine/data-fixtures v2
  [HttpKernel] Ensure HttpCache::getTraceKey() does not throw exception
  don't call EntityManager::initializeObject() with scalar values
  make RelayProxyTrait compatible with relay extension 0.9.0
  [Validator] review italian translations
  Update PR template
  • Loading branch information
nicolas-grekas committed Nov 20, 2024
2 parents 4f69e6b + 0f4099f commit 7da8fba
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion OptionsResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public function setDefault(string $option, mixed $value): static
return $this;
}

if (isset($params[0]) && null !== ($type = $params[0]->getType()) && self::class === $type->getName() && (!isset($params[1]) || (($type = $params[1]->getType()) instanceof \ReflectionNamedType && Options::class === $type->getName()))) {
if (isset($params[0]) && ($type = $params[0]->getType()) instanceof \ReflectionNamedType && self::class === $type->getName() && (!isset($params[1]) || (($type = $params[1]->getType()) instanceof \ReflectionNamedType && Options::class === $type->getName()))) {
// Store closure for later evaluation
$this->nested[$option][] = $value;
$this->defaults[$option] = [];
Expand Down
22 changes: 22 additions & 0 deletions Tests/OptionsResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,28 @@ public function testClosureWithoutParametersNotInvoked()
$this->assertSame(['foo' => $closure], $this->resolver->resolve());
}

public function testClosureWithUnionTypesNotInvoked()
{
$closure = function (int|string|null $value) {
Assert::fail('Should not be called');
};

$this->resolver->setDefault('foo', $closure);

$this->assertSame(['foo' => $closure], $this->resolver->resolve());
}

public function testClosureWithIntersectionTypesNotInvoked()
{
$closure = function (\Stringable&\JsonSerializable $value) {
Assert::fail('Should not be called');
};

$this->resolver->setDefault('foo', $closure);

$this->assertSame(['foo' => $closure], $this->resolver->resolve());
}

public function testAccessPreviousDefaultValue()
{
// defined by superclass
Expand Down

0 comments on commit 7da8fba

Please sign in to comment.