Skip to content

Commit

Permalink
Sort mapping resources
Browse files Browse the repository at this point in the history
  • Loading branch information
julienfalque committed Mar 4, 2021
1 parent 4cc8871 commit 0ec3879
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 8 deletions.
Expand Up @@ -323,7 +323,7 @@ private function getResourcesToWatch(ContainerBuilder $container, array $config)

foreach ($paths as $path) {
if (is_dir($path)) {
foreach (Finder::create()->followLinks()->files()->in($path)->name('/\.(xml|ya?ml)$/') as $file) {
foreach (Finder::create()->followLinks()->files()->in($path)->name('/\.(xml|ya?ml)$/')->sortByName() as $file) {
$resources['yaml' === ($extension = $file->getExtension()) ? 'yml' : $extension][] = $file->getRealPath();
}

Expand Down
Expand Up @@ -806,6 +806,58 @@ public function testDisabledPaginationViaDefaults()
$this->extension->load($config, $containerBuilder);
}

public function testItLoadsMetadataConfigFileInAlphabeticalOrder()
{
$yamlExtractorDefinition = $this->prophesize(Definition::class);
$yamlExtractorDefinition->replaceArgument(0, Argument::that(static function ($paths): bool {
self::assertIsArray($paths);
self::assertContainsOnly('string', $paths);

$normalizePaths = static function (array $paths): array {
return array_map(
static function (string $path): string {
return str_replace(\DIRECTORY_SEPARATOR, '/', $path);
},
$paths
);
};

$testsDirectory = \dirname(__DIR__, 4);

self::assertSame(
$normalizePaths([
"{$testsDirectory}/Bridge/Symfony/Bundle/DependencyInjection/Fixtures/resources/B.yaml",
"{$testsDirectory}/Bridge/Symfony/Bundle/DependencyInjection/Fixtures/resources/Bb.yaml",
"{$testsDirectory}/Bridge/Symfony/Bundle/DependencyInjection/Fixtures/resources/a.yaml",
"{$testsDirectory}/Bridge/Symfony/Bundle/DependencyInjection/Fixtures/resources/a/a.yaml",
"{$testsDirectory}/Bridge/Symfony/Bundle/DependencyInjection/Fixtures/resources/b/a.yaml",
"{$testsDirectory}/Bridge/Symfony/Bundle/DependencyInjection/Fixtures/resources/c.yaml",
"{$testsDirectory}/Bridge/Symfony/Bundle/DependencyInjection/Fixtures/resources/c/a.yaml",
"{$testsDirectory}/Fixtures/TestBundle/Resources/config/api_resources.yml",
"{$testsDirectory}/Fixtures/TestBundle/Resources/config/api_resources/my_resource.yml",
]),
$normalizePaths($paths)
);

return true;
}))->shouldBeCalled();

$containerBuilderProphecy = $this->getBaseContainerBuilderProphecyWithoutDefaultMetadataLoading();
$containerBuilderProphecy
->getDefinition('api_platform.metadata.extractor.xml')
->willReturn($this->prophesize(Definition::class))
->shouldBeCalled();
$containerBuilderProphecy
->getDefinition('api_platform.metadata.extractor.yaml')
->willReturn($yamlExtractorDefinition)
->shouldBeCalled();

$config = self::DEFAULT_CONFIG;
$config['api_platform']['mapping']['paths'] = [__DIR__.'/Fixtures/resources'];

$this->extension->load($config, $containerBuilderProphecy->reveal());
}

private function getPartialContainerBuilderProphecy($configuration = null)
{
$parameterBag = new EnvPlaceholderParameterBag();
Expand Down Expand Up @@ -1042,7 +1094,22 @@ private function getPartialContainerBuilderProphecy($configuration = null)
return $containerBuilderProphecy;
}

private function getBaseContainerBuilderProphecy(array $doctrineIntegrationsToLoad = ['orm'], $configuration = null)
private function getBaseContainerBuilderProphecy(
array $doctrineIntegrationsToLoad = ['orm'],
$configuration = null
) {
$containerBuilderProphecy = $this->getBaseContainerBuilderProphecyWithoutDefaultMetadataLoading($doctrineIntegrationsToLoad, $configuration);

foreach (['yaml', 'xml'] as $format) {
$definitionProphecy = $this->prophesize(Definition::class);
$definitionProphecy->replaceArgument(0, Argument::type('array'))->shouldBeCalled();
$containerBuilderProphecy->getDefinition('api_platform.metadata.extractor.'.$format)->willReturn($definitionProphecy->reveal())->shouldBeCalled();
}

return $containerBuilderProphecy;
}

private function getBaseContainerBuilderProphecyWithoutDefaultMetadataLoading(array $doctrineIntegrationsToLoad = ['orm'], $configuration = null)
{
$hasSwagger = null === $configuration || true === $configuration['api_platform']['enable_swagger'] ?? false;
$hasHydra = null === $configuration || isset($configuration['api_platform']['formats']['jsonld']);
Expand Down Expand Up @@ -1180,12 +1247,6 @@ private function getBaseContainerBuilderProphecy(array $doctrineIntegrationsToLo
$containerBuilderProphecy->setParameter($key, $value)->shouldBeCalled();
}

foreach (['yaml', 'xml'] as $format) {
$definitionProphecy = $this->prophesize(Definition::class);
$definitionProphecy->replaceArgument(0, Argument::type('array'))->shouldBeCalled();
$containerBuilderProphecy->getDefinition('api_platform.metadata.extractor.'.$format)->willReturn($definitionProphecy->reveal())->shouldBeCalled();
}

$definitions = [
'api_platform.data_collector.request',
'api_platform.doctrine.listener.http_cache.purge',
Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.

0 comments on commit 0ec3879

Please sign in to comment.