Skip to content
Snippets Groups Projects
Verified Commit 0f422ac6 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3442025 by phenaproxima, larowlan:...

Issue #3442025 by phenaproxima, larowlan: \Drupal\Core\DefaultContent\Finder::__construct() should error if $decoded['_meta']['uuid'] not set

(cherry picked from commit 2b58be7e0f71f7ed74203563e609ca247aeb723e)
parent 04e1bb20
No related branches found
No related tags found
1 merge request!7908Recipes API on 10.3.x
......@@ -41,9 +41,9 @@ public function __construct(string $path) {
$graph = $files = [];
/** @var \Symfony\Component\Finder\SplFileInfo $file */
foreach ($finder as $file) {
/** @var array{_meta: array{uuid: string, depends: array<string, string>|null}} $decoded */
/** @var array{_meta: array{uuid: string|null, depends: array<string, string>|null}} $decoded */
$decoded = Yaml::decode($file->getContents());
$uuid = $decoded['_meta']['uuid'];
$uuid = $decoded['_meta']['uuid'] ?? throw new ImportException($file->getPathname() . ' does not have a UUID.');
$decoded['_meta']['path'] = $file->getPath();
$files[$uuid] = $decoded;
......
......@@ -4,7 +4,9 @@
namespace Drupal\Tests\Core\DefaultContent;
use Drupal\Component\FileSystem\FileSystem;
use Drupal\Core\DefaultContent\Finder;
use Drupal\Core\DefaultContent\ImportException;
use Drupal\Tests\UnitTestCase;
/**
......@@ -32,4 +34,18 @@ public function testFoundDataIsInDependencyOrder(): void {
$this->assertSame($expected_order, array_slice(array_keys($finder->data), 0, 4));
}
/**
* Tests that files without UUIDs will raise an exception.
*/
public function testExceptionIfNoUuid(): void {
$dir = FileSystem::getOsTemporaryDirectory();
$this->assertIsString($dir);
/** @var string $dir */
file_put_contents($dir . '/no-uuid.yml', '_meta: {}');
$this->expectException(ImportException::class);
$this->expectExceptionMessage("$dir/no-uuid.yml does not have a UUID.");
new Finder($dir);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment