Skip to content

Commit c4a60be

Browse files
committed
Merge branch '7.0' into 7.1
* 7.0: fix tests fix merge [VarDumper] Fix generator dump on PHP 8.4 keep boolean options when their value is false gracefully handle cases when no resolver is set
2 parents 306663f + c62556d commit c4a60be

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

Exception/LogicException.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Config\Exception;
13+
14+
class LogicException extends \LogicException
15+
{
16+
}

Loader/Loader.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Config\Loader;
1313

1414
use Symfony\Component\Config\Exception\LoaderLoadException;
15+
use Symfony\Component\Config\Exception\LogicException;
1516

1617
/**
1718
* Loader is the abstract class used by all built-in loaders.
@@ -20,7 +21,7 @@
2021
*/
2122
abstract class Loader implements LoaderInterface
2223
{
23-
protected LoaderResolverInterface $resolver;
24+
protected ?LoaderResolverInterface $resolver = null;
2425

2526
public function __construct(
2627
protected ?string $env = null,
@@ -29,6 +30,10 @@ public function __construct(
2930

3031
public function getResolver(): LoaderResolverInterface
3132
{
33+
if (null === $this->resolver) {
34+
throw new LogicException('Cannot get a resolver if none was set.');
35+
}
36+
3237
return $this->resolver;
3338
}
3439

Tests/Loader/LoaderTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Config\Exception\LoaderLoadException;
16+
use Symfony\Component\Config\Exception\LogicException;
1617
use Symfony\Component\Config\Loader\Loader;
1718
use Symfony\Component\Config\Loader\LoaderInterface;
1819
use Symfony\Component\Config\Loader\LoaderResolverInterface;
@@ -29,6 +30,14 @@ public function testGetSetResolver()
2930
$this->assertSame($resolver, $loader->getResolver(), '->setResolver() sets the resolver loader');
3031
}
3132

33+
public function testGetResolverWithoutSetResolver()
34+
{
35+
$this->expectException(LogicException::class);
36+
37+
$loader = new ProjectLoader1();
38+
$loader->getResolver();
39+
}
40+
3241
public function testResolve()
3342
{
3443
$resolvedLoader = $this->createMock(LoaderInterface::class);
@@ -46,6 +55,14 @@ public function testResolve()
4655
$this->assertSame($resolvedLoader, $loader->resolve('foo.xml'), '->resolve() finds a loader');
4756
}
4857

58+
public function testResolveWithoutSetResolver()
59+
{
60+
$this->expectException(LoaderLoadException::class);
61+
62+
$loader = new ProjectLoader1();
63+
$loader->resolve('foo.xml');
64+
}
65+
4966
public function testResolveWhenResolverCannotFindLoader()
5067
{
5168
$resolver = $this->createMock(LoaderResolverInterface::class);

0 commit comments

Comments
 (0)