Issue #3437566 by mondrake, longwave, catch, smustgrave, alexpott: Refactor trigger_error in TypedConfigManager

merge-requests/7018/merge
Alex Pott 2024-04-14 10:37:12 +01:00
parent d265060558
commit ea5932e490
No known key found for this signature in database
GPG Key ID: BDA67E7EE836E5CE
2 changed files with 2 additions and 7 deletions

View File

@ -2,7 +2,6 @@
namespace Drupal\Core\Config; namespace Drupal\Core\Config;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Component\Utility\NestedArray; use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Config\Schema\ConfigSchemaAlterException; use Drupal\Core\Config\Schema\ConfigSchemaAlterException;
@ -83,10 +82,7 @@ class TypedConfigManager extends TypedDataManager implements TypedConfigManagerI
$data = $this->configStorage->read($name); $data = $this->configStorage->read($name);
if ($data === FALSE) { if ($data === FALSE) {
// For a typed config the data MUST exist. // For a typed config the data MUST exist.
$data = []; throw new \InvalidArgumentException("Missing required data for typed configuration: $name");
trigger_error(new FormattableMarkup('Missing required data for typed configuration: @config', [
'@config' => $name,
]), E_USER_ERROR);
} }
return $this->createFromNameAndData($name, $data); return $this->createFromNameAndData($name, $data);
} }

View File

@ -12,7 +12,6 @@ use Drupal\Core\TypedData\ComplexDataInterface;
use Drupal\Core\TypedData\Type\IntegerInterface; use Drupal\Core\TypedData\Type\IntegerInterface;
use Drupal\Core\TypedData\Type\StringInterface; use Drupal\Core\TypedData\Type\StringInterface;
use Drupal\KernelTests\KernelTestBase; use Drupal\KernelTests\KernelTestBase;
use PHPUnit\Framework\Error\Error;
use Symfony\Component\Validator\ConstraintViolationListInterface; use Symfony\Component\Validator\ConstraintViolationListInterface;
/** /**
@ -53,7 +52,7 @@ class TypedConfigTest extends KernelTestBase {
$typed_config_manager->get('config_test.non_existent'); $typed_config_manager->get('config_test.non_existent');
$this->fail('Expected error when trying to get non-existent typed config.'); $this->fail('Expected error when trying to get non-existent typed config.');
} }
catch (Error $e) { catch (\InvalidArgumentException $e) {
$this->assertEquals('Missing required data for typed configuration: config_test.non_existent', $e->getMessage()); $this->assertEquals('Missing required data for typed configuration: config_test.non_existent', $e->getMessage());
} }